This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a basic workflow to help you get started with Actions | |
name: Production CI/CD Django, Postgres, Tests & Deploy to DigitalOcean. | |
# Controls when the workflow will run | |
on: | |
# Triggers the workflow on push or pull request events but only for the main branch | |
push: | |
branches: [ main ] | |
pull_request: | |
branches: [ main ] | |
# Allows you to run this workflow manually from the Actions tab | |
workflow_dispatch: | |
# A workflow run is made up of one or more jobs that can run sequentially or in parallel | |
jobs: | |
# This workflow contains a single job called "build" | |
build: | |
# The type of runner that the job will run on | |
runs-on: ubuntu-latest | |
services: | |
postgres_main: | |
image: postgres:12 | |
env: | |
POSTGRES_USER: postgres | |
POSTGRES_PASSWORD: postgres | |
POSTGRES_DB: djtesting | |
ports: | |
- 5432:5432 | |
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 | |
# Steps represent a sequence of tasks that will be executed as part of the job | |
steps: | |
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Setup Python 3.6 | |
uses: actions/setup-python@v2 | |
with: | |
python-version: 3.6 | |
- name: Install requirements | |
run: | | |
pip install -r requirements.txt | |
- name: Run Tests | |
env: | |
DEBUG: "0" | |
DJANGO_SECRET_KEY: CI_CD_TEST_KEY | |
POSTGRES_USER: postgres | |
POSTGRES_PASSWORD: postgres | |
POSTGRES_DB: djtesting | |
POSTGRES_PORT: 5432 | |
run: | | |
python manage.py test | |
- name: Run Collectstatic | |
continue-on-error: true | |
env: | |
DEBUG: "0" | |
DJANGO_SECRET_KEY: CI_CD_TEST_KEY | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_STORAGE_BUCKET_NAME: ${{ secrets.AWS_STORAGE_BUCKET_NAME }} | |
run: | | |
python manage.py collectstatic --noinput | |
- name: Push Main Branch into Production | |
uses: codingforentrepreneurs/action-branch-to-branch@main | |
with: | |
dest_branch: production-3 | |
source_branch: main | |
commit_message: "Release production version" | |
env: | |
GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} | |
- name: Install doctl | |
uses: digitalocean/action-doctl@v2 | |
with: | |
token: ${{ secrets.DO_ACCESS_TOKEN }} | |
- name: Run a DOCTL Command | |
run: | | |
doctl apps update ${{ secrets.DO_APP_ID }} --spec .do/app.yaml |