Skip to content

Commit b45e258

Browse files
committed
update conf
1 parent 7c5bff2 commit b45e258

5 files changed

Lines changed: 138 additions & 63 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: CI/CD Pipeline
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
env:
8+
IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/who-goes-to-try-frontend
9+
NAMESPACE: who-goes-to-try
10+
DEPLOYMENT_NAME: who-goes-to-try-frontend
11+
12+
jobs:
13+
build-and-deploy:
14+
name: Build, Push & Deploy
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
# ── 1. Checkout ──────────────────────────────────────────
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
22+
# ── 2. Build & Push Docker Image ─────────────────────────
23+
- name: Log in to Docker Hub
24+
uses: docker/login-action@v3
25+
with:
26+
username: ${{ secrets.DOCKERHUB_USERNAME }}
27+
password: ${{ secrets.DOCKERHUB_TOKEN }}
28+
29+
- name: Set image tag
30+
id: vars
31+
run: echo "tag=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
32+
33+
- name: Build and push Docker image
34+
uses: docker/build-push-action@v5
35+
with:
36+
context: .
37+
push: true
38+
tags: |
39+
${{ env.IMAGE_NAME }}:${{ steps.vars.outputs.tag }}
40+
${{ env.IMAGE_NAME }}:latest
41+
42+
# ── 3. Deploy ke Kubernetes ───────────────────────────────
43+
- name: Setup kubectl
44+
uses: azure/setup-kubectl@v3
45+
with:
46+
version: 'latest'
47+
48+
- name: Configure kubeconfig
49+
run: |
50+
mkdir -p $HOME/.kube
51+
echo "${{ secrets.KUBECONFIG_DATA }}" | base64 -d > $HOME/.kube/config
52+
chmod 600 $HOME/.kube/config
53+
54+
- name: Apply Kubernetes manifests
55+
run: |
56+
kubectl apply -f k8s/deployment.yaml
57+
kubectl apply -f k8s/service.yaml
58+
kubectl apply -f k8s/ingress.yaml
59+
60+
- name: Update image to latest build
61+
run: |
62+
kubectl set image deployment/${{ env.DEPLOYMENT_NAME }} \
63+
${{ env.DEPLOYMENT_NAME }}=${{ env.IMAGE_NAME }}:${{ steps.vars.outputs.tag }} \
64+
-n ${{ env.NAMESPACE }}
65+
66+
- name: Wait for rollout to finish
67+
run: |
68+
kubectl rollout status deployment/${{ env.DEPLOYMENT_NAME }} \
69+
-n ${{ env.NAMESPACE }} \
70+
--timeout=120s
71+
72+
- name: Show running pods
73+
run: kubectl get pods -n ${{ env.NAMESPACE }}

.github/workflows/main.yml

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

k8s/deployment.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: who-goes-to-try-frontend
5+
namespace: who-goes-to-try
6+
labels:
7+
app: who-goes-to-try-frontend
8+
spec:
9+
replicas: 2
10+
selector:
11+
matchLabels:
12+
app: who-goes-to-try-frontend
13+
template:
14+
metadata:
15+
labels:
16+
app: who-goes-to-try-frontend
17+
spec:
18+
containers:
19+
- name: who-goes-to-try-frontend
20+
image: DOCKER_USERNAME/who-goes-to-try-frontend:latest
21+
imagePullPolicy: Always
22+
ports:
23+
- containerPort: 80
24+
resources:
25+
requests:
26+
cpu: "100m"
27+
memory: "128Mi"
28+
limits:
29+
cpu: "250m"
30+
memory: "256Mi"

k8s/ingress.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apiVersion: networking.k8s.io/v1
2+
kind: Ingress
3+
metadata:
4+
name: who-goes-to-try-frontend
5+
namespace: who-goes-to-try
6+
annotations:
7+
nginx.ingress.kubernetes.io/rewrite-target: /
8+
spec:
9+
ingressClassName: nginx
10+
rules:
11+
- host: who-goes-to-try.hackathon.sev-2.com
12+
http:
13+
paths:
14+
- path: /
15+
pathType: Prefix
16+
backend:
17+
service:
18+
name: who-goes-to-try-frontend
19+
port:
20+
number: 80

k8s/service.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: who-goes-to-try-frontend
5+
namespace: who-goes-to-try
6+
labels:
7+
app: who-goes-to-try-frontend
8+
spec:
9+
selector:
10+
app: who-goes-to-try-frontend
11+
ports:
12+
- protocol: TCP
13+
port: 80
14+
targetPort: 80
15+
type: ClusterIP

0 commit comments

Comments
 (0)