Deploy to production #1156
This file contains hidden or 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
| name: Deploy to production | |
| on: | |
| workflow_dispatch: # allows manual triggering | |
| schedule: | |
| - cron: '0 3 * * *' # runs daily at 00:00 | |
| jobs: | |
| test: | |
| name: Unit tests | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: main | |
| - name: Set up Python 3.x | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.12' | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| - name: Unit tests | |
| run: | | |
| python3 -m venv venv | |
| source venv/bin/activate | |
| pip install --upgrade pip | |
| pip install -r requirements_for_test.txt | |
| export DB_SECRET="{'dbClusterIdentifier':'none','password':'secret','dbname':'accessibility_monitoring_app','engine':'postgres','port':5432,'host':'localhost','username':'admin'}" | |
| export DB_NAME=bucket-name | |
| export ALLOWED_HOSTS='localhost 127.0.0.1 0.0.0.0' | |
| export SECRET_KEY=1234 | |
| export DEBUG=TRUE | |
| npm i | |
| make static_files_process | |
| make test | |
| int-test: | |
| needs: test | |
| name: Integration tests | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: main | |
| - name: Set up Python 3.x | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.12' | |
| - name: Integration tests | |
| run: | | |
| cd stack_tests/integration_tests | |
| docker compose up --abort-on-container-exit | |
| deploy: | |
| needs: int-test | |
| name: Deploy to AWS | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: main | |
| - name: Setup Terraform | |
| uses: hashicorp/setup-terraform@v4 | |
| with: | |
| terraform_version: 1.14.0 | |
| terraform_wrapper: false | |
| - name: Install AWS session manager | |
| run: | | |
| curl "https://s3.amazonaws.com/session-manager-downloads/plugin/latest/ubuntu_64bit/session-manager-plugin.deb" -o "session-manager-plugin.deb" | |
| sudo dpkg -i session-manager-plugin.deb | |
| - name: Backup databases | |
| run: | | |
| python terraform_stack/terraform_deploy/terraform_deployment.py --environment prod --function exec --command "python terraform_stack/terraform_deploy/dump_rds_to_s3_as_sql.py" && \ | |
| sleep 30 && \ | |
| aws s3 sync s3://amp-app-prod-env-prod-env-files/ s3://amp-aurora-backup-prod/ | |
| env: | |
| AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID_COPILOT }} | |
| AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY_COPILOT }} | |
| AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION_COPILOT }} | |
| - name: Staging tests | |
| run: | | |
| aws s3 sync s3://amp-app-prod-env-prod-env-files/ s3://amp-app-staging-env-staging-env-files/ && \ | |
| python terraform_stack/terraform_deploy/terraform_deployment.py --environment staging --function exec --command 'python terraform_stack/terraform_deploy/prod_deploy_tools.py' && \ | |
| python terraform_stack/terraform_deploy/terraform_deployment.py --environment staging --function up && \ | |
| sleep 300 && \ | |
| docker compose --file stack_tests/smoke_tests/staging-platform.docker-compose.yml up --abort-on-container-exit && \ | |
| docker compose --file stack_tests/smoke_tests_viewer/staging-viewer.docker-compose.yml up --abort-on-container-exit | |
| env: | |
| AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID_COPILOT }} | |
| AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY_COPILOT }} | |
| AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION_COPILOT }} | |
| SMOKE_TESTS_USERNAME: ${{ secrets.SMOKE_TESTS_USERNAME }} | |
| SMOKE_TESTS_PASSWORD: ${{ secrets.SMOKE_TESTS_PASSWORD }} | |
| # - name: Deploy to AWS | |
| # run: | | |
| # python terraform_stack/terraform_deploy/terraform_deployment.py --environment prod --function up | |
| # env: | |
| # AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID_COPILOT }} | |
| # AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY_COPILOT }} | |
| # AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION_COPILOT }} | |
| # - name: Smoke tests | |
| # run: | | |
| # cd stack_tests/smoke_tests | |
| # docker compose up --abort-on-container-exit | |
| # cd ../smoke_tests_viewer | |
| # docker compose up --abort-on-container-exit | |
| # env: | |
| # SMOKE_TESTS_USERNAME: ${{ secrets.SMOKE_TESTS_USERNAME }} | |
| # SMOKE_TESTS_PASSWORD: ${{ secrets.SMOKE_TESTS_PASSWORD }} |