-
Notifications
You must be signed in to change notification settings - Fork 0
60 lines (46 loc) · 1.64 KB
/
cicd.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
name: CI/CD Pipeline
on:
push:
branches:
- main
env:
PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
GCE_INSTANCE: arsip-template-vm
GCE_INSTANCE_ZONE: asia-southeast1-c
REGION: asia-southeast1
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- id: "auth"
uses: "google-github-actions/auth@v2"
with:
credentials_json: "${{ secrets.GCP_SA_KEY }}"
- name: "Set up Cloud SDK"
uses: "google-github-actions/setup-gcloud@v2"
- name: "Use gcloud CLI"
run: "gcloud info"
- name: Configure Docker for Artifact Registry
run: |
gcloud auth configure-docker $REGION-docker.pkg.dev
- name: Build and push Docker image
run: |
docker build -t $REGION-docker.pkg.dev/$PROJECT_ID/arsip-template/app:${{ github.sha }} .
docker push $REGION-docker.pkg.dev/$PROJECT_ID/arsip-template/app:${{ github.sha }}
- name: Deploy to VM
run: |
gcloud compute ssh --zone $GCE_INSTANCE_ZONE $GCE_INSTANCE --command '
# Navigate to the project directory where docker-compose.yml is located
cd /home/fadhlurahman_i/projects/arsip-template
export REGION=asia-southeast1
export PROJECT_ID=${{ secrets.GCP_PROJECT_ID }}
export GITHUB_SHA=${{ github.sha }}
# Pull the new image
docker-compose pull
# Stop and remove the existing container (if any)
docker-compose down
# Start the new container with the updated image
docker-compose up -d
'