.github/workflows/CD.yml
name: CD
on:
push:
branches: [ main ]
workflow_dispatch:
jobs:
migration-runner:
runs-on: ubuntu-latest
environment: prod
if: github.actor != 'dependabot'
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: '3.8'
- name: run migration script
env:
MONGO_USER: ${{ secrets.MONGO_USER }}
MONGO_PASSWORD: ${{ secrets.MONGO_PASSWORD }}
MONGO_HOST: ${{ secrets.MONGO_HOST }}
run: |
cd server
pip install pipenv
pipenv install --deploy
pipenv run python3 -m src.db.runner
backend-deploy:
runs-on: ubuntu-latest
environment: prod
needs: migration-runner
steps:
- uses: actions/checkout@v2
- name: Login to Public ECR
uses: docker/login-action@v1
with:
registry: public.ecr.aws
username: ${{ secrets.AWS_ACCESS_KEY_ID }}
password: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
env:
AWS_REGION: us-east-1
- name: Build and push image
uses: docker/build-push-action@v2
with:
pull: true # pull new intermediate images
push: true # push to ECR
tags: public.ecr.aws/a5f0m6q3/syncm8_prod:latest
file: Dockerfile
target: prod # build the prod image
- name: Deploy to ECS
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: us-east-2
run: aws ecs update-service --force-new-deployment --service service --cluster backend-cluster
frontend-deploy:
runs-on: ubuntu-latest
environment: prod
needs: backend-deploy
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 10.x
- name: Build React App
run: |
cd client
npm ci
npm run build
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-2
- name: Push to S3
run: aws s3 sync ./client/build/ s3://syncm8.com --delete