PromucFlow_constructor/.github/workflows/on-demand-build-docker-image-deploy-preview.yml
Goutham Pratapa 48a1bff59e
chore: remove AWS_ROLE_ARN from deployment workflow and update deploy… (#41039)
… script for node affinity

### Changes Made
- Removed `AWS_ROLE_ARN` from the environment variables in the GitHub
Actions workflow for deploying the Helm chart.
- Cleaned up the `deploy_preview.sh` script by removing commented-out
code related to role assumption.
- Added a new `dp-node-affinity-values.yaml` file to define node
affinity and tolerations for deployment.

These changes streamline the deployment process and enhance the
configuration for node scheduling.

## Description
> [!TIP]  
> _Add a TL;DR when the description is longer than 500 words or
extremely technical (helps the content, marketing, and DevRel team)._
>
> _Please also include relevant motivation and context. List any
dependencies that are required for this change. Add links to Notion,
Figma or any other documents that might be relevant to the PR._


Fixes #`Issue Number`  
_or_  
Fixes `Issue URL`
> [!WARNING]  
> _If no issue exists, please create an issue first, and check with the
maintainers if the issue is valid._

## Automation

/ok-to-test tags=""

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!CAUTION]  
> If you modify the content in this section, you are likely to disrupt
the CI result for your PR.

<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No
2025-06-25 18:21:38 +05:30

301 lines
12 KiB
YAML

