Skip to content

Deploy

Deploy #89

Workflow file for this run

name: Deploy
on:
workflow_run:
workflows:
- Test
branches:
- main
- develop
types:
- completed
workflow_dispatch:
push:
branches:
- poc/docker-multi-stages
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
env:
DOCKER_REGISTRY: ${{ secrets.DOCKER_REGISTRY }}
DOCKER_USERNAME: ${{ github.repository_owner }}
DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
DOCKER_IMAGE: ${{ github.repository }}
jobs:
deploy:
name: Deploy application to Heroku
runs-on: ubuntu-latest
if: ${{ github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_branch || github.ref }}
- name: Set BRANCH_TAG
uses: nimblehq/branch-tag-action@v1
with:
ref: ${{ github.event.workflow_run.head_branch || github.ref }}
- name: Set environment variables
run: |
echo "DOCKER_IMAGE_TAG=$DOCKER_REGISTRY/$DOCKER_IMAGE:$BRANCH_TAG" >> $GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-multi-buildx
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
registry: ${{ env.DOCKER_REGISTRY }}
username: ${{ env.DOCKER_USERNAME }}
password: ${{ env.DOCKER_TOKEN }}
- name: Prepare Docker image
run: |
bin/docker-prepare
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ env.DOCKER_IMAGE_TAG }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new
- name: Move cache to correct location
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
- name: Set HEROKU_APP
run: |
if [[ $BRANCH_TAG = "latest" ]]
then
echo "HEROKU_APP=nimble-survey-web" >> $GITHUB_ENV
else
echo "HEROKU_APP=nimble-survey-web-staging" >> $GITHUB_ENV
fi
- name: Log in to Heroku container
run: heroku container:login
- name: Publish application
run: |
heroku container:push --arg DOCKER_REGISTRY=$DOCKER_REGISTRY,DOCKER_IMAGE=$DOCKER_IMAGE,BRANCH_TAG=$BRANCH_TAG --recursive
heroku container:release web worker