fix: simplify bake file to avoid locals/function blocks (buildx compat)
Some checks failed
Release / Test backend (push) Successful in 59s
Release / Check ui (push) Successful in 1m56s
Release / Docker (push) Failing after 2m21s
Release / Deploy to prod (push) Has been skipped
Release / Gitea Release (push) Has been skipped

The Gitea runner's docker buildx doesn't support HCL locals{} or function{}
blocks (added in buildx 0.12+). Replace with plain variables: VERSION and
MAJOR_MINOR are pre-computed in a CI step and passed as env vars to bake.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Admin
2026-04-15 19:43:54 +05:00
parent 8922111471
commit 6d0dac256d
2 changed files with 47 additions and 50 deletions

View File

@@ -166,6 +166,14 @@ jobs:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Compute version tags
id: ver
run: |
V="${{ gitea.ref_name }}"
VER="${V#v}"
echo "version=$VER" >> "$GITHUB_OUTPUT"
echo "major_minor=$(echo "$VER" | cut -d. -f1-2)" >> "$GITHUB_OUTPUT"
- name: Download ui build artifacts
uses: actions/download-artifact@v3
with:

View File

@@ -1,56 +1,25 @@
# docker-bake.hcl — defines all five production images.
#
# Used by CI (docker/bake-action) to build and push all images in one call,
# with shared BuildKit cache and maximum parallelism:
# - backend, runner, pocketbase share the Go builder stage (built once)
# - caddy and ui build independently in parallel alongside the Go targets
# Uses only plain variables for broad buildx compatibility (no locals/functions).
# CI pre-computes VERSION and MAJOR_MINOR from the git tag and passes them as
# env vars. Locally, everything gets a :dev tag.
#
# Local build (push=false by default):
# Local build (no push):
# docker buildx bake
#
# CI passes GIT_TAG (e.g. "v4.1.3") and the bake file computes all three tag
# variants (full semver, major.minor, latest) — no docker/metadata-action needed.
# ── Variables injected by CI ──────────────────────────────────────────────────
# CI passes: DOCKER_USER, VERSION, MAJOR_MINOR, COMMIT, BUILD_TIME
variable "DOCKER_USER" { default = "kalekber" }
# Full git tag, e.g. "v4.1.3". CI passes this via --set or env.
# Locally defaults to "dev" so images get a :dev tag.
variable "GIT_TAG" { default = "dev" }
variable "VERSION" { default = "dev" } # e.g. "4.1.6" (no leading v)
variable "MAJOR_MINOR" { default = "dev" } # e.g. "4.1"
variable "COMMIT" { default = "unknown" }
variable "BUILD_TIME" { default = "" }
# ── Tag helpers ───────────────────────────────────────────────────────────────
locals {
# Strip leading "v": "v4.1.3" → "4.1.3"
version = trimprefix(GIT_TAG, "v")
# major.minor only: "4.1.3" → "4.1"
major_minor = join(".", slice(split(".", local.version), 0, 2))
# true when building a real release tag (not local "dev" build)
is_release = GIT_TAG != "dev"
}
# Return the three standard tags for a given image repo.
# Always includes :latest and the full version; skips major.minor for dev builds.
function "img_tags" {
params = [repo]
result = local.is_release ? [
"${repo}:${local.version}",
"${repo}:${local.major_minor}",
"${repo}:latest",
] : ["${repo}:dev"]
}
# ── Shared defaults ───────────────────────────────────────────────────────────
target "_defaults" {
pull = true
# CI overrides this to push=true via --set *.output=type=image,push=true
# CI overrides to push=true via --set *.output=type=image,push=true
output = ["type=image,push=false"]
cache-to = ["type=inline"]
}
@@ -61,10 +30,14 @@ target "backend" {
inherits = ["_defaults"]
context = "backend"
target = "backend"
tags = img_tags("${DOCKER_USER}/libnovel-backend")
tags = [
"${DOCKER_USER}/libnovel-backend:${VERSION}",
"${DOCKER_USER}/libnovel-backend:${MAJOR_MINOR}",
"${DOCKER_USER}/libnovel-backend:latest",
]
cache-from = ["type=registry,ref=${DOCKER_USER}/libnovel-backend:latest"]
args = {
VERSION = local.version
VERSION = VERSION
COMMIT = COMMIT
}
}
@@ -73,10 +46,14 @@ target "runner" {
inherits = ["_defaults"]
context = "backend"
target = "runner"
tags = img_tags("${DOCKER_USER}/libnovel-runner")
tags = [
"${DOCKER_USER}/libnovel-runner:${VERSION}",
"${DOCKER_USER}/libnovel-runner:${MAJOR_MINOR}",
"${DOCKER_USER}/libnovel-runner:latest",
]
cache-from = ["type=registry,ref=${DOCKER_USER}/libnovel-runner:latest"]
args = {
VERSION = local.version
VERSION = VERSION
COMMIT = COMMIT
}
}
@@ -85,7 +62,11 @@ target "pocketbase" {
inherits = ["_defaults"]
context = "backend"
target = "pocketbase"
tags = img_tags("${DOCKER_USER}/libnovel-pocketbase")
tags = [
"${DOCKER_USER}/libnovel-pocketbase:${VERSION}",
"${DOCKER_USER}/libnovel-pocketbase:${MAJOR_MINOR}",
"${DOCKER_USER}/libnovel-pocketbase:latest",
]
cache-from = ["type=registry,ref=${DOCKER_USER}/libnovel-pocketbase:latest"]
}
@@ -94,10 +75,14 @@ target "pocketbase" {
target "ui" {
inherits = ["_defaults"]
context = "ui"
tags = img_tags("${DOCKER_USER}/libnovel-ui")
tags = [
"${DOCKER_USER}/libnovel-ui:${VERSION}",
"${DOCKER_USER}/libnovel-ui:${MAJOR_MINOR}",
"${DOCKER_USER}/libnovel-ui:latest",
]
cache-from = ["type=registry,ref=${DOCKER_USER}/libnovel-ui:latest"]
args = {
BUILD_VERSION = local.version
BUILD_VERSION = VERSION
BUILD_COMMIT = COMMIT
BUILD_TIME = BUILD_TIME
PREBUILT = "1"
@@ -109,7 +94,11 @@ target "ui" {
target "caddy" {
inherits = ["_defaults"]
context = "caddy"
tags = img_tags("${DOCKER_USER}/libnovel-caddy")
tags = [
"${DOCKER_USER}/libnovel-caddy:${VERSION}",
"${DOCKER_USER}/libnovel-caddy:${MAJOR_MINOR}",
"${DOCKER_USER}/libnovel-caddy:latest",
]
cache-from = ["type=registry,ref=${DOCKER_USER}/libnovel-caddy:latest"]
}