Run Sequelize #26
Workflow file for this run
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: Standup Database and Test Migration | |
on: | |
pull_request: | |
branches: [ main ] | |
# paths: | |
# - 'users-api/src/migrations/**' | |
jobs: | |
check-migrations: | |
runs-on: ubuntu-latest | |
env: | |
GCP_PROEJCT_ID: "database-migration-anonymized" | |
DB_HOST: "users-db" | |
POSTGRES_PASSWORD: ${DB_PASSWORD:-dMVZFeBWLOzYRV71} | |
DB_USERNAME: "postgres" | |
POSTGRES_DB: "postgres" | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Authenticate with GCP | |
uses: google-github-actions/auth@v1 | |
with: | |
credentials_json: ${{ secrets.GCP_SA_KEY }} | |
- name: Set up Cloud SDK | |
uses: google-github-actions/setup-gcloud@v1 | |
- name: Use gcloud CLI | |
run: gcloud info | |
- name: Configure Docker to authenticate with GCR | |
run: | | |
gcloud auth configure-docker | |
- name: Pull PostgreSQL image from GCP | |
run: | | |
docker pull gcr.io/$GCP_PROEJCT_ID/$DB_HOST:latest | |
- name: Start PostgreSQL container | |
run: | | |
docker run -d --name $DB_HOST -e POSTGRES_PASSWORD=$DB_PASSWORD: -e POSTGRES_DB=$POSTGRES_DB -p 5432:5432 gcr.io/$GCP_PROEJCT_ID/$DB_HOST:latest | |
- name: Install Sequelize CLI and dependencies | |
run: | | |
cd ./users-api/src | |
npm install sequelize-cli | |
npm install # Assuming you have package.json with necessary dependencies | |
- name: Wait for Postgres to be ready | |
run: | | |
for i in {1..10}; do | |
nc -z localhost 5432 && echo "Postgres is up" && break | |
echo "Waiting for Postgres..." | |
sleep 10 | |
done | |
- name: Run Sequelize migrations | |
env: | |
DB_PASSWORD: "dMVZFeBWLOzYRV71" # ${POSTGRES_PASSWORD} | |
DB_NAME: "postgres" | |
run: | | |
cd ./users-api/src | |
npx sequelize-cli db:migrate | |
- name: Cleanup | |
run: docker stop $DB_HOST |