Files
workflows/.gitea/workflows/simple-container.yaml
2026-02-11 15:38:21 -05:00

103 lines
3.2 KiB
YAML

name: Build and Publisch a Simple Container
on:
workflow_call:
inputs:
dockerfile:
description: "Dockerfile to use for the build"
required: true
type: string
default: Dockerfile
git_user:
description: "Git user to use for checkout and the container registry"
required: true
type: string
default: campenbe
package-name:
description: "Name of the package to build"
required: true
type: string
package-label:
description: "Label to use for the package"
required: true
type: string
builder-image:
description: "Container image to use for the build"
required: false
type: string
default: gitea.ampenberger.com/campenbe/img-builder:3.21-1.24
version:
description: "Version string passed to the Docker build as build-arg"
required: false
type: string
default: development
extra-build-args:
description: "Extra build args to pass to the Docker build, separate by space"
required: false
type: string
default: ""
subdirectory:
description: "Subdirectory to use for the build context"
required: false
type: string
default: ""
secrets:
PASSWORD:
required: true
GIT_TOKEN:
required: true
env:
PACKAGE_NAME: ${{ inputs.package-name }}
LABEL: ${{ inputs.package-label }}
ARTIFACT_UPLOAD: ${{ env.ACT_EXEC == 'true' && 'actions/upload-artifact@v2' || 'actions/upload-artifact@v3' }}
ARTIFACT_DOWNLOAD: ${{ env.ACT_EXEC == 'true' && 'actions/download-artifact@v2' || 'actions/download-artifact@v3' }}
EXTRA_ARGS: ${{ inputs.extra-build-args }}
jobs:
container:
runs-on: ubuntu-latest
container:
image: ${{inputs.builder-image}}
credentials:
username: ${{inputs.git_user}}
password: ${{secrets.PASSWORD}}
steps:
- name: Install tools
run : |
export LABEL=${{ inputs.package-label }}
gitea_addr.sh
env | sort
- name: Fix git access
run: |
git config --global url."https://git:${{secrets.GIT_TOKEN}}@gitea.ampenberger.com/${{inputs.git_user}}/.insteadOf" git://git.ampenberger.com/
- uses: actions/checkout@v4
with:
submodules: false
- name: Build container
run: |
[ -n "${{inputs.subdirectory}}" ] && cd ${{inputs.subdirectory}}
# split the extra-args and construct build-arg parameters
set -- ${EXTRA_ARGS}
args=""
for p in "$@"; do
args="$args --build-arg ${p}"
done
buildah build -f ${{inputs.dockerfile}} --build-arg GIT_TOKEN=${{secrets.GIT_TOKEN}} --build-arg VERSION=${{inputs.version}} ${args} -t gitea.ampenberger.com/${{inputs.git_user}}/${PACKAGE_NAME}:${LABEL}
echo "Built ${PACKAGE_NAME}:${LABEL}"
buildah images
- name: Publish the container to the registry
run: |
buildah login -u ${{inputs.git_user}} -p ${{secrets.GIT_TOKEN}} gitea.ampenberger.com
buildah push gitea.ampenberger.com/${{inputs.git_user}}/${PACKAGE_NAME}:${LABEL}