Skip to content

Commit

Permalink
Update deploymentCD.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
DucBaoUIT committed Dec 13, 2024
1 parent 71fe318 commit ffea75a
Showing 1 changed file with 34 additions and 27 deletions.
61 changes: 34 additions & 27 deletions .github/workflows/deploymentCD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@ name: Continuous Deployment for User Service

on:
workflow_run:
workflows: ["Continuous Integration for Comment Service"]
workflows: ["Continuous Integration for User Service"]
types:
- completed

env:
PROJECT_ID: gke-project-423206
CLUSTER_NAME: autopilot-cluster-1
ZONE: us-central1
K8S_NAMESPACE: default

jobs:
deploy:
name: Deploy to GKE Autopilot
name: Deploy to Private K8S Server
runs-on: ubuntu-latest
steps:
- name: Checkout code
Expand All @@ -30,27 +28,36 @@ jobs:
mvn clean
mvn -B package --file pom.xml
- name: Authenticate
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.GCP_SA_KEY }}

- name: Configure gcloud
uses: google-github-actions/setup-gcloud@v2
with:
project_id: ${{ env.PROJECT_ID }}
install_components: 'gke-gcloud-auth-plugin'

- name: Set cluster context
- name: Install OpenVPN
run: sudo apt-get update && sudo apt-get install -y openvpn

- name: Connect to VPN
env:
VPN_USERNAME: ${{ secrets.VPN_USERNAME }}
VPN_PASSWORD: ${{ secrets.VPN_PASSWORD }}
run: |
gcloud container clusters get-credentials ${{ env.CLUSTER_NAME }} --zone ${{ env.ZONE }} --project ${{ env.PROJECT_ID }}
echo -e "${VPN_USERNAME}\n${VPN_PASSWORD}" > vpn-auth.txt
sudo openvpn --config profile-559.ovpn --auth-user-pass vpn-auth.txt --daemon
sleep 10
rm vpn-auth.txt
- name: Apply Kubernetes manifests
run: |
kubectl apply -f resources.yaml
notifications:
needs: deploy
uses: ./.github/workflows/notifyCD.yaml
secrets:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL}}
- name: Deploy to Server
uses: appleboy/ssh-action@v0.1.10
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USERNAME }}
key: ${{ secrets.SERVER_SSH_KEY }}
script: |
cd /home/ubuntu/K8S
kubectl apply -f user-mongo-deployment.yaml
kubectl apply -f user-service-deployment.yaml
# - name: Apply Kubernetes manifests
# run: |
# kubectl apply -f resources.yaml

# notifications:
# needs: deploy
# uses: ./.github/workflows/notifyCD.yaml
# secrets:
# SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

0 comments on commit ffea75a

Please sign in to comment.