Skip to content

Commit 706cf5d

Browse files
kenahrensclaude
andcommitted
feat: Add CI/CD infrastructure and documentation
- GitHub Actions workflows for automated testing and image building - Root and Kubernetes Makefiles for development workflow - Comprehensive CI/CD setup documentation - Update plan.md to mark Phase 8 complete - Move test script to scripts directory 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 4e7819c commit 706cf5d

6 files changed

Lines changed: 568 additions & 17 deletions

File tree

.github/workflows/ci.yml

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
name: CI/CD Pipeline
2+
3+
on:
4+
push:
5+
branches: [ main, develop, feature/* ]
6+
pull_request:
7+
branches: [ main, develop ]
8+
9+
env:
10+
REGISTRY: ghcr.io
11+
IMAGE_NAME: ${{ github.repository }}
12+
13+
jobs:
14+
test-backend:
15+
runs-on: ubuntu-latest
16+
17+
services:
18+
postgres:
19+
image: postgres:15
20+
env:
21+
POSTGRES_PASSWORD: password
22+
POSTGRES_DB: banking_test
23+
options: >-
24+
--health-cmd pg_isready
25+
--health-interval 10s
26+
--health-timeout 5s
27+
--health-retries 5
28+
ports:
29+
- 5432:5432
30+
31+
steps:
32+
- uses: actions/checkout@v4
33+
34+
- name: Set up JDK 17
35+
uses: actions/setup-java@v4
36+
with:
37+
java-version: '17'
38+
distribution: 'temurin'
39+
cache: maven
40+
41+
- name: Setup test database
42+
run: |
43+
PGPASSWORD=password psql -h localhost -U postgres -d banking_test -c "
44+
CREATE SCHEMA IF NOT EXISTS user_service;
45+
CREATE SCHEMA IF NOT EXISTS accounts_service;
46+
CREATE SCHEMA IF NOT EXISTS transactions_service;
47+
"
48+
49+
- name: Test Backend Services
50+
run: make test-backend
51+
52+
test-frontend:
53+
runs-on: ubuntu-latest
54+
55+
steps:
56+
- uses: actions/checkout@v4
57+
58+
- name: Setup Node.js
59+
uses: actions/setup-node@v4
60+
with:
61+
node-version: '18'
62+
cache: 'npm'
63+
cache-dependency-path: frontend/package-lock.json
64+
65+
- name: Test Frontend
66+
run: make test-frontend
67+
68+
build-and-push:
69+
needs: [test-backend, test-frontend]
70+
runs-on: ubuntu-latest
71+
if: github.event_name == 'push'
72+
73+
permissions:
74+
contents: read
75+
packages: write
76+
77+
strategy:
78+
matrix:
79+
service:
80+
- user-service
81+
- accounts-service
82+
- transactions-service
83+
- api-gateway
84+
- frontend
85+
86+
steps:
87+
- uses: actions/checkout@v4
88+
89+
- name: Set up Docker Buildx
90+
uses: docker/setup-buildx-action@v3
91+
92+
- name: Log in to Container Registry
93+
uses: docker/login-action@v3
94+
with:
95+
registry: ${{ env.REGISTRY }}
96+
username: ${{ github.actor }}
97+
password: ${{ secrets.GITHUB_TOKEN }}
98+
99+
- name: Extract metadata
100+
id: meta
101+
uses: docker/metadata-action@v5
102+
with:
103+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/${{ matrix.service }}
104+
tags: |
105+
type=ref,event=branch
106+
type=ref,event=pr
107+
type=sha,prefix={{branch}}-
108+
type=raw,value=latest,enable={{is_default_branch}}
109+
110+
- name: Build and push Docker image
111+
uses: docker/build-push-action@v5
112+
with:
113+
context: ${{ matrix.service == 'frontend' && './frontend' || format('./backend/{0}', matrix.service) }}
114+
push: true
115+
tags: ${{ steps.meta.outputs.tags }}
116+
labels: ${{ steps.meta.outputs.labels }}
117+
cache-from: type=gha
118+
cache-to: type=gha,mode=max
119+
120+
e2e-test:
121+
needs: [build-and-push]
122+
runs-on: ubuntu-latest
123+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
124+
125+
steps:
126+
- uses: actions/checkout@v4
127+
128+
- name: Setup Node.js
129+
uses: actions/setup-node@v4
130+
with:
131+
node-version: '18'
132+
cache: 'npm'
133+
cache-dependency-path: frontend/package-lock.json
134+
135+
- name: Install Playwright
136+
run: |
137+
cd frontend
138+
npm ci
139+
npx playwright install --with-deps
140+
141+
- name: Start services with docker-compose
142+
run: |
143+
docker-compose up -d
144+
sleep 30
145+
146+
- name: Run E2E tests
147+
run: |
148+
cd frontend
149+
npm run test:e2e
150+
151+
- name: Upload test results
152+
uses: actions/upload-artifact@v4
153+
if: always()
154+
with:
155+
name: playwright-report
156+
path: frontend/playwright-report/
157+
retention-days: 30

CI_CD_SETUP.md

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
# CI/CD Pipeline Setup
2+
3+
This document describes the CI/CD pipeline setup for the banking application microservices.
4+
5+
## Overview
6+
7+
The CI/CD pipeline uses GitHub Actions for automated building, testing, and deployment. The pipeline includes:
8+
9+
1. **Continuous Integration (CI)**: Automated testing and building
10+
2. **Container Registry**: Docker images pushed to GitHub Container Registry
11+
3. **Continuous Deployment (CD)**: Automated deployment to Kubernetes
12+
13+
## Pipeline Structure
14+
15+
### CI Pipeline (`.github/workflows/ci.yml`)
16+
17+
**Triggers:**
18+
- Push to `main`, `develop`, or `feature/*` branches
19+
- Pull requests to `main` or `develop`
20+
21+
**Jobs:**
22+
1. `test-backend`: Tests all Java microservices
23+
2. `test-frontend`: Tests Next.js frontend application
24+
3. `build-and-push`: Builds and pushes Docker images to registry
25+
4. `e2e-test`: Runs end-to-end Playwright tests (main branch only)
26+
27+
### Deployment Pipeline (`.github/workflows/deploy.yml`)
28+
29+
**Triggers:**
30+
- Push to `main` branch
31+
- Git tags matching `v*`
32+
- Manual workflow dispatch
33+
34+
**Jobs:**
35+
1. Updates Kubernetes manifests with registry image references
36+
2. Deploys to staging/production environments
37+
38+
## Container Registry
39+
40+
Images are pushed to GitHub Container Registry (GHCR) at:
41+
- `ghcr.io/speedscale/microsvc/user-service`
42+
- `ghcr.io/speedscale/microsvc/accounts-service`
43+
- `ghcr.io/speedscale/microsvc/transactions-service`
44+
- `ghcr.io/speedscale/microsvc/api-gateway`
45+
- `ghcr.io/speedscale/microsvc/frontend`
46+
47+
## Makefile Commands
48+
49+
The project includes comprehensive Makefiles for development and deployment:
50+
51+
### Root Makefile Commands
52+
53+
**Build & Test:**
54+
```bash
55+
make build-all # Build all services
56+
make test-all # Run all tests
57+
make docker-build # Build Docker images
58+
make docker-push # Push to registry
59+
```
60+
61+
**Development:**
62+
```bash
63+
make dev-up # Start dev environment
64+
make dev-down # Stop dev environment
65+
make dev-reset # Reset dev environment
66+
```
67+
68+
**CI/CD:**
69+
```bash
70+
make ci-test # Run CI tests
71+
make ci-build # Build and push images
72+
make ci-deploy # Full CI/CD pipeline
73+
```
74+
75+
### Kubernetes Makefile Commands
76+
77+
```bash
78+
cd kubernetes
79+
make deploy # Deploy to Kubernetes
80+
make update-images # Update manifests with registry images
81+
make status # Check deployment status
82+
make logs # View service logs
83+
make test-deployment # Run E2E tests against deployment
84+
```
85+
86+
## Environment Variables
87+
88+
**CI/CD Configuration:**
89+
- `REGISTRY`: Docker registry URL (default: `ghcr.io/speedscale/microsvc`)
90+
- `IMAGE_TAG`: Docker image tag (default: `latest`)
91+
92+
**GitHub Secrets Required:**
93+
- `GITHUB_TOKEN`: Automatically provided by GitHub Actions
94+
95+
## Image Tagging Strategy
96+
97+
- **Latest**: `latest` tag for main branch builds
98+
- **Branch**: `feature-branch-name` for feature branches
99+
- **SHA**: `main-abc1234` for commit-specific builds
100+
- **Release**: `v1.0.0` for tagged releases
101+
102+
## Deployment Environments
103+
104+
### Staging
105+
- Triggered on push to `main` branch
106+
- Uses latest images from main branch
107+
- Deployed to staging Kubernetes cluster
108+
109+
### Production
110+
- Triggered on git tags (`v*`) or manual dispatch
111+
- Uses tagged release images
112+
- Deployed to production Kubernetes cluster
113+
114+
## Local Development with Registry Images
115+
116+
To test with registry images locally:
117+
118+
```bash
119+
# Update manifests to use registry images
120+
make update-k8s-images REGISTRY=ghcr.io/speedscale/microsvc IMAGE_TAG=latest
121+
122+
# Deploy to minikube
123+
cd kubernetes
124+
make deploy
125+
126+
# Restore local images for development
127+
make restore-local-images
128+
```
129+
130+
## Troubleshooting
131+
132+
### Authentication Issues
133+
If you encounter registry authentication issues:
134+
1. Ensure `GITHUB_TOKEN` has `packages:write` permission
135+
2. Check that the repository has GitHub Packages enabled
136+
137+
### Image Pull Failures
138+
If Kubernetes can't pull images:
139+
1. Verify the image exists in the registry
140+
2. Check `imagePullPolicy` is set to `Always` for registry images
141+
3. Ensure Kubernetes has access to pull from GHCR
142+
143+
### Build Failures
144+
If tests fail in CI:
145+
1. Run tests locally: `make test-all`
146+
2. Check test database setup in GitHub Actions
147+
3. Verify all environment variables are set correctly

0 commit comments

Comments
 (0)