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 }} username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_TOKEN }} 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 - name: Download ui build artifacts
uses: actions/download-artifact@v3 uses: actions/download-artifact@v3
with: with:

View File

@@ -1,56 +1,25 @@
# docker-bake.hcl — defines all five production images. # docker-bake.hcl — defines all five production images.
# #
# Used by CI (docker/bake-action) to build and push all images in one call, # Uses only plain variables for broad buildx compatibility (no locals/functions).
# with shared BuildKit cache and maximum parallelism: # CI pre-computes VERSION and MAJOR_MINOR from the git tag and passes them as
# - backend, runner, pocketbase share the Go builder stage (built once) # env vars. Locally, everything gets a :dev tag.
# - caddy and ui build independently in parallel alongside the Go targets
# #
# Local build (push=false by default): # Local build (no push):
# docker buildx bake # docker buildx bake
# #
# CI passes GIT_TAG (e.g. "v4.1.3") and the bake file computes all three tag # CI passes: DOCKER_USER, VERSION, MAJOR_MINOR, COMMIT, BUILD_TIME
# variants (full semver, major.minor, latest) — no docker/metadata-action needed.
# ── Variables injected by CI ────────────────────────────────────────────────── variable "DOCKER_USER" { default = "kalekber" }
variable "VERSION" { default = "dev" } # e.g. "4.1.6" (no leading v)
variable "DOCKER_USER" { default = "kalekber" } variable "MAJOR_MINOR" { default = "dev" } # e.g. "4.1"
variable "COMMIT" { default = "unknown" }
# Full git tag, e.g. "v4.1.3". CI passes this via --set or env. variable "BUILD_TIME" { default = "" }
# Locally defaults to "dev" so images get a :dev tag.
variable "GIT_TAG" { default = "dev" }
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 ─────────────────────────────────────────────────────────── # ── Shared defaults ───────────────────────────────────────────────────────────
target "_defaults" { target "_defaults" {
pull = true 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"] output = ["type=image,push=false"]
cache-to = ["type=inline"] cache-to = ["type=inline"]
} }
@@ -61,10 +30,14 @@ target "backend" {
inherits = ["_defaults"] inherits = ["_defaults"]
context = "backend" context = "backend"
target = "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"] cache-from = ["type=registry,ref=${DOCKER_USER}/libnovel-backend:latest"]
args = { args = {
VERSION = local.version VERSION = VERSION
COMMIT = COMMIT COMMIT = COMMIT
} }
} }
@@ -73,10 +46,14 @@ target "runner" {
inherits = ["_defaults"] inherits = ["_defaults"]
context = "backend" context = "backend"
target = "runner" 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"] cache-from = ["type=registry,ref=${DOCKER_USER}/libnovel-runner:latest"]
args = { args = {
VERSION = local.version VERSION = VERSION
COMMIT = COMMIT COMMIT = COMMIT
} }
} }
@@ -85,7 +62,11 @@ target "pocketbase" {
inherits = ["_defaults"] inherits = ["_defaults"]
context = "backend" context = "backend"
target = "pocketbase" 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"] cache-from = ["type=registry,ref=${DOCKER_USER}/libnovel-pocketbase:latest"]
} }
@@ -94,10 +75,14 @@ target "pocketbase" {
target "ui" { target "ui" {
inherits = ["_defaults"] inherits = ["_defaults"]
context = "ui" 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"] cache-from = ["type=registry,ref=${DOCKER_USER}/libnovel-ui:latest"]
args = { args = {
BUILD_VERSION = local.version BUILD_VERSION = VERSION
BUILD_COMMIT = COMMIT BUILD_COMMIT = COMMIT
BUILD_TIME = BUILD_TIME BUILD_TIME = BUILD_TIME
PREBUILT = "1" PREBUILT = "1"
@@ -109,7 +94,11 @@ target "ui" {
target "caddy" { target "caddy" {
inherits = ["_defaults"] inherits = ["_defaults"]
context = "caddy" 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"] cache-from = ["type=registry,ref=${DOCKER_USER}/libnovel-caddy:latest"]
} }