name: On demand build Docker image and deploy preview
on:
# This workflow is only triggered by the `/build-deploy-preview` command dispatch
repository_dispatch:
types: [build-deploy-preview-command]
jobs:
notify-job-details:
runs-on: ubuntu-latest
steps:
# This step creates a comment on the PR with a link to this workflow run.
- name: Add a comment on the PR with link to workflow run
uses: peter-evans/create-or-update-comment@v3
with:
issue-number: ${{ github.event.client_payload.pull_request.number }}
body: |
Deploying Your Preview: <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}>.
Workflow: `${{ github.workflow }}`.
skip-tests: `${{ github.event.client_payload.slash_command.args.named.skip-tests }}`.
env: `${{ github.event.client_payload.slash_command.args.named.env }}`.
PR: ${{ github.event.client_payload.pull_request.number }}.
recreate: ${{ github.event.client_payload.slash_command.args.named.recreate }}.
server-build:
name: server-build
if: github.event.client_payload.slash_command.args.named.env != 'release'
uses: ./.github/workflows/server-build.yml
secrets: inherit
with:
pr: ${{ github.event.client_payload.pull_request.number }}
skip-tests: ${{ github.event.client_payload.slash_command.args.named.skip-tests }}
is-pg-build: ${{ github.event.client_payload.pull_request.base.ref == 'pg' }}
client-build:
name: client-build
if: github.event.client_payload.slash_command.args.named.env != 'release'
uses: ./.github/workflows/client-build.yml
secrets: inherit
with:
pr: ${{ github.event.client_payload.pull_request.number }}
skip-tests: ${{ github.event.client_payload.slash_command.args.named.skip-tests }}
rts-build:
name: rts-build
if: github.event.client_payload.slash_command.args.named.env != 'release'
uses: ./.github/workflows/rts-build.yml
secrets: inherit
with:
pr: ${{ github.event.client_payload.pull_request.number }}
skip-tests: ${{ github.event.client_payload.slash_command.args.named.skip-tests }}
vercel-build:
name: vercel-build
if: github.event.client_payload.slash_command.args.named.env == 'release'
runs-on: ubuntu-latest
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
steps:
- name: Checkout PR
uses: actions/checkout@v4
with:
ref: "refs/pull/${{ github.event.client_payload.pull_request.number }}/merge"
- name: Install Vercel CLI
run: npm install --global vercel@latest
- name: Use Node.js
if: steps.run_result.outputs.run_result != 'success'
uses: actions/setup-node@v4
with:
node-version-file: app/client/package.json
# actions/setup-node@v4 doesn't work properly with Yarn 3
# when the project lives in a subdirectory: https://github.com/actions/setup-node/issues/488
# Restoring the cache manually instead
- name: Restore Yarn cache
if: steps.run_result.outputs.run_result != 'success'
uses: actions/cache@v4
with:
path: app/.yarn/cache
key: v1-yarn3-${{ hashFiles('app/yarn.lock') }}
restore-keys: |
v1-yarn3-
- name: Pull Vercel Environment Information
run: vercel pull --yes --token=${{ secrets.VERCEL_TOKEN }}
- name: Build Project Artifacts
run: vercel build --yes --token=${{ secrets.VERCEL_TOKEN }}
- name: Deploy Project Artifacts to Vercel
run: |
vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }} | tee -a ~/run_result.txt
- uses: actions/github-script@v7
with:
script: |
const dpUrl = require("fs").readFileSync(process.env.HOME + "/run_result.txt", "utf8")
const bodyLines = ["Deploy-Preview-URL: " + dpUrl]
if (context.repo.repo === "appsmith") {
bodyLines.push(
"",
"🚨 *Note*: The release environment runs EE code, so using a frontend-only DP on this repo, will",
"likely behave unexpectedly. Consider using a full DP instead.",
"[Learn more](https://notion.so/031b87bce3404e3a95240d4c14c82e46).",
)
}
github.rest.issues.createComment({
issue_number: context.payload.client_payload.pull_request.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: bodyLines.join("\n"),
})
push-image:
needs: [client-build, rts-build, server-build]
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
if: success()
steps:
# Check out merge commit
- name: Checkout PR
uses: actions/checkout@v4
with:
ref: "refs/pull/${{ github.event.client_payload.pull_request.number }}/merge"
# Timestamp will be used to create cache key
- id: timestamp
run: echo "timestamp=$(date +'%Y-%m-%dT%H:%M:%S')" >> $GITHUB_OUTPUT
# get Git-hash will be used to create cache key
- id: git_hash
run: echo "git_hash=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Download the client build artifact
uses: actions/download-artifact@v4
with:
name: client-build
path: app/client
- name: Unpack the client build artifact
if: steps.run_result.outputs.run_result != 'success'
run: |
mkdir -p app/client/build
tar -xvf app/client/build.tar -C app/client/build
- name: Download the server build artifact
uses: actions/download-artifact@v4
with:
name: server-build
path: app/server/dist
- name: Download the rts build artifact
uses: actions/download-artifact@v4
with:
name: rts-dist
path: app/client/packages/rts/dist
- name: Untar the rts folder
run: |
tar -xvf app/client/packages/rts/dist/rts-dist.tar -C app/client/packages/rts/
echo "Cleaning up the tar files"
rm app/client/packages/rts/dist/rts-dist.tar
- name: Generate info.json
id: info_json
run: |
scripts/generate_info_json.sh
- name: Place server artifacts-es
run: |
if [[ -f scripts/prepare_server_artifacts.sh ]]; then
scripts/prepare_server_artifacts.sh
fi
- name: Set up Depot CLI
uses: depot/setup-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Set base image tag
id: set_base_tag
run: |
if [[ ${{ github.event.client_payload.pull_request.base.ref }} == 'pg' ]]; then
base_tag=pg
else
base_tag=release
fi
echo "base_tag=$base_tag" >> $GITHUB_OUTPUT
- name: Push to Docker Hub
uses: depot/build-push-action@v1
with:
context: .
pull: true
push: true
platforms: linux/arm64,linux/amd64
cache-from: ${{ vars.DOCKER_HUB_ORGANIZATION }}/appsmith-${{ vars.EDITION }}:release
tags: |
${{ vars.DOCKER_HUB_ORGANIZATION }}/appsmith-dp:${{ vars.EDITION }}-${{ github.event.client_payload.pull_request.number }}
labels: |
org.opencontainers.image.revision=${{ steps.info_json.outputs.commitSha }}
org.opencontainers.image.source=${{ steps.info_json.outputs.repo }}
org.opencontainers.image.version=${{ steps.info_json.outputs.version }}
build-args: |
APPSMITH_CLOUD_SERVICES_BASE_URL=https://release-cs.appsmith.com
BASE=${{ vars.DOCKER_HUB_ORGANIZATION }}/base-${{ vars.EDITION }}:${{ steps.set_base_tag.outputs.base_tag }}
outputs:
imageHash: ${{ vars.EDITION }}-${{ github.event.client_payload.pull_request.number }}
build-deploy-preview:
needs: [push-image]
runs-on: ubuntu-latest
defaults:
run:
working-directory: "."
if: success()
steps:
- name: Checkout PR
uses: actions/checkout@v4
with:
ref: "refs/pull/${{ github.event.client_payload.pull_request.number }}/merge"
- name: Print versions of tools
run: |
set -o errexit
set -o xtrace
aws --version || true
kubectl version || true
helm version || true
- name: Install mongosh
run: |
curl -fsSL https://pgp.mongodb.com/server-6.0.asc \
| sudo gpg -o /usr/share/keyrings/mongodb-server-6.0.gpg --dearmor
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-6.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/6.0 multiverse" \
| sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
sudo apt-get update
sudo apt-get install --yes mongodb-mongosh
echo "MongoSH version: $(mongosh --version)"
- name: Install relevant packages
run: |
set -o errexit
# We still need Kubectl v1.23. Once we up the cluster version, we can get rid of this step.
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.23.6/bin/linux/amd64/kubectl
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
kubectl version || true
- name: Deploy Helm chart
env:
AWS_ACCESS_KEY_ID: ${{ secrets.APPSMITH_CI_AWS_SECRET_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.APPSMITH_CI_AWS_SECRET_ACCESS_KEY }}
IMAGE_HASH: ${{ needs.push-image.outputs.imageHash }}
AWS_RELEASE_CERT: ${{ secrets.APPSMITH_AWS_RELEASE_CERT_RELEASE }}
DOCKER_HUB_ORGANIZATION: ${{ vars.DOCKER_HUB_ORGANIZATION }}
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
DOCKER_HUB_ACCESS_TOKEN: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
PULL_REQUEST_NUMBER: ${{ github.event.client_payload.pull_request.number }}
RECREATE: ${{ github.event.client_payload.slash_command.args.named.recreate }}
DB_USERNAME: ${{ secrets.DB_USERNAME }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
DB_URL: ${{ secrets.DB_URL }}
DP_EFS_ID: ${{ secrets.APPSMITH_DP_EFS_ID }}
DP_POSTGRES_URL: ${{ secrets.DP_POSTGRES_URL }}
REDIS_URL: ${{ secrets.APPSMITH_DP_REDIS_URL }}
OPENAI_ASSISTANT_ID: ${{ secrets.OPENAI_ASSISTANT_ID }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
APPSMITH_CARBON_API_KEY: ${{ secrets.APPSMITH_CARBON_API_KEY }}
APPSMITH_CARBON_API_BASE_PATH: ${{ secrets.APPSMITH_CARBON_API_BASE_PATH }}
APPSMITH_AI_SERVER_MANAGED_HOSTING: ${{ secrets.APPSMITH_AI_SERVER_MANAGED_HOSTING }}
IN_DOCKER: ${{ secrets.IN_DOCKER }}
run: |
echo "environment variables set to deploy the image" $IMAGE_HASH
/bin/bash ./scripts/deploy_preview.sh
notify-url:
needs: [build-deploy-preview]
runs-on: ubuntu-latest
if: success()
steps:
# This step creates a comment on the PR with a link to this workflow run.
- name: Add a comment on the PR with link to Deploy-Preview
uses: peter-evans/create-or-update-comment@v3
with:
issue-number: ${{ github.event.client_payload.pull_request.number }}
body: |
Deploy-Preview-URL: https://${{ vars.EDITION }}-${{ github.event.client_payload.pull_request.number }}.dp.appsmith.com