Files
ci-templates/.gitea/workflows/docker_build.yaml
2025-11-11 02:29:49 +03:00

79 lines
2.3 KiB
YAML

name: Build docker image
on:
workflow_call:
inputs:
ci_image:
required: true
type: string
description: image to use inside the workflow jobs
default: git.romalex.cc/public/ci-image:v1
registry:
required: true
type: string
description: registry to push images to
default: git.romalex.cc
dockerfile_path:
required: true
type: string
description: path to Dockerfile
default: Dockerfile
registry_user:
required: true
type: string
description: username to access gitea registry
default: ${{ github.actor }}
secrets:
registry_access_token:
required: true
description: Token to access the gitea registry
outputs:
version:
description: Published image version
value: ${{ jobs.set_version.outputs.version }}
jobs:
set_version:
name: Set image version
runs-on: romalex-public
container:
image: ${{ inputs.ci_image }}
outputs:
version: ${{ steps.calculate.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Calculate image version
id: calculate
run: |
if [ -s version.txt ]; then
echo "version=$(cat version.txt)" >> "${GITHUB_OUTPUT}"
elif [ "${{ github.ref_type }}" = 'tag' ]; then
echo 'version=${{ github.ref_name }}' >> "${GITHUB_OUTPUT}"
else
echo "version=$(echo '${{ github.sha }}' | cut -c -6)" >> "${GITHUB_OUTPUT}"
fi
build_image:
name: Build docker image
runs-on: romalex-public
container:
image: ${{ inputs.ci_image }}
needs: set_version
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Login to registry
uses: docker/login-action@v3
with:
registry: ${{ inputs.registry }}
username: ${{ inputs.registry_user }}
password: ${{ secrets.registry_access_token }}
- name: Build and push
uses: docker/build-push-action@v6
with:
push: true
file: ${{ inputs.dockerfile_path }}
tags: |
${{ inputs.registry }}/${{ github.repository }}:${{ needs.set_version.outputs.version }}