Files
docker-build-action/action.yml
Andreas Rocznik 7053f2f43b
All checks were successful
Actionlint / build (push) Successful in 6s
Update action.yml
2025-01-20 11:00:15 +02:00

83 lines
3.9 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'
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::\n::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::\n::group::Extract Docker metadata"
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96 # v5.6.1
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::\n::group::Configure build Cache"
- uses: int128/docker-build-cache-config-action@622932dfa73db7d3a65e40d5fcc094f2101e659a # v1.37.0
id: cache
with:
image: ${{ inputs.registry }}/${{ inputs.image_name }}-cache
extra-cache-to: image-manifest=true
- run: echo "::endgroup::\n::group::Setup Buildx"
- name: Setup Docker buildx
uses: docker/setup-buildx-action@6524bf65af31da8d45b59e8c27de4bd072b392f5 # v3.8.0
- run: echo "::endgroup::\n::group::Log into Registry ${{ inputs.registry }}"
- name: Log into registry ${{ inputs.registry }}
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
registry: ${{ inputs.registry }}
username: ${{ github.actor }}
password: ${{ inputs.token }}
- run: echo "::endgroup::\n::group::Build and Push docker image"
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@67a2d409c0a876cbe6b11854e3e25193efe4e62d # v6.12.0
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
platforms: linux/amd64
labels: ${{ steps.meta.outputs.labels }}
cache-from: |
type=registry,ref=${{ inputs.registry }}/${{ inputs.image_name }}-cache:latest
type=registry,ref=${{ inputs.registry }}/${{ inputs.image_name }}-cache:${{ github.ref_name }}
${{ steps.cache.outputs.cache-from }}
cache-to: |
${{ steps.cache.outputs.cache-to }}
type=registry,ref=${{ inputs.registry }}/${{ inputs.image_name }}-cache:latest,mode=max,image-manifest=true
- run: echo "::endgroup::"