Skip to content

build-docker-image

build-docker-image #5

name: build-docker-image
on:
workflow_dispatch:
inputs:
tag:
description: 'Tag for Docker image (excluding the "v" prefix e.g. 3.5.3)'
required: true
ref:
description: 'Branch, tag, or commit SHA to build from'
required: true
default: main
jobs:
build-and-push:
runs-on: ubuntu-latest
timeout-minutes: 300
env:
DOCKERFILE_PATH: share/docker/openfast_ubuntu/Dockerfile
DOCKERFILE_PERMALINK: https://raw.githubusercontent.com/octue/openfast/update-dockerfiles/share/docker/openfast_ubuntu/Dockerfile
DOCKER_HUB_REPOSITORY: octue/openfast
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.ref }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Get Dockerfile for versions < 3.5.3
run: |
if [ ! -f ${{ env.DOCKERFILE_PATH }} ]; \
then wget -O ${{ env.DOCKERFILE_PATH }} ${{ env.DOCKERFILE_PERMALINK }}; \
fi
- name: Build and push to registry
uses: docker/build-push-action@v5
with:
context: .
file: ${{ env.DOCKERFILE_PATH }}
platforms: linux/amd64
tags: ${{ env.DOCKER_HUB_REPOSITORY }}:${{ github.event.inputs.tag }}
push: true
cache-from: type=gha
cache-to: type=gha,mode=max