From 2353952b9d0b4059a158cda971d6215aa66d6f1c Mon Sep 17 00:00:00 2001 From: Kim Dongyun <76711238+myway00@users.noreply.github.com> Date: Thu, 21 Sep 2023 15:36:55 +0900 Subject: [PATCH] add : cicd.yml for build,deploy automation --- .github/workflows/cicd.yml | 59 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 .github/workflows/cicd.yml diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml new file mode 100644 index 0000000..b228d4b --- /dev/null +++ b/.github/workflows/cicd.yml @@ -0,0 +1,59 @@ +# Copyright 2020 Google, LLC. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: Build and Deploy to Google Compute Engine + +on: + push: + branches: + - master + +env: + PROJECT_ID: $ + GCE_INSTANCE: test # TODO: update to instance name + GCE_INSTANCE_ZONE: asia-northeast3 # TODO: update to instance zone + +jobs: + setup-build-publish-deploy: + name: Setup, Build, Publish, and Deploy + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v2 + + # Setup gcloud CLI + - uses: GoogleCloudPlatform/github-actions/setup-gcloud@master + with: + version: '290.0.1' + service_account_key: $ + project_id: $ + + # Configure Docker to use the gcloud command-line tool as a credential + # helper for authentication + - run: |- + gcloud --quiet auth configure-docker + # Build the Docker image + - name: Build + run: |- + docker build --tag "gcr.io/$PROJECT_ID/$GCE_INSTANCE-image:$GITHUB_SHA" . + # Push the Docker image to Google Container Registry + - name: Publish + run: |- + docker push "gcr.io/$PROJECT_ID/$GCE_INSTANCE-image:$GITHUB_SHA" + - name: Deploy + run: |- + gcloud compute instances update-container "$GCE_INSTANCE" \ + --zone "$GCE_INSTANCE_ZONE" \ + --container-image "gcr.io/$PROJECT_ID/$GCE_INSTANCE-image:$GITHUB_SHA"