Skip to content

fixed compute engine deploy to use ssh with authorized user #16

fixed compute engine deploy to use ssh with authorized user

fixed compute engine deploy to use ssh with authorized user #16

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: oys
command: |-
"docker pull ${{ env.IMAGE_TAG }} \
&& docker stop $(docker ps -aq) \
&& docker run ${{ env.IMAGE_TAG }} \
&& docker image prune -a"
- name: Show Output
run: |-
echo `${{ steps.deploy.outputs.stdout }}`
echo `${{ steps.deploy.outputs.stderr }}`