mirror of
https://github.com/dockersrc/go
synced 2026-06-24 14:01:08 -04:00
🔧 Refactor env vars and optimize Go tool installation 🔧
- 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
This commit is contained in:
+11
-9
@@ -1,10 +1,10 @@
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
##@Version : 202604221922-git
|
||||
##@Version : 202605041627-git
|
||||
# @@Author : CasjaysDev
|
||||
# @@Contact : CasjaysDev <docker-admin@casjaysdev.pro>
|
||||
# @@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 <docker-admin@casjaysdev.pro>"
|
||||
@@ -37,12 +38,12 @@ ENV_MAINTAINER="CasjaysDev <docker-admin@casjaysdev.pro>"
|
||||
# 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
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user