Skip to content

Deploy on Release

Deploy on Release #1

name: Deploy on Release
on:
release:
types: [published]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install golang-migrate/migrate
run: |
wget https://github.com/golang-migrate/migrate/releases/latest/download/migrate.linux-amd64.deb
sudo dpkg -i migrate.linux-amd64.deb
- name: Run database migration
env:
DB_HOST: ${{ vars.DB_HOST }}
DB_PORT: ${{ vars.DB_PORT }}
DB_NAME: ${{ vars.DB_NAME }}
DB_USER: ${{ secrets.DB_USER }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
run: |
migrate -path db/migrations/ \
-database "postgresql://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}" \
-verbose up
- name: Set up Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: 1.1.7
- name: Terraform Init
run: terraform init
working-directory: ./infra
- name: Terraform Apply
run: terraform apply -auto-approve
working-directory: ./infra
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
TF_VAR_db_username: ${{ secrets.TF_VAR_DB_USERNAME }}
TF_VAR_db_password: ${{ secrets.TF_VAR_DB_PASSWORD }}