From cb4b4f2cd9c35a76217fb64ec85307bef20bc621 Mon Sep 17 00:00:00 2001 From: Siddhartha Basu Date: Mon, 15 Apr 2024 06:33:25 -0500 Subject: [PATCH] refactor(.github/workflows/staging-build.yaml): simplify workflow by using shared docker-build-push workflow The staging-build workflow was simplified by removing the individual steps for building and pushing Docker images, and instead using a shared workflow for these tasks. This change was made to reduce redundancy and improve maintainability. --- .github/workflows/staging-build.yaml | 106 ++------------------------- 1 file changed, 7 insertions(+), 99 deletions(-) diff --git a/.github/workflows/staging-build.yaml b/.github/workflows/staging-build.yaml index e882b6f..023e54c 100644 --- a/.github/workflows/staging-build.yaml +++ b/.github/workflows/staging-build.yaml @@ -4,102 +4,10 @@ on: branches: - staging jobs: - build: - runs-on: ubuntu-20.04 - steps: - - name: set up golang - uses: actions/setup-go@v5 - with: - go-version: 1.13.15 - - name: check out code - uses: actions/checkout@v4 - - name: set up docker buildx - uses: docker/setup-buildx-action@v3 - - name: cache docker layers - uses: actions/cache@v4.0.2 - with: - path: /tmp/.buildx-cache - key: ${{ runner.os }}-buildx-${{ github.sha }} - restore-keys: | - ${{ runner.os }}-buildx- - - name: log into dockerhub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKER_USER }} - password: ${{ secrets.DOCKER_PASSWORD }} - - name: get short sha - id: vars - run: | - sha=$(git rev-parse --short HEAD) - echo ::set-output name=image_tag::${sha} - - name: docker build and push - uses: docker/build-push-action@v5 - with: - push: true - file: build/package/Dockerfile - tags: dictybase/${{ github.event.repository.name }}:staging-${{ steps.vars.outputs.image_tag }} - cache-from: type=local,src=/tmp/.buildx-cache - cache-to: type=local,dest=/tmp/.buildx-cache - - name: prepare for deploy - if: ${{ success() }} - id: prepare_deploy - uses: dictybase-docker/prepare-deploy@v2 - with: - cluster-name: staging - cluster-zone: "us-central1-a" - namespace: dictybase - chart-name: content-api-server - chart-path: deployments/charts/content-api-server - token: ${{ secrets.GITHUB_TOKEN }} - image-tag: staging-${{ steps.vars.outputs.image_tag }} - ref: ${{ github.ref }} - owner: ${{ github.repository_owner }} - repo: ${{ github.event.repository.name }} - artifact: ${{ github.event.repository.name }} - environment: staging - deploy: - runs-on: ubuntu-20.04 - needs: build - steps: - - name: check out code - uses: actions/checkout@v4 - - name: download deployment artifact - uses: actions/download-artifact@v4 - with: - name: ${{ github.event.repository.name }} - - name: download and setup path for github action binary - run: | - mkdir -p github-actions/bin - curl -L -o github-actions/bin/actions https://github.com/dictybase-docker/github-actions/releases/download/v2.1.4/action_2.1.4_Linux_x86_64 - chmod +x github-actions/bin/actions - echo "$GITHUB_WORKSPACE/github-actions/bin" >> $GITHUB_PATH - - name: extract information from deployment payload - id: deploy_info - run: actions --log-level debug sdp -f deployment.json - - name: set in_progress deployment status - if: ${{ success() }} - run: actions --log-level debug -t ${{ secrets.REPO_ACCESS_TOKEN }} --owner ${{ github.repository_owner }} -r ${{ github.event.repository.name }} ds --state in_progress --deployment_id ${{ steps.deploy_info.outputs.id }} --url ${{ steps.deploy_info.outputs.url }} - - name: setup google cloud sdk - uses: GoogleCloudPlatform/github-actions/setup-gcloud@master - with: - version: "313.0.1" - project_id: ${{ secrets.STAGING_PROJECT_ID }} - service_account_key: ${{ secrets.STAGING_SA_KEY }} - export_default_credentials: true - - name: set up helm - uses: azure/setup-helm@v1.1 - with: - version: "v2.16.12" - - name: add dictybase helm repo - run: helm init --client-only && helm repo add dictybase https://dictybase-docker.github.io/kubernetes-charts - - name: get gcloud credentials for k8s cluster - run: gcloud container clusters get-credentials --project ${{ secrets.STAGING_PROJECT_ID }} --zone ${{ steps.deploy_info.outputs.zone }} ${{ steps.deploy_info.outputs.cluster }} - - name: deploy chart - if: ${{ success() }} - run: actions --log-level debug dc --name ${{ steps.deploy_info.outputs.chart }} --namespace ${{ steps.deploy_info.outputs.namespace }} --image-tag ${{ steps.deploy_info.outputs.image_tag }} --path ${{ steps.deploy_info.outputs.path }} - - name: set successful deploy status - if: ${{ success() }} - run: actions --log-level debug -t ${{ secrets.REPO_ACCESS_TOKEN }} --owner ${{ github.repository_owner }} -r ${{ github.event.repository.name }} ds --state success --deployment_id ${{ steps.deploy_info.outputs.id }} --url ${{ steps.deploy_info.outputs.url }} - - name: set unsuccessful deploy status - if: ${{ failure() }} - run: actions --log-level debug -t ${{ secrets.REPO_ACCESS_TOKEN }} --owner ${{ github.repository_owner }} -r ${{ github.event.repository.name }} ds --state error --deployment_id ${{ steps.deploy_info.outputs.id }} --url ${{ steps.deploy_info.outputs.url }} + call-docker-build: + needs: test + uses: dictyBase/workflows/.github/workflows/docker-build-push.yaml@develop + secrets: inherit + with: + repository: ${{ github.repository }} + ref: ${{ github.ref_name }}