.github/actions/build-container/action.yml
name: Build Spot container
inputs:
image_name:
required: true
description: "Name for Docker image (ex. 'lafayette/rails')"
tag:
required: true
description: "Version identifier for release (ex. '2023.1')"
context:
required: false
default: '.'
description: "Context for Docker image"
registry:
required: false
default: "docker.io"
description: "Registry tag (default is 'docker.io')"
target:
required: false
description: "Docker target to build"
runs:
using: composite
steps:
-
id: build_date
shell: bash
name: Generate build date variable for Image
run: |
build_date="$(date +'%Y%m%d')"
echo "date=$build_date" >> "$GITHUB_OUTPUT"
-
id: clean_tag
shell: bash
name: Clean Docker tag
env:
CURRENT_TAG: ${{ inputs.tag }}
run: |
clean_tag=$(echo $CURRENT_TAG | sed 's/\//__/')
echo "tag=$clean_tag" >> "$GITHUB_OUTPUT"
-
name: Build and push ${{ inputs.image_name }} container
uses: docker/build-push-action@v5
with:
build-args: |
build_date="${{ steps.build_date.outputs.date }}"
cache-from: type=gha
cache-to: type=gha,mode=max
context: ${{ inputs.context }}
provenance: false
push: true
tags: ${{ inputs.registry }}/${{ inputs.image_name }}:${{ steps.clean_tag.outputs.tag }}
target: ${{ inputs.target }}