Files
docker-build-action/action.yml
Andreas Rocznik 5eecde82b3
All checks were successful
Actionlint / build (push) Successful in 8s
Update action.yml
2025-05-23 15:18:24 +03:00

93 lines
4.1 KiB
YAML

name: 'Tag Build and Push Docker image'
description: 'Tags verion in current repo, builds docker image and pushes it to registry'
inputs:
registry: # id of input
description: 'docker regisry host name'
required: true
default: 'gitea.phadric.de'
cache-registry: # id of input
description: 'docker regisry host name'
required: true
default: 'imagecache.phadric.de'
image_name:
description: 'name of the dockerimage'
required: true
default: ${{ github.repository }}
token:
description: 'repo auth token'
required: true
runs:
using: "composite"
steps:
- run: echo "::group::Checkout repository"
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: '0'
- run: echo "::endgroup::"
- run: echo "::group::Bump version and push tag"
- name: Bump version and push tag
id: tag
uses: phadric/github-tag-action@a5250a59655e9f4b0350407380a92c73948f2aec # master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # if you don't want to set write permissions use a PAT token
DEFAULT_BUMP: patch
GIT_API_TAGGING: false # dont use API
WITH_V: true
PRERELEASE: true
PRERELEASE_SUFFIX: ${{ github.ref_name }}
- run: echo "::endgroup::"
- run: echo "::group::Extract Docker metadata"
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804 # v5.7.0
with:
flavor: |
latest=${{ github.ref_name == 'main' || github.ref_name == 'master' }}
tags: |
type=ref,event=branch
type=semver,pattern={{version}},value=${{steps.tag.outputs.tag}}
# output 0.1
type=semver,pattern={{major}}.{{minor}},value=${{steps.tag.outputs.tag}}
# disabled if major zero
type=semver,pattern={{major}},value=${{steps.tag.outputs.tag}},enable=${{ !startsWith(steps.tag.outputs.tag, 'v0.') }}
images: ${{ inputs.registry }}/${{ inputs.image_name }}
- run: echo "::endgroup::"
- run: echo "::group::Configure build Cache"
- uses: int128/docker-build-cache-config-action@338206c80bf9eeb2b9694b7b4fc8c247c317e2a8 # v1.38.0
id: cache
with:
image: ${{ inputs.cache-registry }}/${{ inputs.image_name }}-cache
extra-cache-to: image-manifest=true
- run: echo "::endgroup::"
- run: echo "::group::Setup Buildx"
- name: Setup Docker buildx
uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3.10.0
- run: echo "::endgroup::"
- run: echo "::group::Log into Registry ${{ inputs.registry }}"
- name: Log into registry ${{ inputs.registry }}
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
with:
registry: ${{ inputs.registry }}
username: ${{ github.actor }}
password: ${{ inputs.token }}
- run: echo "::endgroup::"
- run: echo "::group::Build and Push docker image"
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@1dc73863535b631f98b2378be8619f83b136f4a0 # v6.17.0
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
platforms: linux/amd64
labels: ${{ steps.meta.outputs.labels }}
cache-from: |
type=registry,ref=${{ inputs.cache-registry }}/${{ inputs.image_name }}-cache:latest
type=registry,ref=${{ inputs.cache-registry }}/${{ inputs.image_name }}-cache:${{ github.ref_name }}
${{ steps.cache.outputs.cache-from }}
cache-to: |
${{ steps.cache.outputs.cache-to }}
type=registry,ref=${{ inputs.cache-registry }}/${{ inputs.image_name }}-cache:latest,mode=max,image-manifest=true
- run: echo "::endgroup::"