-
Notifications
You must be signed in to change notification settings - Fork 0
69 lines (59 loc) · 2.09 KB
/
cicd-branch-main.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
name: CI/CD
on: push
env:
GOOGLE_PROJECT_ID: botchi
# GAR_LOCATION: asia-northeast3-docker.pkg.dev
# REPOSITORY: botchi/botchi-go
# SERVICE: botchi-go
GOOGLE_REGION: asia-northeast3
IMAGE_TAG: ${{ secrets.DOCKERHUB_USERNAME }}/${{ vars.APP_NAME }}:${{ github.ref_type }}-${{ github.ref_name }}
jobs:
cicd:
permissions:
contents: "read"
id-token: "write"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Google Auth
id: google-auth
uses: "google-github-actions/auth@v1"
with:
token_format: "access_token"
workload_identity_provider: "${{ secrets.GOOGLE_WORKLOAD_IDENTITY_PROVIDER }}"
service_account: "${{ secrets.GOOGLE_SERVICE_ACCOUNT }}"
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v5
with:
build-args: |
DISCORD_BOT_TOKEN=${{ secrets.DISCORD_BOT_TOKEN }}
DISCORD_BOT_LOG_GUILD_ID=${{ vars.DISCORD_BOT_LOG_GUILD_ID }}
DISCORD_BOT_LOG_CHANNEL_ID=${{ vars.DISCORD_BOT_LOG_CHANNEL_ID }}
tags: ${{ env.IMAGE_TAG }}
push: true
- name: Deploy to Compute engine
id: deploy
uses: google-github-actions/ssh-compute@v0
with:
instance_name: container-runner-main
zone: asia-northeast3-a
ssh_private_key: "${{ secrets.GCP_SSH_PRIVATE_KEY }}"
user: ${{ secrets.GCP_SSH_USER }}
command: |
docker pull ${{ env.IMAGE_TAG }}
if $(docker ps -aq); then
docker stop $(docker ps -aq); fi
docker run -d --rm ${{ env.IMAGE_TAG }}
docker image prune -af
- name: Show Output
run: |-
echo '${{ steps.deploy.outputs.stdout }}'
echo '${{ steps.deploy.outputs.stderr }}'