Skip to content

Merge pull request #7 from speedscale/fix/k8s-deploy-registry-images #21

Merge pull request #7 from speedscale/fix/k8s-deploy-registry-images

Merge pull request #7 from speedscale/fix/k8s-deploy-registry-images #21

Workflow file for this run

name: CI/CD Pipeline
on:
push:
branches: [ master, develop, feature/* ]
pull_request:
branches: [ master, develop ]
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
test-backend:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:15
env:
POSTGRES_PASSWORD: password
POSTGRES_DB: banking_test
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: maven
- name: Setup test database
run: |
PGPASSWORD=password psql -h localhost -U postgres -d banking_test -c "
CREATE SCHEMA IF NOT EXISTS user_service;
CREATE SCHEMA IF NOT EXISTS accounts_service;
CREATE SCHEMA IF NOT EXISTS transactions_service;
"
- name: Test Backend Services
run: make test-backend
test-frontend:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'npm'
cache-dependency-path: frontend/package-lock.json
- name: Test Frontend
run: make test-frontend
build-and-push:
needs: [test-backend, test-frontend]
runs-on: ubuntu-latest
if: github.event_name == 'push'
permissions:
contents: read
packages: write
strategy:
matrix:
service:
- user-service
- accounts-service
- transactions-service
- api-gateway
- frontend
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/${{ matrix.service }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=sha,prefix={{branch}}-
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: ${{ matrix.service == 'frontend' && './frontend' || format('./backend/{0}', matrix.service) }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
e2e-test:
needs: [build-and-push]
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'npm'
cache-dependency-path: frontend/package-lock.json
- name: Install Playwright
run: |
cd frontend
npm ci
npx playwright install --with-deps
- name: Start services with docker-compose
run: |
docker-compose up -d
sleep 30
- name: Run E2E tests
run: |
cd frontend
npm run test:e2e
- name: Upload test results
uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report
path: frontend/playwright-report/
retention-days: 30