From 00f1a9b4e72cec22b3a6c341ba05f2d4c9af7b1e Mon Sep 17 00:00:00 2001 From: Shivam Gutgutia Date: Fri, 15 Dec 2023 14:03:50 +0530 Subject: [PATCH] Trying new way to deplot to google cloud run --- .github/workflows/docker-image.yml | 27 -------------- .github/workflows/main.yml | 48 +++++++++++++++++++++++++ cloudbuild.yaml | 58 ------------------------------ 3 files changed, 48 insertions(+), 85 deletions(-) delete mode 100644 .github/workflows/docker-image.yml create mode 100644 .github/workflows/main.yml delete mode 100644 cloudbuild.yaml diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml deleted file mode 100644 index 43360ef..0000000 --- a/.github/workflows/docker-image.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Docker Image CI - -on: - push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] - -jobs: - - build: - - runs-on: windows-latest - - steps: - - uses: actions/checkout@v3 - - name: Build the Docker image - run: docker build . --file Dockerfile --tag shivamgutgutia/vcfgenerator - - - name: Login to Docker Hub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Push Docker image to Docker Hub - run: docker push shivamgutgutia/vcfgenerator diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..6c30331 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,48 @@ +name: Deploy to Google Cloud Run + +on: + push: + branches: + - main + +jobs: + setup-build-publish-deploy: + name: Setup, Build, Publish, and Deploy + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + + - name: Build and push Docker image + id: docker_build + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile + push: true + tags: shivamgutgutia/contactify:latest + + - name: Setup gcloud CLI + uses: google-github-actions/setup-gcloud@master + with: + project_id: shivam-contacts-generator + service_account_key: ${{ secrets.GCLOUD_AUTH }} + + - name: Deploy to Cloud Run + run: | + gcloud run deploy contacts-generator-backend-continuous \ + --image shivamgutgutia/contactify:latest \ + --region asia-south1 \ + --project=shivam-contacts-generator \ + && gcloud run services update-traffic contacts-generator-backend-continuous --to-latest --region=asia-south1\ + --platform managed diff --git a/cloudbuild.yaml b/cloudbuild.yaml deleted file mode 100644 index d7ca411..0000000 --- a/cloudbuild.yaml +++ /dev/null @@ -1,58 +0,0 @@ -steps: - # Delete previous containers based on the image (if any running) - - name: 'gcr.io/cloud-builders/gcloud' - entrypoint: 'bash' - args: - - '-c' - - | - set -x - for tag in $(gcloud container images list-tags "gcr.io/shivam-contacts-generator/github.com/shivamgutgutia/contactsgeneratorbackend" --format='get(digest)' --limit=999999); do - gcloud container images delete -q --force-delete-tags "gcr.io/shivam-contacts-generator/github.com/shivamgutgutia/contactsgeneratorbackend@$tag" || true - done - - # Delete previous images - - name: 'gcr.io/cloud-builders/docker' - entrypoint: 'bash' - args: - - '-c' - - | - set -x - docker images -a | grep 'gcr.io/shivam-contacts-generator/github.com/shivamgutgutia/contactsgeneratorbackend' | awk '{print $3}' | xargs -r docker rmi -f - - # Build the new image with the latest commit SHA as a tag - - name: 'gcr.io/cloud-builders/docker' - args: - - 'build' - - '-t' - - 'gcr.io/shivam-contacts-generator/github.com/shivamgutgutia/contactsgeneratorbackend:$COMMIT_SHA' - - '-f' - - 'Dockerfile' - - '.' - - # Push the new image to Google Container Registry - - name: 'gcr.io/cloud-builders/docker' - args: - - 'push' - - 'gcr.io/shivam-contacts-generator/github.com/shivamgutgutia/contactsgeneratorbackend:$COMMIT_SHA' - - # Fetch the latest commit SHA from environment variables - - name: 'gcr.io/cloud-builders/gcloud' - entrypoint: 'bash' - args: - - '-c' - - | - COMMIT_SHA=$(echo $COMMIT_SHA) - - # Deploy the new revision to Cloud Run using the updated image with the latest commit SHA - - name: 'gcr.io/cloud-builders/gcloud' - entrypoint: 'bash' - args: - - '-c' - - | - gcloud run deploy contacts-generator-backend-continuous \ - --image=gcr.io/shivam-contacts-generator/github.com/shivamgutgutia/contactsgeneratorbackend:$COMMIT_SHA \ - --region=asia-south1 \ - --project=shivam-contacts-generator \ - && gcloud run services update-traffic contacts-generator-backend-continuous --to-latest --region=asia-south1 -options: - logging: CLOUD_LOGGING_ONLY