-
Notifications
You must be signed in to change notification settings - Fork 0
73 lines (60 loc) · 2.35 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
61
62
63
64
65
66
67
68
69
70
71
72
73
name: CI/CD Pipeline
on:
push:
branches:
- main
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 ${{ secrets.GCE_REGION }}-docker.pkg.dev
- name: Build and push Docker image
env:
GCP_SA_KEY: ${{ secrets.GCP_SA_KEY }}
PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
GITHUB_SHA: ${{ github.sha }}
GCE_REGION: ${{ secrets.GCE_REGION }}
BUCKET_NAME: ${{ secrets.BUCKET_NAME }}
run: |
echo "$GCP_SA_KEY" > gcp-service-account-key.json
docker build --build-arg DATABASE_URL=${{ secrets.DATABASE_URL }} --build-arg GCS_BUCKET_NAME=$BUCKET_NAME --build-arg GCP_SA_KEY="$GCP_SA_KEY" -t $GCE_REGION-docker.pkg.dev/$PROJECT_ID/arsip-template/app:$GITHUB_SHA .
docker push $GCE_REGION-docker.pkg.dev/$PROJECT_ID/arsip-template/app:$GITHUB_SHA
- name: Copy docker-compose.yml to SSH server
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
source: "docker-compose.yml"
target: "${{ secrets.PROJECT_PATH }}/"
- name: Deploy to SSH server
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
export REGION=${{ secrets.GCE_REGION }}
export PROJECT_ID=${{ secrets.GCP_PROJECT_ID }}
export GITHUB_SHA=${{ github.sha }}
cd ${{ secrets.PROJECT_PATH }}
if [ ! -f docker-compose.yml ]; then
echo "docker-compose.yml not found in ${{ secrets.PROJECT_PATH }}"
exit 1
fi
# Pull the latest image from Google Artifact Registry
docker-compose pull
docker-compose down
docker-compose up -d