Skip to content

Merge pull request #5062 from nulib/combined-dependencies #754

Merge pull request #5062 from nulib/combined-dependencies

Merge pull request #5062 from nulib/combined-dependencies #754

Workflow file for this run

---
name: Build & Deploy Meadow
on:
push:
branches:
- "main"
- "deploy/**"
- "build/**"
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
actions: write
jobs:
get-environment:
if: ${{ !github.event.pull_request && !contains(github.event.head_commit.message, '[no-deploy]') }}
runs-on: ubuntu-latest
outputs:
deploy_env: ${{ steps.set-deploy-env.outputs.result }}
container_tag: ${{ steps.set-container-tag.outputs.result }}
meadow_tenant: ${{ steps.set-meadow-prefix.outputs.result }}
steps:
- name: Set DEPLOY_ENV from Branch Name
id: set-deploy-env
run: |
if [[ $BRANCH == 'refs/heads/main' ]]; then
echo "result=production" >> $GITHUB_OUTPUT
else
echo "result=$(echo $BRANCH | awk -F/ '{print $NF}')" >> $GITHUB_OUTPUT
fi
env:
BRANCH: ${{ github.ref }}
- name: Set container tag from DEPLOY_ENV
id: set-container-tag
run: |
if [[ $DEPLOY_ENV == 'production' || $DEPLOY_ENV == 'staging' ]]; then
echo "result=latest" >> $GITHUB_OUTPUT
else
echo "result=$DEPLOY_ENV" >> $GITHUB_OUTPUT
fi
env:
DEPLOY_ENV: ${{ steps.set-deploy-env.outputs.result }}
- name: Set MEADOW_TENANT from DEPLOY_ENV
id: set-meadow-prefix
run: |
if [[ $DEPLOY_ENV == 'production' || $DEPLOY_ENV == 'staging' ]]; then
echo "result=meadow" >> $GITHUB_OUTPUT
else
echo "result=$DEPLOY_ENV" >> $GITHUB_OUTPUT
fi
env:
DEPLOY_ENV: ${{ steps.set-deploy-env.outputs.result }}
- name: Output Environment Info
run: |
echo "Deploying to environment: ${{ steps.set-deploy-env.outputs.result }}"
echo "Using container tag: ${{ steps.set-container-tag.outputs.result }}"
echo "Using meadow tenant prefix: ${{ steps.set-meadow-prefix.outputs.result }}"
build:
if: ${{ !github.event.pull_request && !contains(github.event.head_commit.message, '[no-deploy]') }}
runs-on: ubuntu-latest
needs: get-environment
env:
DEPLOY_ENV: ${{ needs.get-environment.outputs.deploy_env }}
CONTAINER_TAG: ${{ needs.get-environment.outputs.container_tag }}
MEADOW_TENANT: ${{ needs.get-environment.outputs.meadow_tenant }}
steps:
- uses: actions/checkout@v2
- name: Configure AWS
run: .github/scripts/configure_aws.sh
env:
DEPLOY_ENV: ${{ env.DEPLOY_ENV }}
GITHUB_ENV: ${{ env.GITHUB_ENV }}
SECRETS: ${{ toJSON(secrets) }}
- name: Extract MEADOW_VERSION from mix.exs
run: echo "MEADOW_VERSION=$(grep '@app_version "' mix.exs | sed -n 's/^.*"\(.*\)".*/\1/p')" >> $GITHUB_ENV
working-directory: app
- run: echo "Building Meadow v${MEADOW_VERSION} as nulib/meadow:${CONTAINER_TAG}"
- name: Tag Meadow Release
if: ${{ github.ref == 'refs/heads/main' }}
run: |
git config --global user.email "$(git log --pretty=format:"%ae" | head -1)"
git config --global user.name "$(git log --pretty=format:"%an" | head -1)"
git tag -a v${MEADOW_VERSION} -m "Release ${MEADOW_VERSION}"
- uses: docker/setup-qemu-action@v1
- uses: docker/setup-buildx-action@v1
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Determine container tags
id: determine-container-tags
run: |
{
echo "tags<<EOF"
echo "${REGISTRY_NAME}/meadow:${CONTAINER_TAG}"
if [[ ${CONTAINER_TAG} == "latest" ]]; then
echo "${REGISTRY_NAME}/meadow:${MEADOW_VERSION}"
fi
echo "EOF"
} >> $GITHUB_OUTPUT
env:
REGISTRY_NAME: ${{ steps.login-ecr.outputs.registry }}
- name: Set Meadow Release Name
id: meadow-release
run: echo "name=meadow-$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- uses: docker/build-push-action@v2
with:
context: ./app
push: true
tags: ${{ steps.determine-container-tags.outputs.tags }}
build-args: |
BUILD_IMAGE=hexpm/elixir:1.18.2-erlang-27.3-debian-bookworm-20250224
RUNTIME_IMAGE=node:22-bookworm-slim
HONEYBADGER_API_KEY=${{ secrets.HONEYBADGER_API_KEY }}
HONEYBADGER_API_KEY_FRONTEND=${{ secrets.HONEYBADGER_API_KEY_FRONTEND }}
HONEYBADGER_ENVIRONMENT=${{ env.DEPLOY_ENV }}
HONEYBADGER_REVISION=${{ github.sha }}
RELEASE_NAME=${{ steps.meadow-release.outputs.name }}
MEADOW_TENANT=${{ env.MEADOW_TENANT }}
MEADOW_VERSION=${{ env.MEADOW_VERSION }}
- name: Upload Source Maps to Honeybadger
run: .github/scripts/upload_source_maps.sh
env:
DEPLOY_ENV: ${{ env.DEPLOY_ENV }}
MEADOW_IMAGE: ${{ steps.login-ecr.outputs.registry }}/meadow:${{ env.CONTAINER_TAG }}
MEADOW_VERSION: ${{ env.MEADOW_VERSION }}
HONEYBADGER_API_KEY_FRONTEND: ${{ secrets.HONEYBADGER_API_KEY_FRONTEND }}
HONEYBADGER_REVISION: ${{ github.sha }}
- name: Set GitHub Deploy Key
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.REPO_PRIVATE_KEY }}
- name: Push Release Tag
if: ${{ github.ref == 'refs/heads/main' }}
run: |
git push origin v${MEADOW_VERSION}
- name: Dispatch New Production PR
if: ${{ github.ref == 'refs/heads/main' }}
uses: actions/github-script@v6
with:
script: |
github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'next_version.yml',
ref: 'deploy/staging',
})
build-livebook:
if: ${{ !github.event.pull_request && !contains(github.event.head_commit.message, '[no-deploy]') }}
runs-on: ubuntu-latest
needs: get-environment
env:
DEPLOY_ENV: ${{ needs.get-environment.outputs.deploy_env }}
CONTAINER_TAG: ${{ needs.get-environment.outputs.container_tag }}
MEADOW_TENANT: ${{ needs.get-environment.outputs.meadow_tenant }}
steps:
- uses: actions/checkout@v2
- name: Extract MEADOW_VERSION from mix.exs
run: echo "MEADOW_VERSION=$(grep '@app_version "' mix.exs | sed -n 's/^.*"\(.*\)".*/\1/p')" >> $GITHUB_ENV
working-directory: app
- name: Configure AWS
run: .github/scripts/configure_aws.sh
env:
DEPLOY_ENV: ${{ env.DEPLOY_ENV }}
GITHUB_ENV: ${{ env.GITHUB_ENV }}
SECRETS: ${{ toJSON(secrets) }}
- uses: docker/setup-qemu-action@v1
- uses: docker/setup-buildx-action@v1
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Determine container tags
id: determine-container-tags
run: |
{
echo "tags<<EOF"
echo "${REGISTRY_NAME}/meadow:livebook-${CONTAINER_TAG}"
if [[ ${CONTAINER_TAG} == "latest" ]]; then
echo "${REGISTRY_NAME}/meadow:livebook-${MEADOW_VERSION}"
fi
echo "EOF"
} >> $GITHUB_OUTPUT
env:
REGISTRY_NAME: ${{ steps.login-ecr.outputs.registry }}
- uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile.livebook
push: true
tags: ${{ steps.determine-container-tags.outputs.tags }}
deploy:
needs:
- get-environment
- build
- build-livebook
if: ${{ ! startsWith(github.ref, 'refs/heads/build/') }}
runs-on: ubuntu-latest
env:
DEPLOY_ENV: ${{ needs.get-environment.outputs.deploy_env }}
CONTAINER_TAG: ${{ needs.get-environment.outputs.container_tag }}
MEADOW_TENANT: ${{ needs.get-environment.outputs.meadow_tenant }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 2
- name: Configure AWS
run: .github/scripts/configure_aws.sh
env:
DEPLOY_ENV: ${{ env.DEPLOY_ENV }}
GITHUB_ENV: ${{ env.GITHUB_ENV }}
SECRETS: ${{ toJSON(secrets) }}
- name: Set Service and Task Names
id: set-service-task
run: |
if [[ "$DEPLOY_ENV" == "production" || "$DEPLOY_ENV" == "staging" ]]; then
echo "cluster=meadow" >> $GITHUB_OUTPUT
echo "task=meadow-all" >> $GITHUB_OUTPUT
else
echo "cluster=${MEADOW_TENANT}" >> $GITHUB_OUTPUT
echo "task=${MEADOW_TENANT}-all" >> $GITHUB_OUTPUT
fi
- name: Update ECS Service
run: .github/scripts/update_ecs_service.sh
env:
ECS_CLUSTER: ${{ steps.set-service-task.outputs.cluster }}
ECS_CONTAINER: meadow
ECS_SERVICE: meadow
ECS_TASK: ${{ steps.set-service-task.outputs.task }}
PRIOR_HEAD: ${{ github.event.before }}
- name: Notify Honeybadger
run: .github/scripts/honeybadger_deploy_notification.sh
env:
DEPLOY_ENV: ${{ env.DEPLOY_ENV }}
HONEYBADGER_API_KEY: ${{ secrets.HONEYBADGER_API_KEY }}
HONEYBADGER_REVISION: ${{ github.sha }}