From ffea75af9f84fa096a59142fe67a037edf86c39b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=E1=BA=A1=20=C4=90=E1=BB=A9c=20B=E1=BA=A3o?= <146197243+DucBaoUIT@users.noreply.github.com> Date: Fri, 13 Dec 2024 17:28:36 +0700 Subject: [PATCH] Update deploymentCD.yaml --- .github/workflows/deploymentCD.yaml | 61 ++++++++++++++++------------- 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/.github/workflows/deploymentCD.yaml b/.github/workflows/deploymentCD.yaml index 4d59425..7ecfee4 100644 --- a/.github/workflows/deploymentCD.yaml +++ b/.github/workflows/deploymentCD.yaml @@ -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 @@ -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}} \ No newline at end of file + - 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 }}