Skip to content

Commit b530b26

Browse files
committed
Update CI CD
1 parent d76a980 commit b530b26

File tree

3 files changed

+108
-13
lines changed

3 files changed

+108
-13
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Continuous Deployment for Frontend
2+
3+
on:
4+
workflow_run:
5+
workflows: ["Continuous Integration for Frontend"]
6+
types:
7+
- completed
8+
9+
10+
jobs:
11+
deploy:
12+
name: Deploy to GKE Autopilot
13+
runs-on: ubuntu-latest
14+
15+
strategy:
16+
matrix:
17+
node-version: [18.x]
18+
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v3
22+
23+
- name: Build the application
24+
run: |
25+
npm ci
26+
npm run build
27+
env:
28+
CI: ""
29+
30+
- name: Install OpenVPN
31+
run: sudo apt-get update && sudo apt-get install -y openvpn
32+
33+
- name: Connect to VPN
34+
env:
35+
VPN_USERNAME: ${{ secrets.VPN_USERNAME }}
36+
VPN_PASSWORD: ${{ secrets.VPN_PASSWORD }}
37+
run: |
38+
echo "${{ secrets.VPN_PROFILE_BASE64 }}" | base64 --decode > profile-559.ovpn
39+
echo -e "${VPN_USERNAME}\n${VPN_PASSWORD}" > vpn-auth.txt
40+
sudo openvpn --config profile-559.ovpn --auth-user-pass vpn-auth.txt --daemon
41+
sleep 10
42+
rm vpn-auth.txt
43+
rm profile-559.ovpn
44+
45+
- name: Deploy to Server
46+
uses: appleboy/[email protected]
47+
with:
48+
host: ${{ secrets.SERVER_HOST }}
49+
username: ${{ secrets.SERVER_USERNAME }}
50+
key: ${{ secrets.SERVER_SSH_KEY }}
51+
script: |
52+
cd /home/ubuntu/K8S
53+
sudo kubectl apply -f react-app-deployment.yaml
54+
55+
notifications:
56+
needs: deploy
57+
uses: ./.github/workflows/notifyCD.yaml
58+
secrets:
59+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

.github/workflows/main.yaml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,26 @@ jobs:
3333
- name: Set up MongoDB URI
3434
run: echo "SPRING_DATA_MONGODB_URI=mongodb://localhost:27017/frontend" >> $GITHUB_ENV
3535

36-
# sonar-cloud-scan:
37-
# needs: testing
38-
# uses: ./.github/workflows/sonarqube-scan.yaml
39-
# secrets:
40-
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
36+
sonar-cloud-scan:
37+
needs: testing
38+
uses: ./.github/workflows/sonarqube-scan.yaml
39+
secrets:
40+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
4141

4242
build-image:
4343
needs: testing
4444
uses: ./.github/workflows/build-image.yaml
4545
secrets:
4646
DOCKER_HUB_ACCESS_TOKEN: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
4747

48-
# scan-image:
49-
# needs: build-image
50-
# uses: ./.github/workflows/scan-image.yaml
48+
scan-image:
49+
needs: build-image
50+
uses: ./.github/workflows/scan-image.yaml
5151

52-
# notify:
53-
# needs: scan-image
54-
# uses: ./.github/workflows/notifyCI.yaml
55-
# secrets:
56-
# SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
52+
notify:
53+
needs: scan-image
54+
uses: ./.github/workflows/notifyCI.yaml
55+
secrets:
56+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
5757

5858
### Push image ###

.github/workflows/notifyCD.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Send Slack Notification for Frontend
2+
3+
on:
4+
workflow_call:
5+
secrets:
6+
SLACK_WEBHOOK_URL:
7+
required: true
8+
9+
jobs:
10+
success_notifier:
11+
if: success()
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Send success notification on Slack
15+
uses: slackapi/[email protected]
16+
with:
17+
payload: |
18+
{
19+
"text": "The Continuous Deployment for Frontend workflow has completed successfully."
20+
}
21+
env:
22+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
23+
24+
failure_notifier:
25+
if: failure()
26+
runs-on: ubuntu-latest
27+
steps:
28+
- name: Send failure notification on Slack
29+
uses: slackapi/[email protected]
30+
with:
31+
payload: |
32+
{
33+
"text": "The Continuous Deployment for Frontend workflow has failed."
34+
}
35+
env:
36+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

0 commit comments

Comments
 (0)