Deploy PROD Worker #79
Workflow file for this run
This file contains 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 PROD Worker | |
# Controls when the action will run. Triggers the workflow on push or pull request | |
# events but only for the master branch | |
on: | |
workflow_dispatch: | |
jobs: | |
test_worker: | |
strategy: | |
# The order is important for ee to be first, otherwise outputs not work correctly | |
matrix: | |
name: [ 'novu/worker-ee', 'novu/worker' ] | |
uses: ./.github/workflows/reusable-worker-e2e.yml | |
with: | |
ee: ${{ contains (matrix.name,'-ee') }} | |
secrets: inherit | |
build_prod_image: | |
if: "!contains(github.event.head_commit.message, 'ci skip')" | |
# The type of runner that the job will run on | |
runs-on: ubuntu-latest | |
needs: test_worker | |
timeout-minutes: 80 | |
environment: Production | |
strategy: | |
# The order is important for ee to be first, otherwise outputs not work correctly | |
matrix: | |
name: [ 'novu/worker-ee', 'novu/worker' ] | |
outputs: | |
docker_image: ${{ steps.build-image.outputs.IMAGE }} | |
permissions: | |
contents: read | |
packages: write | |
deployments: write | |
id-token: write | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
submodules: ${{ contains (matrix.name,'-ee') }} | |
token: ${{ secrets.SUBMODULES_TOKEN }} | |
- uses: ./.github/actions/setup-project | |
with: | |
submodules: ${{ contains (matrix.name,'-ee') }} | |
- name: build worker | |
run: pnpm build:worker --skip-nx-cache | |
- uses: crazy-max/ghaction-setup-docker@v2 | |
with: | |
version: v24.0.6 | |
daemon-config: | | |
{ | |
"features": { | |
"containerd-snapshotter": true | |
} | |
} | |
- name: Setup QEMU | |
uses: docker/setup-qemu-action@v3 | |
with: | |
platforms: linux/amd64,linux/arm64 | |
- name: Set Up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
with: | |
driver-opts: 'image=moby/buildkit:v0.12.4' | |
- name: Set Bull MQ Env variable for EE | |
if: contains(matrix.name, 'ee') | |
shell: bash | |
run: | | |
echo "BULL_MQ_PRO_NPM_TOKEN=${{ secrets.BULL_MQ_PRO_NPM_TOKEN }}" >> $GITHUB_ENV | |
- name: Build, tag, and push image to Amazon ECR | |
id: build-image | |
env: | |
REGISTRY_OWNER: novuhq | |
DOCKER_NAME: ${{matrix.name}} | |
IMAGE_TAG: ${{ github.sha }} | |
GH_ACTOR: ${{ github.actor }} | |
GH_PASSWORD: ${{ secrets.GH_PACKAGES }} | |
run: | | |
echo $GH_PASSWORD | docker login ghcr.io -u $GH_ACTOR --password-stdin | |
cd apps/worker && pnpm --silent --workspace-root pnpm-context -- apps/worker/Dockerfile | BULL_MQ_PRO_NPM_TOKEN=${BULL_MQ_PRO_NPM_TOKEN} docker buildx build --secret id=BULL_MQ_PRO_NPM_TOKEN --build-arg PACKAGE_PATH=apps/worker - -t novu-worker --load --platform=linux/amd64,linux/arm64 --provenance=false | |
docker tag novu-worker ghcr.io/$REGISTRY_OWNER/$DOCKER_NAME:latest | |
docker tag novu-worker ghcr.io/$REGISTRY_OWNER/$DOCKER_NAME:prod | |
docker tag novu-worker ghcr.io/$REGISTRY_OWNER/$DOCKER_NAME:$IMAGE_TAG | |
docker run --network=host --name worker -dit --env NODE_ENV=test ghcr.io/$REGISTRY_OWNER/$DOCKER_NAME:$IMAGE_TAG | |
docker run --network=host appropriate/curl --retry 10 --retry-delay 5 --retry-connrefused http://127.0.0.1:1342/v1/health-check | grep 'ok' | |
docker push ghcr.io/$REGISTRY_OWNER/$DOCKER_NAME:prod | |
docker push ghcr.io/$REGISTRY_OWNER/$DOCKER_NAME:latest | |
docker push ghcr.io/$REGISTRY_OWNER/$DOCKER_NAME:$IMAGE_TAG | |
echo "IMAGE=ghcr.io/$REGISTRY_OWNER/$DOCKER_NAME:$IMAGE_TAG" >> $GITHUB_OUTPUT | |
# Temporary for the migration phase | |
deploy_general_worker_eu: | |
needs: build_prod_image | |
uses: ./.github/workflows/reusable-app-service-deploy.yml | |
secrets: inherit | |
with: | |
environment: Production | |
service_name: worker | |
terraform_workspace: novu-prod-eu | |
# This is a workaround to an issue with matrix outputs | |
docker_image: ghcr.io/novuhq/novu/worker-ee:${{ github.sha }} | |
deploy_prod_workers_eu: | |
needs: deploy_general_worker_eu | |
uses: ./.github/workflows/reusable-workers-service-deploy.yml | |
secrets: inherit | |
with: | |
environment: Production | |
terraform_workspace: novu-prod-eu | |
# This is a workaround to an issue with matrix outputs | |
docker_image: ghcr.io/novuhq/novu/worker-ee:${{ github.sha }} | |
# Temporary for the migration phase | |
deploy_general_worker_us: | |
needs: | |
- deploy_prod_workers_eu | |
- build_prod_image | |
uses: ./.github/workflows/reusable-app-service-deploy.yml | |
secrets: inherit | |
with: | |
environment: Production | |
service_name: worker | |
terraform_workspace: novu-prod | |
# This is a workaround to an issue with matrix outputs | |
docker_image: ghcr.io/novuhq/novu/worker-ee:${{ github.sha }} | |
deploy_prod_workers_us: | |
needs: | |
- deploy_general_worker_us | |
- build_prod_image | |
uses: ./.github/workflows/reusable-workers-service-deploy.yml | |
secrets: inherit | |
with: | |
environment: Production | |
terraform_workspace: novu-prod | |
# This is a workaround to an issue with matrix outputs | |
docker_image: ghcr.io/novuhq/novu/worker-ee:${{ github.sha }} | |
deploy_sentry_release: true | |
sentry_project: worker | |
newrelic: | |
runs-on: ubuntu-latest | |
name: New Relic Deploy | |
needs: deploy_prod_workers_us | |
environment: Production | |
steps: | |
# This step builds a var with the release tag value to use later | |
- name: Set Release Version from Tag | |
run: echo "RELEASE_VERSION=${{ github.ref_name }}" >> $GITHUB_ENV | |
# This step creates a new Change Tracking Marker | |
- name: New Relic Application Deployment Marker | |
uses: newrelic/deployment-marker-action@v2.3.0 | |
with: | |
region: EU | |
apiKey: ${{ secrets.NEW_RELIC_API_KEY }} | |
guid: "MzgxMjQwOHxBUE18QVBQTElDQVRJT058NDk3NzA2ODk2" | |
version: "${{ env.RELEASE_VERSION }}" | |
user: "${{ github.actor }}" |