From 32061b81690ec289a2bd23a1626d1478dc46d037 Mon Sep 17 00:00:00 2001 From: casjay Date: Mon, 4 May 2026 20:58:11 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Refactor=20env=20vars=20and=20op?= =?UTF-8?q?timize=20Go=20tool=20installation=20=F0=9F=94=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Rename ENV_IMAGE_NAME to ENV_REGISTRY_REPO and ENV_ORG_NAME to ENV_REGISTRY_ORG for consistent naming - Clarify ENV_REGISTRY_URL to be the provider base URL and rename ENV_IMAGE_PUSH to ENV_REGISTRY_PUSH - Extract install_go_tool helper to handle best-effort installs with periodic cache flushing every 5 tools - Add GOMAXPROCS, GOMEMLIMIT, and GOFLAGS env vars for controlled Go build resource usage - Clear test cache before module cache cleanup to reduce peak disk usage during image builds .env.scripts rootfs/root/docker/setup/05-custom.sh --- .env.scripts | 20 +++++++++-------- rootfs/root/docker/setup/05-custom.sh | 31 +++++++++++++++++++++------ 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/.env.scripts b/.env.scripts index cf05d06..c64bd5e 100644 --- a/.env.scripts +++ b/.env.scripts @@ -1,10 +1,10 @@ # - - - - - - - - - - - - - - - - - - - - - - - - - -##@Version : 202604221922-git +##@Version : 202605041627-git # @@Author : CasjaysDev # @@Contact : CasjaysDev # @@License : MIT # @@Copyright : Copyright 2026 CasjaysDev -# @@Created : Wed Apr 22 07:22:44 PM EDT 2026 +# @@Created : Mon May 4 04:27:58 PM EDT 2026 # @@File : .env.scripts # @@Description : Variables for gen-dockerfile and buildx scripts # @@Changelog : newScript @@ -25,11 +25,12 @@ DOCKER_ENTYPOINT_HEALTH_ENDPOINTS="$DOCKER_ENTYPOINT_HEALTH_ENDPOINTS" # - - - - - - - - - - - - - - - - - - - - - - - - - # Dockerfile info ENV_DOCKERFILE="Dockerfile" -ENV_IMAGE_NAME="go" +# ENV_REGISTRY_REPO: Registry repository/image name +ENV_REGISTRY_REPO="go" ENV_USE_TEMPLATE="alpine" # - - - - - - - - - - - - - - - - - - - - - - - - - # Maintainer info -ENV_ORG_NAME="casjaysdev" +ENV_REGISTRY_ORG="casjaysdev" ENV_VENDOR="CasjaysDev" ENV_AUTHOR="CasjaysDev" ENV_MAINTAINER="CasjaysDev " @@ -37,12 +38,12 @@ ENV_MAINTAINER="CasjaysDev " # Repository URLs (Full URLs) # ENV_GIT_REPO_URL: Complete Git repository URL for source code ENV_GIT_REPO_URL="https://github.com/dockersrc/go" -# ENV_REGISTRY_URL: Complete registry URL for reference (NOT used for pushing) -ENV_REGISTRY_URL="https://hub.docker.com/casjaysdev/go" +# ENV_REGISTRY_URL: Registry provider base URL (for example https://docker.io) +ENV_REGISTRY_URL="https://docker.io" # - - - - - - - - - - - - - - - - - - - - - - - - - # Push Configuration -# ENV_IMAGE_PUSH: Complete push destination (this IS used for pushing) -ENV_IMAGE_PUSH="casjaysdev/go" +# ENV_REGISTRY_PUSH: Complete push destination derived from registry/org/repo +ENV_REGISTRY_PUSH="casjaysdev/go" # ENV_IMAGE_TAG: Default tag for the image ENV_IMAGE_TAG="latest" # ENV_ADD_TAGS: Additional tags, comma-separated (USE_DATE = auto date tag) @@ -62,7 +63,7 @@ SERVICE_PORT="" EXPOSE_PORTS="" # - - - - - - - - - - - - - - - - - - - - - - - - - # IF using a lanuage such as go, php, rust, ruby, etc set the version here. -LANG_VERSION="go" +LANG_VERSION="" # - - - - - - - - - - - - - - - - - - - - - - - - - # Versions PHP_VERSION="system" @@ -80,3 +81,4 @@ ENV_PACKAGES="" # - - - - - - - - - - - - - - - - - - - - - - - - - # ex: ts=2 sw=2 et filetype=sh # - - - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/rootfs/root/docker/setup/05-custom.sh b/rootfs/root/docker/setup/05-custom.sh index 83a08d7..a7d57e7 100755 --- a/rootfs/root/docker/setup/05-custom.sh +++ b/rootfs/root/docker/setup/05-custom.sh @@ -40,10 +40,32 @@ export GOBIN="/usr/local/bin" export PATH="${GOBIN}:${PATH}" export CGO_ENABLED=0 export GOTOOLCHAIN=auto +export GOMAXPROCS="${GOMAXPROCS:-2}" +export GOMEMLIMIT="${GOMEMLIMIT:-1GiB}" +export GOFLAGS="${GOFLAGS:+${GOFLAGS} }-p=1" mkdir -p "$GOPATH" "$GOPATH/bin" "$GOPATH/cache" "$GOPATH/pkg/mod" if command -v go >/dev/null 2>&1; then echo "Installing Go developer tools with $(go version)" + tool_install_count=0 + + install_go_tool() { + local tool="$1" + + echo "go install $tool" + # Best-effort: don't fail the build if a single upstream tool has + # stale deps incompatible with the current Go release. The rest of + # the kitchen-sink installs cleanly and the user can manually + # `go install` whichever tools they need at runtime against their + # own version pin. + go install "$tool" || echo " WARN: skipping $tool (install failed)" >&2 + + tool_install_count=$((tool_install_count + 1)) + if [ "$tool_install_count" -ge 5 ]; then + go clean -cache -testcache 2>/dev/null || true + tool_install_count=0 + fi + } for tool in \ "github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest" \ @@ -99,13 +121,7 @@ if command -v go >/dev/null 2>&1; then "github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@latest" \ "github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@latest" \ ; do - echo "go install $tool" - # Best-effort: don't fail the build if a single upstream tool has - # stale deps incompatible with the current Go release. The rest of - # the kitchen-sink installs cleanly and the user can manually - # `go install` whichever tools they need at runtime against their - # own version pin. - go install "$tool" || echo " WARN: skipping $tool (install failed)" >&2 + install_go_tool "$tool" done # migrate: needs build tags for DB driver compilation. Limited to @@ -121,6 +137,7 @@ if command -v go >/dev/null 2>&1; then || echo " WARN: skipping migrate (install failed)" >&2 # Drop the module cache; it's not needed in the final image. + go clean -testcache 2>/dev/null || true go clean -modcache 2>/dev/null || true go clean -cache 2>/dev/null || true rm -rf "$GOPATH/pkg" "$GOPATH/src" 2>/dev/null || true