CI/CD pipeline for UserService #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Continuous Deployment for Comment Service | |
on: | |
push: | |
branches: | |
- main | |
env: | |
PROJECT_ID: gke-project-423206 | |
CLUSTER_NAME: autopilot-cluster-1 | |
ZONE: us-central1 | |
jobs: | |
deploy: | |
name: Deploy to GKE Autopilot | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Setup JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'corretto' | |
java-version: 17 | |
- name: Build the application | |
run: | | |
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: Login to Docker Hub | |
uses: docker/login-action@v1 | |
with: | |
username: datuits | |
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | |
- name: Build and Push the docker image | |
run: | | |
docker build -t datuits/devops-user-service:latest . | |
docker push datuits/devops-user-service:latest | |
- name: Set cluster context | |
run: | | |
gcloud container clusters get-credentials ${{ env.CLUSTER_NAME }} --zone ${{ env.ZONE }} --project ${{ env.PROJECT_ID }} | |
- name: Apply Kubernetes manifests | |
run: | | |
kubectl apply -f resources.yaml |