Skip to content

fix: add deployment step to Azure Web App in CI workflow #24

fix: add deployment step to Azure Web App in CI workflow

fix: add deployment step to Azure Web App in CI workflow #24

Workflow file for this run

name: Express Server CI/CD Workflow
on:
push:
branches: ["@dilshan"]
jobs:
build-and-test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:15
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: rest-api-db
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
strategy:
matrix:
node-version: [22.x, 24.x]
steps:
- name: Checkout code to runner
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: "${{ matrix.node-version }}"
- name: Install dependencies
run: npm install
# Up and running db is required for prisma migration commands
- name: Setup Database and run Tests
env:
DATABASE_URL: postgres://postgres:password@localhost:5432/rest-api-db
NODE_ENV: test
run: |
# Wait for postgres to be ready (prevents connection errors)
until pg_isready -h localhost -p 5432; do
echo "Waiting for Postgres..."
sleep 2
done
npx prisma generate
npx prisma migrate deploy
npm test
deploy:
needs: build-and-test
runs-on: ubuntu-latest
steps:
- name: Checkout code to runner
uses: actions/checkout@v2
- name: Create short SHA for tagging
uses: benjlevesque/short-sha@v3.0
id: short-sha
with:
length: 7
- name: Login to Azure Container Registry
uses: azure/docker-login@v1
with:
login-server: ${{ secrets.ACR_LOGIN_SERVER }}
username: ${{ secrets.ACR_LOGIN_USERNAME }}
password: ${{ secrets.ACR_LOGIN_PASSWORD }}
- name: Build and push Docker image to ACR
run: |
REGISTRY_IMAGE=${{ secrets.ACR_LOGIN_SERVER }}/express-server
SHA_TAG=${{ steps.short-sha.outputs.sha }}
docker build -t $REGISTRY_IMAGE:$SHA_TAG .
docker tag $REGISTRY_IMAGE:$SHA_TAG $REGISTRY_IMAGE:latest
docker push $REGISTRY_IMAGE:$SHA_TAG
docker push $REGISTRY_IMAGE:latest
echo "IMAGE_TAG=$REGISTRY_IMAGE:$SHA_TAG" >> $GITHUB_ENV
- name: Deploy to Azure Web App
uses: azure/webapps-deploy@v2
with:
app-name: ${{ secrets.AZURE_WEBAPP_NAME }}
images: ${{ secrets.ACR_LOGIN_SERVER }}/express-server:latest