Skip to content

Build Docker image

Build Docker image #4

# build docker image and push to docker hub
# note: this won't work because the cross-platform build takes around 10h,
# but github limits us to 6h.
# so need to build it locally and push to docker hub.
# see Dockerfile for instructions.
# needs github secrets set for -
# DOCKERHUB_USERNAME - ie mtconnect
# DOCKERHUB_TOKEN - token for that account
# Set VERSION below before building.
# See CMakeLists.txt for the current version.
# Note: this will tag the image with that version, as well as 'latest'.
name: Build Docker image
env:
PLATFORMS: linux/amd64,linux/arm64
# when to run workflow
on:
# # run on push or pull request events for the master branch
push:
paths-ignore: ["**/*.md", "LICENSE.txt", ".gitignore"]
branches: [ "main", "main-dev" ]
tags:
- "v*.*.*"
# allows you to run this workflow manually from the actions tab
workflow_dispatch:
# a workflow run has one or more jobs that can run sequentially or in parallel
jobs:
# this workflow contains a single job called "build"
build:
# the type of runner that the job will run on
runs-on: ubuntu-latest
strategy:
matrix:
include:
- dockerfile: docker/alpine/Dockerfile
name: agent
# - dockerfile: demo/Dockerfile.alpine
# name: demo
#- dockerfile: docker/replicator/Dockerfile
# name: replicator
# steps represent a sequence of tasks that will be executed as part of the job
steps:
# checks-out your repository under $GITHUB_WORKSPACE
# see https://github.com/actions/checkout
- name: Checkout Agent
uses: actions/checkout@v3
# the QEMU emulator lets us build for arm processors also
# see https://github.com/docker/setup-qemu-action
- name: Set up QEMU emulator
uses: docker/setup-qemu-action@v3
# see https://github.com/docker/setup-buildx-action
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# see https://github.com/docker/build-push-action
- name: Build image and push to DockerHub
uses: docker/build-push-action@v5
with:
context: .
file: ${{ matrix.dockerfile }}
platforms: ${{ env.PLATFORMS }}
# docker hub user/repo:tag
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/${{ matrix.name }}:latest
${{ secrets.DOCKERHUB_USERNAME }}/${{ matrix.name }}:${{ github.ref_name }}
# push to docker hub
push: true