Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update release flow with staging deployment and image building #118

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/build-image.yml
Original file line number Diff line number Diff line change
@@ -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 }}
12 changes: 12 additions & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand Down
62 changes: 62 additions & 0 deletions .github/workflows/staging-deploy.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading