Move the dependencies into individual packages #530 #4
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: Deploy API | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- main | |
- develop | |
paths: ['apps/api/**', '.github/workflows/deploy-api.yml', 'package.json'] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
environment: ${{ github.ref == 'refs/heads/main' && 'alpha' || 'stage' }} | |
name: Build and push API docker image for release | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Docker Login | |
uses: azure/docker-login@v2 | |
with: | |
login-server: ${{ vars.ACR_REGISTRY_URL }} | |
username: ${{ secrets.ACR_USERNAME }} | |
password: ${{ secrets.ACR_PASSWORD }} | |
- name: Build Docker image | |
id: build | |
env: | |
ACR_REGISTRY_URL: ${{ vars.ACR_REGISTRY_URL }} | |
REPOSITORY_NAME: api | |
run: | | |
# Build a docker container and push it to ACR | |
docker build -t $ACR_REGISTRY_URL/$REPOSITORY_NAME:${GITHUB_SHA::6} -t $ACR_REGISTRY_URL/$REPOSITORY_NAME:latest -f ./apps/api/Dockerfile . | |
echo "Pushing image to ACR..." | |
docker push $ACR_REGISTRY_URL/$REPOSITORY_NAME:latest | |
docker push $ACR_REGISTRY_URL/$REPOSITORY_NAME:${GITHUB_SHA::6} | |
echo "name=image::$ACR_REGISTRY_URL/$REPOSITORY_NAME:latest" >> $GITHUB_OUTPUT | |
migrate: | |
runs-on: ubuntu-latest | |
environment: ${{ github.ref == 'refs/heads/main' && 'alpha' || 'stage' }} | |
name: Run database migrations | |
needs: build | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Run migrations | |
env: | |
DATABASE_URL: ${{ secrets.DATABASE_URL }} | |
run: | | |
# Install pnpm | |
npm i -g pnpm | |
# Install dependencies | |
pnpm i | |
# Run migrations | |
pnpm db:generate-types | |
pnpm db:deploy-migrations | |
deploy: | |
runs-on: ubuntu-latest | |
environment: ${{ github.ref == 'refs/heads/main' && 'alpha' || 'stage' }} | |
name: Restart API container app | |
needs: migrate | |
steps: | |
- name: Azure Login action | |
uses: azure/login@v2 | |
with: | |
creds: ${{ secrets.CONTAINER_APP_SP_CREDENTIALS }} | |
enable-AzPSSession: true | |
- name: Azure CLI script | |
uses: azure/cli@v2 | |
env: | |
API_CONTAINER: ${{ vars.API_CONTAINER }} | |
API_CONTAINER_RG: ${{ vars.API_CONTAINER_RG }} | |
ACR_REGISTRY_URL: ${{ vars.ACR_REGISTRY_URL }} | |
REPOSITORY_NAME: api | |
with: | |
azcliversion: latest | |
inlineScript: | | |
az containerapp update \ | |
--name $API_CONTAINER \ | |
--resource-group $API_CONTAINER_RG \ | |
--image $ACR_REGISTRY_URL/$REPOSITORY_NAME:latest |