Deploy to Novu Cloud #34
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy to Novu Cloud | |
on: | |
workflow_dispatch: | |
inputs: | |
environment: | |
description: 'Environment to deploy to' | |
required: true | |
type: choice | |
default: Development | |
options: | |
- Development | |
- production-us | |
- production-eu | |
- production-both | |
deploy_api: | |
description: 'Deploy API' | |
required: true | |
type: boolean | |
default: true | |
deploy_worker: | |
description: 'Deploy Worker' | |
required: true | |
type: boolean | |
default: false | |
deploy_ws: | |
description: 'Deploy WS' | |
required: true | |
type: boolean | |
default: false | |
deploy_webhook: | |
description: 'Deploy Webhook' | |
required: true | |
type: boolean | |
default: false | |
jobs: | |
prepare-matrix: | |
runs-on: ubuntu-latest | |
outputs: | |
env_matrix: ${{ steps.set-matrix.outputs.env_matrix }} | |
service_matrix: ${{ steps.set-matrix.outputs.service_matrix }} | |
steps: | |
- name: Generate Environment & Service Matrices | |
id: set-matrix | |
run: | | |
envs=() | |
services=() | |
# Collect selected environments | |
if [ "${{ github.event.inputs.environment }}" == "Development" ]; then | |
envs+=("\"Development\"") | |
fi | |
if [ "${{ github.event.inputs.environment }}" == "production-us" ]; then | |
envs+=("\"production-us\"") | |
fi | |
if [ "${{ github.event.inputs.environment }}" == "production-eu" ]; then | |
envs+=("\"production-eu\"") | |
fi | |
if [ "${{ github.event.inputs.environment }}" == "production-both" ]; then | |
envs+=("\"production-us\"") | |
envs+=("\"production-eu\"") | |
fi | |
# Collect selected services | |
if [ "${{ github.event.inputs.deploy_api }}" == "true" ]; then | |
services+=("\"api\"") | |
fi | |
if [ "${{ github.event.inputs.deploy_worker }}" == "true" ]; then | |
services+=("\"worker\"") | |
fi | |
if [ "${{ github.event.inputs.deploy_ws }}" == "true" ]; then | |
services+=("\"ws\"") | |
fi | |
if [ "${{ github.event.inputs.deploy_webhook }}" == "true" ]; then | |
services+=("\"webhook\"") | |
fi | |
env_matrix="{\"environment\": [$( | |
IFS=','; echo "${envs[*]}" | |
)]}" | |
service_matrix="{\"service\": [$( | |
IFS=','; echo "${services[*]}" | |
)]}" | |
echo "env_matrix=$env_matrix" >> $GITHUB_OUTPUT | |
echo "service_matrix=$service_matrix" >> $GITHUB_OUTPUT | |
build: | |
needs: prepare-matrix | |
timeout-minutes: 60 | |
runs-on: ubuntu-latest | |
environment: ${{ fromJson(needs.prepare-matrix.outputs.env_matrix).environment[0] }} | |
outputs: | |
docker_image: ${{ steps.build-image.outputs.IMAGE }} | |
strategy: | |
matrix: | |
service: ${{ fromJson(needs.prepare-matrix.outputs.service_matrix).service }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
submodules: true | |
fetch-depth: 0 | |
token: ${{ secrets.SUBMODULES_TOKEN }} | |
- name: Install pnpm | |
uses: pnpm/action-setup@v4 | |
with: | |
version: 9.11.0 | |
run_install: false | |
- name: Setup Node Version | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20.8.1' | |
cache: 'pnpm' | |
- name: Install Dependencies | |
shell: bash | |
run: pnpm install --frozen-lockfile | |
- name: Set Up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
with: | |
driver-opts: 'image=moby/buildkit:v0.13.1' | |
- name: Prepare Variables | |
run: echo "BULL_MQ_PRO_NPM_TOKEN=${{ secrets.BULL_MQ_PRO_NPM_TOKEN }}" >> $GITHUB_ENV | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID}} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ secrets.AWS_REGION }} | |
- name: Login to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v2 | |
- name: Build, tag, and push image to Amazon ECR | |
id: build-image | |
env: | |
REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
REPOSITORY: ${{ secrets.ECR_REPO_PREFIX }}/${{ matrix.service }} | |
SERVICE: ${{ matrix.service }} | |
IMAGE_TAG: ${{ github.sha }} | |
DOCKER_BUILD_ARGUMENTS: > | |
--platform=linux/amd64 | |
--output=type=image,name=$REGISTRY/$REPOSITORY,push-by-digest=true,name-canonical=true | |
run: | | |
cp scripts/dotenvcreate.mjs apps/$SERVICE/src/dotenvcreate.mjs | |
cd apps/$SERVICE && pnpm run docker:build | |
docker tag novu-$SERVICE $REGISTRY/$REPOSITORY:latest | |
docker tag novu-$SERVICE $REGISTRY/$REPOSITORY:$IMAGE_TAG | |
docker push $REGISTRY/$REPOSITORY:latest | |
docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG | |
echo "IMAGE=$REGISTRY/$REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT | |
deploy: | |
needs: [build, prepare-matrix] | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
env: ${{ fromJson(needs.prepare-matrix.outputs.env_matrix).environment }} | |
service: ${{ fromJson(needs.prepare-matrix.outputs.service_matrix).service }} | |
steps: | |
- name: Print Important Info | |
run: | | |
echo "Deploying ${{ matrix.service }} to ${{ matrix.env }}" | |
echo "Docker Image: ${{ needs.build.outputs.docker_image }}" |