Nightly staging database sync #279
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
name: Nightly staging database sync | |
on: | |
schedule: | |
# Runs nightly at 00:00 (https://crontab.guru/#0_0_*_*_*) | |
- cron: '0 0 * * *' | |
workflow_dispatch: | |
jobs: | |
build: | |
name: Seed Database | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install pulumi | |
uses: pulumi/setup-pulumi@v2 | |
- run: | | |
echo "STAGING_PG_URL=$(pulumi stack output --stack staging --show-secrets dbRootUrl)" >> $GITHUB_ENV | |
working-directory: infrastructure/data | |
env: | |
PULUMI_ACCESS_TOKEN: ${{ secrets.PULUMI_ACCESS_TOKEN }} | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
aws-access-key-id: ${{ secrets.PIZZA_AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.PIZZA_AWS_SECRET_ACCESS_KEY }} | |
aws-region: eu-west-2 | |
- name: Copy .env files from Staging S3 to the current working directory with AWS CLI | |
run: ./scripts/pull-secrets.sh | |
- name: Check if .env files exist | |
id: check_files | |
uses: andstor/file-existence-action@v2 | |
with: | |
files: ".env, .env.staging, api.planx.uk/.env.test, hasura.planx.uk/.env.test" | |
fail: true | |
- name: Run sync script | |
run: | | |
{ | |
docker run --rm -v "$(pwd)/scripts/seed-database:/app" --workdir="/app" postgis/postgis:12-3.0-alpine "./container.sh" "${STAGING_PG_URL}" "${PRODUCTION_PG_URL_FOR_USER_GITHUB_ACTIONS}" "reset_flows" | |
} || { | |
echo "Database sync failed!" | |
exit 1 | |
} | |
env: | |
PRODUCTION_PG_URL_FOR_USER_GITHUB_ACTIONS: ${{ secrets.PRODUCTION_PG_URL_FOR_USER_GITHUB_ACTIONS }} | |
- name: Slack Notification | |
uses: rtCamp/action-slack-notify@v2 | |
if: failure() | |
env: | |
SLACK_CHANNEL: planx-notifications-internal | |
SLACK_USERNAME: GitHub Actions | |
SLACK_COLOR: "#FF5733" | |
SLACK_TITLE: Staging sync failure | |
SLACK_MESSAGE: Failed to sync the staging database with production | |
SLACK_WEBHOOK: ${{ secrets.SLACK_DEPLOYMENT_WEBHOOK }} |