From 15a27d7865c31f0de9264ce5cdfdd7e4d4a6ab73 Mon Sep 17 00:00:00 2001 From: Sai Sankeerth Date: Mon, 18 Mar 2024 19:03:03 +0530 Subject: [PATCH 1/4] chore: add build image on PR raise chore: add logic to deploy into staging environment when a PR is raised to main chore: reuse build, push image & deployment into staging environment --- .github/workflows/build-image.yml | 38 +++++++++++++++++ .github/workflows/release-please.yml | 12 ++++++ .github/workflows/staging-deploy.yml | 62 ++++++++++++++++++++++++++++ 3 files changed, 112 insertions(+) create mode 100644 .github/workflows/build-image.yml create mode 100644 .github/workflows/staging-deploy.yml diff --git a/.github/workflows/build-image.yml b/.github/workflows/build-image.yml new file mode 100644 index 0000000..32144b8 --- /dev/null +++ b/.github/workflows/build-image.yml @@ -0,0 +1,38 @@ +name: Build Artifacts for PRs + +on: + pull_request: + types: + - opened + - reopened + - synchronize + +jobs: + generate-tag: + name: Generate docker tag + runs-on: ubuntu-latest + outputs: + image_tag: ${{steps.gen_tag_names.outputs.tag_name}} + steps: + - name: Checkout + uses: actions/checkout@v4.1.1 + with: + fetch-depth: 1 + + # Replace problematic characters in branch name (like '/') with safe characters (like '.') + - name: Generate Tag Names + id: gen_tag_names + run: | + tag_name=$(echo ${{ github.head_ref }} | tr "/" .) + echo "Tag Name: $tag_name" + echo "tag_name=$tag_name" >> $GITHUB_OUTPUT + + build: + name: Build Shopify Tracker Docker Image + uses: ./.github/workflows/build-and-push-docker-image.yml + needs: [generate-tag] + with: + img_tag: ${{ needs.generate-tag.outputs.image_tag }} + secrets: + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} + DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml index 79630fb..99b1d4a 100644 --- a/.github/workflows/release-please.yml +++ b/.github/workflows/release-please.yml @@ -10,6 +10,7 @@ jobs: runs-on: ubuntu-latest outputs: release_created: ${{ steps.release.outputs.release_created }} + pr_created: ${{steps.release.outputs.pr_created}} release_version: ${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }}.${{ steps.release.outputs.patch }} steps: - name: Extract Branch Name @@ -29,6 +30,17 @@ jobs: bump-minor-pre-major: true bump-patch-for-minor-pre-major: true + staging-deploy-pr: + if: ${{needs.release-please.outputs.pr_created}} + needs: [release-please] + uses: ./.github/workflows/staging-deploy.yml + with: + image_tag: ${{needs.release-please.outputs.release_version}} + secrets: + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} + DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} + PAT: ${{ secrets.PAT }} + production-release: name: Make production release for shopify-tracker needs: [release-please] diff --git a/.github/workflows/staging-deploy.yml b/.github/workflows/staging-deploy.yml new file mode 100644 index 0000000..074d6e1 --- /dev/null +++ b/.github/workflows/staging-deploy.yml @@ -0,0 +1,62 @@ +name: Deploy shopify-tracker to staging environment +on: + workflow_call: + inputs: + image_tag: + type: string + required: true + description: docker image which needs to be deployed to staging environment + secrets: + DOCKERHUB_USERNAME: + required: true + DOCKERHUB_TOKEN: + required: true + PAT: + required: true + description: Personal access token to be used for cloning rudder-devops + +permissions: read-all + +jobs: + prepare-staging-image-tag: + runs-on: ubuntu-latest + outputs: + tag_name_stg: "staging-${{inputs.image_tag}}" + + build-push-staging-image: + needs: [prepare-staging-image-tag] + uses: ./.github/workflows/build-and-push-docker-image.yml + with: + img_tag: ${{ needs.prepare-staging-image-tag.outputs.tag_name_stg }} + secrets: + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} + DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} + + deploy-to-staging: + runs-on: ubuntu-latest + needs: [prepare-staging-image-tag, build-push-staging-image] + steps: + - name: Initialize Mandatory Git Config + run: | + git config --global user.name "GitHub Actions" + git config --global user.email "noreply@github.com" + + - name: Clone Devops Repo + run: | + git clone https://${{secrets.PAT}}@github.com/rudderlabs/rudder-devops.git + + - name: Create staging PR + env: + GITHUB_TOKEN: ${{ secrets.PAT }} + SP_IMAGE_REPOSITORY: rudderstack/rudder-shopify-tracker + TAG_NAME: ${{needs.prepare-staging-image-tag.outputs.tag_name_stg}} + run: | + cd rudder-devops + git checkout -b shopify-tracker-$TAG_NAME $TAG_NAME + cd helm-charts/helm/shopify-tracking/environment/staging + yq eval -i ".image.tag=\"$TAG_NAME\"" base.yaml + yq eval -i ".image.repository=\"$SP_IMAGE_REPOSITORY\"" base.yaml + git add base.yaml + git commit -m "chore: upgrade shopify tracker to $TAG_NAME" + git push -u origin shopify-tracker-$TAG_NAME + gh pr create --fill \ No newline at end of file From 7d5b43c266b59f384ef32e234584f9b76451c0c5 Mon Sep 17 00:00:00 2001 From: Sai Sankeerth Date: Mon, 18 Mar 2024 19:10:38 +0530 Subject: [PATCH 2/4] fix: add install packages step Signed-off-by: Sai Sankeerth --- .github/workflows/build-and-push-docker-image.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/build-and-push-docker-image.yml b/.github/workflows/build-and-push-docker-image.yml index 68c7c0c..18f8aa8 100644 --- a/.github/workflows/build-and-push-docker-image.yml +++ b/.github/workflows/build-and-push-docker-image.yml @@ -28,6 +28,18 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Setup Node + uses: actions/setup-node@v4.0.2 + with: + node-version-file: '.nvmrc' + cache: 'npm' + + - name: Install Dependencies + env: + HUSKY: 0 + run: | + npm ci + - name: Build and Push Images uses: docker/build-push-action@v5 with: From 4aa4be12bee7eef199a2ea30f25438ec6fa55f61 Mon Sep 17 00:00:00 2001 From: Sai Sankeerth Date: Mon, 18 Mar 2024 22:05:50 +0530 Subject: [PATCH 3/4] chore: update install script in Dockerfile Signed-off-by: Sai Sankeerth --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 3043ba6..4e29901 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ COPY package*.json ./ COPY . . RUN rm -rf /usr/src/app/node_modules -RUN npm install --only=prod +RUN npm ci --no-audit --cache .npm # If you are building your code for production # RUN npm ci --only=production From 13a1fbfaacedd4b781d87c5dc5f8c876a9bde9a0 Mon Sep 17 00:00:00 2001 From: Sai Sankeerth Date: Mon, 18 Mar 2024 22:11:31 +0530 Subject: [PATCH 4/4] chore: remove unnecessary npm ci command in build-and-push GHA Signed-off-by: Sai Sankeerth --- .github/workflows/build-and-push-docker-image.yml | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/.github/workflows/build-and-push-docker-image.yml b/.github/workflows/build-and-push-docker-image.yml index 18f8aa8..68c7c0c 100644 --- a/.github/workflows/build-and-push-docker-image.yml +++ b/.github/workflows/build-and-push-docker-image.yml @@ -28,18 +28,6 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Setup Node - uses: actions/setup-node@v4.0.2 - with: - node-version-file: '.nvmrc' - cache: 'npm' - - - name: Install Dependencies - env: - HUSKY: 0 - run: | - npm ci - - name: Build and Push Images uses: docker/build-push-action@v5 with: