Files
gitea-workflows/.gitea/workflows/build-container.yaml
T

91 lines
3.2 KiB
YAML

name: Build Container
on:
workflow_call:
inputs:
prerelease:
type: boolean
description: Whether to create a prerelease tag
default: false
dry-run:
type: boolean
description: Whether to dry run the build and push
default: false
registry:
type: string
description: The registry to use
required: true
registry-user:
type: string
description: The username to use for the registry
required: true
registry-password:
type: string
description: The password to use for the registry
required: true
repo-name:
type: string
description: The name of the repository
required: true
tag:
type: string
description: The tag to use for the repository
required: true
context:
type: string
description: The context to use for the build
default: .
dockerfile:
type: string
description: The Dockerfile to use for the build
default: Dockerfile
jobs:
build_and_push:
name: Build and push
strategy:
matrix:
# Prepared for future multi-arch support in the future, as soon as ACT has support for dynamic matrixes.
arch: [amd64]
runs-on:
- ubuntu-latest
- linux_${{ matrix.arch }}
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- uses: docker/setup-buildx-action@bb05f3f5519dd87d3ba754cc423b652a5edd6d2c # v4.2.0
- uses: docker/login-action@af1e73f918a031802d376d3c8bbc3fe56130a9b0 # v4.4.0
with:
registry: ${{ inputs.registry }}
username: ${{ inputs.registry-user }}
password: ${{ inputs.registry-password }}
- uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7.3.0
with:
context: ${{ inputs.context }}
file: ${{ inputs.dockerfile }}
platforms: linux/${{ matrix.arch }}
push: ${{ inputs.dry-run == false || inputs.dry-run == 'false' }}
provenance: false
tags: |
${{ inputs.registry }}/${{ inputs.repo-name }}:${{ inputs.tag }}-${{ matrix.arch }}
cache-from: type=registry,ref=${{ inputs.registry }}/${{ inputs.repo-name }}:cache-${{ matrix.arch }}
cache-to: type=registry,ref=${{ inputs.registry }}/${{ inputs.repo-name }}:cache-${{ matrix.arch }},mode=max
create_manifest:
name: Create manifest
if: ${{ inputs.dry-run == false || inputs.dry-run == 'false' }}
needs:
- build_and_push
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- uses: docker/login-action@af1e73f918a031802d376d3c8bbc3fe56130a9b0 # v4.4.0
with:
registry: ${{ inputs.registry }}
username: ${{ inputs.registry-user }}
password: ${{ inputs.registry-password }}
- run: |
docker manifest create ${{ inputs.registry }}/${{ inputs.repo-name }}:${{ inputs.tag }} \
${{ inputs.registry }}/${{ inputs.repo-name }}:${{ inputs.tag }}-amd64
docker manifest push ${{ inputs.registry }}/${{ inputs.repo-name }}:${{ inputs.tag }}