Skip to content

Build and publish Docker image #3

Build and publish Docker image

Build and publish Docker image #3

# Workflow is triggered after a new Optimizt version is successfully published to NPM
name: Build and publish Docker image
on:
workflow_run:
workflows: [Publish Package to npmjs]
types: [completed]
branches: [master]
defaults:
run:
shell: bash
jobs:
docker:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Check-out repo
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Define variables
run: |
echo "OPTIMIZT_VERSION=$(grep -m1 version ./package.json | sed 's/[", ]//g' | cut -d ":" -f 2)" >> $GITHUB_ENV
echo "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_ENV
- name: Build and push
uses: docker/build-push-action@v4
with:
push: true
tags: funbox/optimizt:latest,funbox/optimizt:${{ env.OPTIMIZT_VERSION }}
build-args: |
OPTIMIZT_VERSION=${{ env.OPTIMIZT_VERSION }}
BUILD_DATE=${{ env.BUILD_DATE }}
fail:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
steps:
- run: echo "Publish workflow failed"