068142690c
/ ssh-client-container-build-push (push) Successful in 12s
modified: .gitea/workflows/ssh-client-build-deploy.yaml
86 lines
2.3 KiB
YAML
86 lines
2.3 KiB
YAML
name: BuildKit Build and push - dev
|
|
description: "Build and push images using remote Buildkit"
|
|
inputs:
|
|
registry_addr:
|
|
description: registry address
|
|
required: true
|
|
registry_username:
|
|
description: "registry username"
|
|
required: true
|
|
registry_password:
|
|
description: "registry password"
|
|
required: true
|
|
buildkit_addr:
|
|
description: "buildkit address"
|
|
required: true
|
|
tags:
|
|
description: "image tags / buildctl image name"
|
|
required: true
|
|
context:
|
|
description: "buildctl build context"
|
|
required: false
|
|
default: "."
|
|
dockerfile:
|
|
description: "buildctl build dockerfile/folder"
|
|
required: true
|
|
default: "."
|
|
filename:
|
|
description: "Docker file name (Default: Dockerfile)"
|
|
required: true
|
|
default: "Dockerfile"
|
|
build_args:
|
|
description: "Build arguments (multiline KEY=VALUE)"
|
|
required: false
|
|
default: ""
|
|
runs:
|
|
using: "composite"
|
|
steps:
|
|
- name: run buildctl build and push
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
|
|
USER='${{ inputs.registry_username }}'
|
|
PASS='${{ inputs.registry_password }}'
|
|
|
|
AUTH_INLINE=$(printf '%s:%s' "$USER" "$PASS" | base64 -w0)
|
|
echo "AUTH_INLINE generated successfully"
|
|
|
|
# Build JSON safely
|
|
read -r -d '' AUTH_JSON <<'EOF'
|
|
{
|
|
"auths": {
|
|
"__REGISTRY__": {
|
|
"auth": "__AUTH__"
|
|
}
|
|
}
|
|
}
|
|
EOF
|
|
|
|
AUTH_JSON="${AUTH_JSON/__REGISTRY__/${{ inputs.registry_addr }}}"
|
|
AUTH_JSON="${AUTH_JSON/__AUTH__/$AUTH_INLINE}"
|
|
|
|
# FIX: avoid unbound variable
|
|
BUILD_ARGS="${{ inputs.build_args:-}}"
|
|
|
|
BUILD_ARG_FLAGS=""
|
|
while IFS= read -r line; do
|
|
[[ -z "$line" ]] && continue
|
|
BUILD_ARG_FLAGS="$BUILD_ARG_FLAGS --opt build-arg:${line}"
|
|
done <<< "$BUILD_ARGS"
|
|
|
|
echo "Using build args: $BUILD_ARG_FLAGS"
|
|
|
|
echo "build and push image ${{ inputs.registry_username }}"
|
|
|
|
buildctl \
|
|
--addr ${{ inputs.buildkit_addr }} \
|
|
build \
|
|
--frontend=dockerfile.v0 \
|
|
--local context=${{ inputs.context }} \
|
|
--local dockerfile=${{ inputs.dockerfile }} \
|
|
--opt filename=${{ inputs.filename }} \
|
|
$BUILD_ARG_FLAGS \
|
|
--output type=image,name=${{ inputs.tags }},push=true,registry.config="$AUTH_JSON"
|
|
|