Skip to content

Commit 86d1ad5

Browse files
committed
Add CI and deploy GitHub Actions workflows
1 parent f051ed7 commit 86d1ad5

2 files changed

Lines changed: 143 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: CI Pipeline
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
pull_request:
7+
branches: [ main, develop ]
8+
9+
jobs:
10+
backend-test:
11+
name: Backend Tests
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- name: Set up JDK 21
18+
uses: actions/setup-java@v4
19+
with:
20+
java-version: '21'
21+
distribution: 'temurin'
22+
cache: maven
23+
24+
- name: Run Backend Tests
25+
run: ./mvnw test
26+
27+
- name: Upload Test Results
28+
if: always()
29+
uses: actions/upload-artifact@v4
30+
with:
31+
name: backend-test-results
32+
path: target/surefire-reports/
33+
34+
frontend-build:
35+
name: Frontend Build
36+
runs-on: ubuntu-latest
37+
38+
steps:
39+
- uses: actions/checkout@v4
40+
41+
- name: Set up Node.js
42+
uses: actions/setup-node@v4
43+
with:
44+
node-version: '20'
45+
cache: 'npm'
46+
cache-dependency-path: frontend/package-lock.json
47+
48+
- name: Install Dependencies
49+
working-directory: ./frontend
50+
run: npm ci
51+
52+
- name: Build Frontend
53+
working-directory: ./frontend
54+
run: npm run build
55+
56+
- name: Upload Build Artifacts
57+
uses: actions/upload-artifact@v4
58+
with:
59+
name: frontend-build
60+
path: src/main/resources/static/
61+
62+
docker-build:
63+
name: Docker Build Test
64+
runs-on: ubuntu-latest
65+
needs: [backend-test, frontend-build]
66+
67+
steps:
68+
- uses: actions/checkout@v4
69+
70+
- name: Set up Docker Buildx
71+
uses: docker/setup-buildx-action@v3
72+
73+
- name: Build Docker Image
74+
uses: docker/build-push-action@v5
75+
with:
76+
context: .
77+
file: ./Dockerfile
78+
push: false
79+
load: true
80+
tags: website:ci-test
81+
cache-from: type=gha
82+
cache-to: type=gha,mode=max
83+
84+
- name: Test Docker Image
85+
run: |
86+
docker run -d -p 8080:8080 --name test-app website:ci-test
87+
sleep 30
88+
curl -f http://localhost:8080/api/client/info || exit 1
89+
docker stop test-app
90+
docker rm test-app

.github/workflows/deploy.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Deploy to Production
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
workflow_dispatch:
7+
8+
env:
9+
REGISTRY: ghcr.io
10+
IMAGE_NAME: ${{ github.repository }}
11+
12+
jobs:
13+
build-and-push:
14+
name: Build and Push Docker Image
15+
runs-on: ubuntu-latest
16+
permissions:
17+
contents: read
18+
packages: write
19+
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v4
23+
24+
- name: Set up Docker Buildx
25+
uses: docker/setup-buildx-action@v3
26+
27+
- name: Log in to Container Registry
28+
uses: docker/login-action@v3
29+
with:
30+
registry: ${{ env.REGISTRY }}
31+
username: ${{ github.actor }}
32+
password: ${{ secrets.GITHUB_TOKEN }}
33+
34+
- name: Extract metadata
35+
id: meta
36+
uses: docker/metadata-action@v5
37+
with:
38+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
39+
tags: |
40+
type=raw,value=latest,enable={{is_default_branch}}
41+
type=sha,prefix=main-
42+
43+
- name: Build and push Docker image
44+
uses: docker/build-push-action@v5
45+
with:
46+
context: .
47+
file: ./Dockerfile
48+
push: true
49+
tags: ${{ steps.meta.outputs.tags }}
50+
labels: ${{ steps.meta.outputs.labels }}
51+
cache-from: type=gha
52+
cache-to: type=gha,mode=max
53+
platforms: linux/amd64

0 commit comments

Comments
 (0)