ci: Deploy preview from branch (#25846)

Updated ad-hoc dp workflow to update the db with progress.
- This workflow should only be called via internal ops api.
- This workflow uses the internal ops api to patch data with the updates
on the workflow statuses.

---------

Co-authored-by: Shrikant Sharat Kandula <shrikant@appsmith.com>
This commit is contained in:
Sumesh Pradhan 2023-08-07 10:59:42 +05:30 committed by GitHub
parent d58c7ff8d3
commit be9c935732
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 97 deletions

View File

@ -12,37 +12,26 @@ on:
description: "Flag to skip Cypress tests"
required: true
default: "true"
uid:
description: "Unique ID to store the run data in the db"
required: false
id:
description: "Document ID for the workflow entry in the MongoDB ( This gets initialized by the ops api )"
required: true
sub-domain-name:
description: "Sub-domain for dp.appsmith.com to by used by this deploy preview (This will also be the image name and the k8s namespace identifier)"
required: true
jobs:
# write-job-details-to-db:
# runs-on: ubuntu-latest
# steps:
# - name: Install mongosh
# run: |
# sudo apt-get update
# sudo apt-get install -y wget gnupg
# wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -
# echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
# sudo apt-get update
# sudo apt-get install -y mongodb-mongosh
# - name: Update job data to mongoDB
# run: |
# # mongosh '' --eval 'db.appsmiht-ce-github-dp-runs.insert( { run_id: ${{ github.run_id }}, uid: ${{ github.event.inputs.uid }}, status: "Started" } )'
# mongosh '' --eval 'db.appsmiht-ce-github-dp-runs.update(
# { _id: ${{ github.event.inputs.uid }} },
# {
# $set: {
# run_id: ${{ github.run_id }},
# status: "BUILD IN PROGRESS"
# }
# }
# )'
# #TODO Add mongo URI as secret
update-job-details-to-db:
runs-on: ubuntu-latest
steps:
- name: Update workflow details
run: |
curl --request PATCH 'https://ops.appsmith.com/appsmith_deploy_workflow/${{github.event.inputs.uid}}' \
--header 'Content-Type: application/json' \
--oauth2-bearer '${{secrets.INTENRAL_OPS_API_TOKEN}}' \
--data ' {
"status": "IN_PROGRESS",
"githubWorkflowId": "${{github.workflow.id}}",
"githubWorkflowHtmlUrl": "${{github.workflow.githubWorkflowHtmlUrl}}",
}'
server-build:
name: server-build
@ -72,31 +61,11 @@ jobs:
runs-on: ubuntu-latest
if: success()
steps:
# - name: Install mongosh
# run: |
# sudo apt-get update
# sudo apt-get install -y wget gnupg
# wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -
# echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
# sudo apt-get update
# sudo apt-get install -y mongodb-mongosh
# - name: Update job data to mongoDB
# run: |
# # mongosh '' --eval 'db.appsmiht-ce-github-dp-runs.insert( { run_id: ${{ github.run_id }}, uid: ${{ github.event.inputs.uid }}, status: "Started" } )'
# mongosh '' --eval 'db.appsmiht-ce-github-dp-runs.update(
# { _id: ${{ github.event.inputs.uid }} },
# {
# $set: {
# status: "BUILD SUCCESSFUL"
# }
# }
# )'
# Check out merge commit
- name: Checkout PR
- name: Checkout Branch
uses: actions/checkout@v3
with:
ref: "refs/pull/${{ github.event.client_payload.pull_request.number }}/merge"
ref: ${{ github.event.inputs.branch }}
# Timestamp will be used to create cache key
- id: timestamp
@ -166,30 +135,10 @@ jobs:
if: success()
steps:
- name: Install mongosh
run: |
sudo apt-get update
sudo apt-get install -y wget gnupg
wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
sudo apt-get update
sudo apt-get install -y mongodb-mongosh
- name: Update job data to mongoDB
run: |
# mongosh '' --eval 'db.appsmiht-ce-github-dp-runs.insert( { run_id: ${{ github.run_id }}, uid: ${{ github.event.inputs.uid }}, status: "Started" } )'
# mongosh '' --eval 'db.appsmiht-ce-github-dp-runs.update(
# { _id: ${{ github.event.inputs.uid }} },
# {
# $set: {
# status: "DEPLOYMENT IN PROGRESS"
# }
# }
# )'
- name: Checkout PR
uses: actions/checkout@v3
with:
ref: "refs/pull/${{ github.event.client_payload.pull_request.number }}/merge"
fetch-depth: 0
ref: ${{ github.event.inputs.branch }}
- name: Install relevant packages
run: |
@ -216,35 +165,30 @@ jobs:
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
DB_URL: ${{ secrets.DB_URL }}
run: |
echo "environment variables set to deploy the image" $IMAGE_HASH
/bin/bash ./scripts/build_dp_form_branch.sh
echo "environment variables set to deploy the image $IMAGE_HASH"
/bin/bash ./scripts/build_dp_from_branch.sh
update-db-on-completion:
needs: [build-deploy-preview]
runs-on: ubuntu-latest
if: success()
steps:
- run: echo "Workflow completed successfully!"
- name: Update workflow completed successfully
if: success()
run: |
curl --request PATCH 'https://ops.appsmith.com/appsmith_deploy_workflow/${{github.event.inputs.id}}' \
--header 'Content-Type: application/json' \
--oauth2-bearer '${{secrets.INTENRAL_OPS_API_TOKEN}}' \
--data ' {
"status": "COMPLETED"
}'
- name: Update workflow failure
if: failure()
run: |
curl --request PATCH 'https://ops.appsmith.com/appsmith_deploy_workflow/${{github.event.inputs.id}}' \
--header 'Content-Type: application/json' \
--oauth2-bearer '${{secrets.INTENRAL_OPS_API_TOKEN}}' \
--data ' {
"status": "FAILED"
}'
# This step creates a comment on the PR with a link to this workflow run.
# - name: Install mongosh
# run: |
# sudo apt-get update
# sudo apt-get install -y wget gnupg
# wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -
# echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
# sudo apt-get update
# sudo apt-get install -y mongodb-mongosh
# - name: Update job data to mongoDB
# run: |
# # mongosh '' --eval 'db.appsmiht-ce-github-dp-runs.insert( { run_id: ${{ github.run_id }}, uid: ${{ github.event.inputs.uid }}, status: "Started" } )'
# mongosh '' --eval 'db.appsmiht-ce-github-dp-runs.update(
# { _id: ${{ github.event.inputs.uid }} },
# {
# $set: {
# status: "DEPLOYMENT COMPLETE"
# url: https://${{ github.event.inputs.sub-domain-name }}.dp.appsmith.com
# }
# }
# )'

View File

@ -5,6 +5,9 @@
mkdir ~/.aws; touch ~/.aws/config
echo "[default]
aws_access_key_id = $AWS_ACCESS_KEY_ID
aws_secret_access_key = $AWS_SECRET_ACCESS_KEY" > ~/.aws/credentials
echo "[default]
[profile eksci]