Skip to content

fix: add build and push steps for Docker images in CI workflow #21

fix: add build and push steps for Docker images in CI workflow

fix: add build and push steps for Docker images in CI workflow #21

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 Tagging
run: |
docker build -t ${{ secrets.ACR_LOGIN_SERVER }}/express-server:${{ steps.short-sha.outputs.sha }} .
docker build -t ${{ secrets.ACR_LOGIN_SERVER }}/express-server:latest .
- name: Push to Azure Container Registry
run: |
docker push ${{ secrets.ACR_LOGIN_SERVER }}/express-server:${{ steps.short-sha.outputs.sha }}
docker push ${{ secrets.ACR_LOGIN_SERVER }}/express-server:latest