Skip to content

Commit afcad19

Browse files
ci: simplify fe,be pipeline
1 parent 9d166ad commit afcad19

9 files changed

Lines changed: 232 additions & 297 deletions

.github/workflows/backend/ci-backend.yml

Lines changed: 0 additions & 40 deletions
This file was deleted.

.github/workflows/backend/docker-build-backend.yml

Lines changed: 0 additions & 62 deletions
This file was deleted.

.github/workflows/backend/deploy-backend.yml renamed to .github/workflows/deploy-backend.yml

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,83 @@ name: CD — Deploy Backend & Database Migration
22

33
on:
44
push:
5-
branches: ['main', 'production']
5+
branches: ["main", "production"]
66
paths:
7-
- 'backend/**'
8-
- '.github/workflows/backend/**'
7+
- "backend/**"
8+
- ".github/workflows/deploy-backend.yml"
9+
- '!**/**/*.md'
910

1011
workflow_dispatch: # Memungkinkan trigger deployment secara manual dari GitHub Actions UI
1112

1213
jobs:
14+
build-and-test:
15+
name: Build & Test (Bun)
16+
runs-on: ubuntu-latest
17+
defaults:
18+
run:
19+
working-directory: ./backend
20+
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v4
24+
25+
- name: Setup Bun environment
26+
uses: oven-sh/setup-bun@v2
27+
with:
28+
bun-version: latest
29+
30+
- name: Install dependencies
31+
run: bun install --frozen-lockfile
32+
33+
- name: Typecheck & Compile (Build)
34+
run: bun run build
35+
36+
- name: Run Unit Tests
37+
run: bun test
38+
39+
build-and-push-ghcr:
40+
name: Build & Push Backend Docker Image to GHCR
41+
runs-on: ubuntu-latest
42+
permissions:
43+
contents: read
44+
packages: write
45+
46+
steps:
47+
- name: Checkout repository
48+
uses: actions/checkout@v4
49+
50+
- name: Set up Docker Buildx
51+
uses: docker/setup-buildx-action@v3
52+
53+
- name: Log in to GitHub Container Registry (GHCR)
54+
if: github.event_name != 'pull_request'
55+
uses: docker/login-action@v3
56+
with:
57+
registry: ${{ env.REGISTRY }}
58+
username: ${{ github.actor }}
59+
password: ${{ secrets.GITHUB_TOKEN }}
60+
61+
- name: Extract Docker metadata (tags, labels)
62+
id: meta
63+
uses: docker/metadata-action@v5
64+
with:
65+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
66+
tags: |
67+
type=ref,event=branch
68+
type=sha,format=short
69+
type=raw,value=latest,enable={{is_default_branch}}
70+
71+
- name: Build and push Backend Docker image to GHCR
72+
uses: docker/build-push-action@v6
73+
with:
74+
context: ./backend
75+
file: ./backend/Dockerfile
76+
push: ${{ github.event_name != 'pull_request' }}
77+
tags: ${{ steps.meta.outputs.tags }}
78+
labels: ${{ steps.meta.outputs.labels }}
79+
cache-from: type=gha
80+
cache-to: type=gha,mode=max
81+
1382
deploy-to-production:
1483
name: Deploy to Server & Run Migrations
1584
runs-on: ubuntu-latest
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
name: CD — Deploy Frontend Dashboard
2+
3+
on:
4+
push:
5+
branches: [ "main", "production" ]
6+
paths:
7+
- "frontend/**"
8+
- '.github/workflows/deploy-frontend'
9+
- '!**/**/*.md'
10+
11+
12+
workflow_dispatch: # Trigger manual dari GitHub Actions UI
13+
14+
jobs:
15+
build-and-test-frontend:
16+
name: Build & Lint Frontend
17+
runs-on: ubuntu-latest
18+
defaults:
19+
run:
20+
working-directory: ./frontend
21+
22+
steps:
23+
- name: Checkout repository
24+
uses: actions/checkout@v4
25+
26+
- name: Setup Bun environment
27+
uses: oven-sh/setup-bun@v2
28+
with:
29+
bun-version: latest
30+
31+
- name: Install dependencies (jika package.json ada)
32+
run: |
33+
if [ -f "package.json" ]; then
34+
bun install --frozen-lockfile
35+
else
36+
echo "package.json belum ada di folder frontend/. Melewatkan instalasi."
37+
fi
38+
39+
- name: Lint & Build (jika package.json ada)
40+
run: |
41+
if [ -f "package.json" ]; then
42+
bun run build --if-present
43+
else
44+
echo "package.json belum ada di folder frontend/. Melewatkan build."
45+
fi
46+
build-and-push-ghcr-frontend:
47+
name: Build & Push Frontend Docker Image to GHCR
48+
runs-on: ubuntu-latest
49+
permissions:
50+
contents: read
51+
packages: write
52+
53+
steps:
54+
- name: Checkout repository
55+
uses: actions/checkout@v4
56+
57+
- name: Periksa keberadaan Dockerfile Frontend
58+
id: check_files
59+
run: |
60+
if [ -f "frontend/Dockerfile" ]; then
61+
echo "exists=true" >> $GITHUB_OUTPUT
62+
else
63+
echo "exists=false" >> $GITHUB_OUTPUT
64+
echo "Dockerfile belum tersedia di frontend/. Melewatkan build Docker."
65+
fi
66+
67+
- name: Set up Docker Buildx
68+
if: steps.check_files.outputs.exists == 'true'
69+
uses: docker/setup-buildx-action@v3
70+
71+
- name: Log in to GitHub Container Registry (GHCR)
72+
if: steps.check_files.outputs.exists == 'true' && github.event_name != 'pull_request'
73+
uses: docker/login-action@v3
74+
with:
75+
registry: ${{ env.REGISTRY }}
76+
username: ${{ github.actor }}
77+
password: ${{ secrets.GITHUB_TOKEN }}
78+
79+
- name: Extract Docker metadata (tags, labels)
80+
if: steps.check_files.outputs.exists == 'true'
81+
id: meta
82+
uses: docker/metadata-action@v5
83+
with:
84+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
85+
tags: |
86+
type=ref,event=branch
87+
type=sha,format=short
88+
type=raw,value=latest,enable={{is_default_branch}}
89+
90+
- name: Build and push Frontend Docker image to GHCR
91+
if: steps.check_files.outputs.exists == 'true'
92+
uses: docker/build-push-action@v6
93+
with:
94+
context: ./frontend
95+
file: ./frontend/Dockerfile
96+
push: ${{ github.event_name != 'pull_request' }}
97+
tags: ${{ steps.meta.outputs.tags }}
98+
labels: ${{ steps.meta.outputs.labels }}
99+
cache-from: type=gha
100+
cache-to: type=gha,mode=max
101+
102+
103+
deploy-frontend:
104+
name: Deploy Frontend Stack via SSH
105+
runs-on: ubuntu-latest
106+
environment: staging
107+
108+
steps:
109+
- name: Checkout repository
110+
uses: actions/checkout@v4
111+
112+
- name: Copy Frontend Docker Compose file via SCP
113+
uses: appleboy/scp-action@v0.1.7
114+
with:
115+
host: ${{ secrets.SERVER_HOST }}
116+
username: ${{ secrets.SERVER_USER }}
117+
port: ${{ secrets.SERVER_PORT || '22' }}
118+
key: ${{ secrets.SSH_PRIVATE_KEY }}
119+
source: "frontend/docker-compose.yml"
120+
target: "${{ vars.DEPLOY_PATH_FRONTEND || secrets.DEPLOY_PATH_FRONTEND || format('/home/{0}/mini-grafana-frontend', secrets.SERVER_USER) }}"
121+
122+
- name: Deploy Frontend Stack to Server via SSH
123+
uses: appleboy/ssh-action@v1.0.3
124+
with:
125+
host: ${{ secrets.SERVER_HOST }}
126+
username: ${{ secrets.SERVER_USER }}
127+
port: ${{ secrets.SERVER_PORT || '22' }}
128+
key: ${{ secrets.SSH_PRIVATE_KEY }}
129+
script_stop: true
130+
script: |
131+
echo "=========================================================="
132+
echo " [1/3] Menentukan direktori dan Git Pull (Frontend)"
133+
echo "=========================================================="
134+
DEPLOY_DIR="${{ vars.DEPLOY_PATH_FRONTEND || secrets.DEPLOY_PATH_FRONTEND || format('/home/{0}/mini-grafana-frontend', secrets.SERVER_USER) }}"
135+
echo "Directori frontend deployment: $DEPLOY_DIR"
136+
mkdir -p "$DEPLOY_DIR"
137+
cd "$DEPLOY_DIR" || exit 1
138+
139+
# Jika ini repositori git atau folder tersendiri:
140+
if [ -d ".git" ]; then
141+
git fetch --all
142+
git reset --hard origin/main
143+
fi
144+
145+
echo "=========================================================="
146+
echo " [2/3] Menulis file .env dari secret ENV_FRONTEND"
147+
echo "=========================================================="
148+
cat <<'EOF_ENV' > .env
149+
${{ secrets.ENV_FRONTEND }}
150+
EOF_ENV
151+
chmod 600 .env
152+
153+
echo "=========================================================="
154+
echo " [3/3] Menjalankan / Merestart Container Frontend"
155+
echo "=========================================================="
156+
docker network inspect proxy_network >/dev/null 2>&1 || docker network create proxy_network
157+
cd frontend && docker compose up -d --force-recreate
158+
echo "✅ Deployment Frontend Dashboard selesai!"

.github/workflows/deploy-monitoring.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
paths:
77
- "monitoring/**"
88
- '.github/workflows/deploy-monitoring.yml'
9+
- '!**/**/*.md'
910

1011
workflow_dispatch: # Trigger manual dari GitHub Actions UI
1112

.github/workflows/deploy-ollama.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
paths:
77
- "ollama/**"
88
- '.github/workflows/deploy-ollama'
9-
9+
- '!**/**/*.md'
1010

1111
workflow_dispatch: # Trigger manual dari GitHub Actions UI
1212

0 commit comments

Comments
 (0)