1+ name : Argo Continuous Deployment for Comment Service
2+
3+ on :
4+ push :
5+ branches :
6+ - main
7+
8+ env :
9+ PROJECT_ID : devops-project-426109
10+ CLUSTER_NAME : autopilot-cluster-1
11+ ZONE : us-central1
12+
13+ jobs :
14+ deploy :
15+ name : Deploy to GKE Autopilot
16+ runs-on : ubuntu-latest
17+ steps :
18+ - name : Checkout code
19+ uses : actions/checkout@v3
20+
21+ - name : Setup JDK 17
22+ uses : actions/setup-java@v3
23+ with :
24+ distribution : ' corretto'
25+ java-version : 17
26+
27+ - name : Authenticate
28+ uses : google-github-actions/auth@v2
29+ with :
30+ credentials_json : ${{ secrets.GCP_SA_KEY_2 }}
31+
32+ - name : Configure gcloud
33+ uses : google-github-actions/setup-gcloud@v2
34+ with :
35+ project_id : ${{ env.PROJECT_ID }}
36+ install_components : ' gke-gcloud-auth-plugin'
37+
38+ - name : Set cluster context
39+ run : |
40+ gcloud container clusters get-credentials ${{ env.CLUSTER_NAME }} --zone ${{ env.ZONE }} --project ${{ env.PROJECT_ID }}
41+
42+ - name : Install ArgoCD CLI
43+ run : |
44+ curl -sSL -o argocd-linux-amd64 https://github.com/argoproj/argo-cd/releases/latest/download/argocd-linux-amd64
45+ sudo install -m 555 argocd-linux-amd64 /usr/local/bin/argocd
46+ rm argocd-linux-amd64
47+
48+ - name : Install ArgoCD in Kubernetes cluster
49+ run : |
50+ kubectl create namespace argocd || true
51+ kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
52+
53+ - name : Wait for ArgoCD server to be ready
54+ run : |
55+ kubectl wait --for=condition=available --timeout=600s deployment/argocd-server -n argocd
56+
57+ - name : Get ArgoCD initial admin password
58+ id : argocd_password
59+ run : |
60+ ARGOCD_PASSWORD=$(kubectl get pods -n argocd -l app.kubernetes.io/name=argocd-server -o jsonpath='{.items[0].metadata.name}')
61+ echo "::set-output name=ARGOCD_PASSWORD::${ARGOCD_PASSWORD}"
62+
63+ - name : Login to ArgoCD
64+ run : |
65+ argocd login --insecure --username admin --password ${{ steps.argocd_password.outputs.ARGOCD_PASSWORD }} --grpc-web argocd-server.argocd.svc.cluster.local:443
66+
67+ - name : Create ArgoCD application
68+ run : |
69+ argocd app create comment-service \
70+ --repo https://github.com/DevOps-Video-Sharing/CommentService \
71+ --path k8s \
72+ --dest-server https://kubernetes.default.svc \
73+ --dest-namespace default
74+
75+ - name : Sync ArgoCD application
76+ run : |
77+ argocd app sync comment-service
78+
79+ notify :
80+ needs : deploy
81+ uses : ./.github/workflows/notifyCD.yaml
82+ secrets :
83+ SLACK_WEBHOOK_URL : ${{ secrets.SLACK_WEBHOOK_URL }}
0 commit comments