-
Notifications
You must be signed in to change notification settings - Fork 0
139 lines (115 loc) · 3.7 KB
/
deploy.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
name: Web CI/CD Pipeline
on:
push:
branches:
- main
paths:
- frontend/**
jobs:
lint-and-test:
name: Lint and Test Code
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Cache Node.js modules
uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install Dependencies
working-directory: ./frontend
run: npm install
- name: Run Prettier Check
working-directory: ./frontend
run: npx prettier --check .
- name: Run ESLint
working-directory: ./frontend
run: npx eslint .
- name: Install Playwright Browsers
working-directory: ./frontend
run: npx playwright install --with-deps
- name: Run Tests
working-directory: ./frontend
run: npx playwright test
build:
name: Build Application
runs-on: ubuntu-latest
needs: lint-and-test
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Cache Node.js modules
uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install Dependencies
working-directory: ./frontend
run: npm ci
- name: Build the App
working-directory: ./frontend
run: npm run build
- name: Upload Build Artifacts
uses: actions/upload-artifact@v4
with:
name: frontend-build
path: ./frontend/build
docker:
name: Build and Push Docker Image
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Download Build Artifacts
uses: actions/download-artifact@v4
with:
name: frontend-build
path: ./frontend/build
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build Docker Image
working-directory: ./frontend
run: |
docker build -f prod.Dockerfile -t ${{ secrets.DOCKER_USERNAME }}/portfolio:frontend-latest .
docker tag ${{ secrets.DOCKER_USERNAME }}/portfolio:frontend-latest ${{ secrets.DOCKER_USERNAME }}/portfolio:frontend-${{ github.sha }}
- name: Push Docker Image
run: |
docker push ${{ secrets.DOCKER_USERNAME }}/portfolio:frontend-latest
docker push ${{ secrets.DOCKER_USERNAME }}/portfolio:frontend-${{ github.sha }}
deploy:
name: Deploy to k3s
runs-on: ubuntu-latest
needs: docker
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Set up kubectl
uses: azure/setup-kubectl@v4
with:
version: "latest"
- name: Configure kubeconfig
run: |
mkdir -p $HOME/.kube
echo "${{ secrets.KUBECONFIG }}" > $HOME/.kube/config
- name: Apply Kubernetes Manifest with Rollout
run: |
kubectl set image deployment/frontend frontend=${{ secrets.DOCKER_USERNAME }}/portfolio:frontend-latest --record
kubectl rollout restart deployment/frontend
kubectl rollout status deployment/frontend