mirror of
https://github.com/dockersrc/go
synced 2026-06-24 14:01:08 -04:00
🐛 Fix dead accumulator, multi-arg exec drop, and init placeholder 🐛
set -e in go-workflow made the retVal/GO_EXITCODE accumulator dead code —
any failing run_step call exits the script immediately via set -e before
retVal=$? is ever reached, so GO_EXITCODE only ever sums zeros.
Remove the accumulator and simplify run_step; set -e already propagates
failures naturally.
__exec_command in the *) and exec) cases only used the first element of its
arg array (local cmdExec="${arg:-}" expands to arg[0]), silently dropping
every subsequent word. "docker run casjaysdev/go go test ./..." ran just
"go" with no subcommand. Replace __exec_command with exec "$@" directly in
both cases; exec is correct (no extra process) and preserves all args.
00-go.sh exported CONTAINER_INIT and SERVICE_USES_PID inside a subshell
( source "$init" ) — those exports never propagated back to the parent
entrypoint. Move SERVICE_USES_PID="no" to go.sh (sourced by the parent
shell before __start_init_scripts runs) so the framework takes the explicit
"config service, no PID" path. Rewrite 00-go.sh as a documented placeholder
explaining why the file must still exist (init_count == 0 triggers an
infinite background keep-alive loop).
- rootfs/usr/local/bin/go-workflow: remove GO_EXITCODE/retVal accumulator;
simplify run_step to drop exitCode capture (always 0 with set -e)
- rootfs/usr/local/bin/entrypoint.sh: *) case uses exec "$@" / exec go-workflow;
exec) case uses exec "$@" with proper empty-arg error instead of broken
__exec_command fallback
- rootfs/usr/local/etc/docker/env/go.sh: add SERVICE_USES_PID="no"
- rootfs/usr/local/etc/docker/init.d/00-go.sh: remove dead exports; add
comment explaining placeholder purpose
rootfs/usr/local/bin/entrypoint.sh
rootfs/usr/local/bin/go-workflow
rootfs/usr/local/etc/docker/env/go.sh
rootfs/usr/local/etc/docker/init.d/00-go.sh
This commit is contained in:
@@ -655,8 +655,11 @@ procs)
|
|||||||
# execute commands
|
# execute commands
|
||||||
exec)
|
exec)
|
||||||
shift 1
|
shift 1
|
||||||
__exec_command "${@:-echo "No commands given"}"
|
if [ $# -eq 0 ]; then
|
||||||
exit $?
|
echo "Error: exec requires a command" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
exec "$@"
|
||||||
;;
|
;;
|
||||||
# show/start init scripts
|
# show/start init scripts
|
||||||
start)
|
start)
|
||||||
@@ -682,11 +685,10 @@ start)
|
|||||||
*)
|
*)
|
||||||
if [ $# -eq 0 ]; then
|
if [ $# -eq 0 ]; then
|
||||||
# No args: run the default Go workflow (tidy → fmt → vet → test → build)
|
# No args: run the default Go workflow (tidy → fmt → vet → test → build)
|
||||||
__exec_command go-workflow
|
exec go-workflow
|
||||||
else
|
else
|
||||||
__exec_command "$@"
|
exec "$@"
|
||||||
fi
|
fi
|
||||||
exit $?
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
# Resolve the working directory — prefer /app if mounted, else cwd
|
# Resolve the working directory — prefer /app if mounted, else cwd
|
||||||
GO_EXITCODE=0
|
|
||||||
WORK_DIR="${GOWORKDIR:-${PWD}}"
|
WORK_DIR="${GOWORKDIR:-${PWD}}"
|
||||||
cd "$WORK_DIR"
|
cd "$WORK_DIR"
|
||||||
|
|
||||||
@@ -25,35 +24,21 @@ echo ""
|
|||||||
|
|
||||||
run_step() {
|
run_step() {
|
||||||
local label="$1"; shift
|
local label="$1"; shift
|
||||||
local exitCode=0
|
|
||||||
echo "── ${label}"
|
echo "── ${label}"
|
||||||
"$@"
|
"$@"
|
||||||
exitCode=$?
|
|
||||||
echo ""
|
echo ""
|
||||||
return $exitCode
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# 1. Sync module graph and go.sum before anything reads them
|
# 1. Sync module graph and go.sum before anything reads them
|
||||||
run_step "go mod tidy" go mod tidy
|
run_step "go mod tidy" go mod tidy
|
||||||
retVal=$?
|
|
||||||
GO_EXITCODE=$((GO_EXITCODE + retVal))
|
|
||||||
# 2. Format all Go source files in place
|
# 2. Format all Go source files in place
|
||||||
run_step "gofmt -w ." gofmt -w .
|
run_step "gofmt -w ." gofmt -w .
|
||||||
retVal=$?
|
|
||||||
GO_EXITCODE=$((GO_EXITCODE + retVal))
|
|
||||||
# 3. Catch suspicious constructs
|
# 3. Catch suspicious constructs
|
||||||
run_step "go vet ./..." go vet ./...
|
run_step "go vet ./..." go vet ./...
|
||||||
retVal=$?
|
|
||||||
GO_EXITCODE=$((GO_EXITCODE + retVal))
|
|
||||||
# 4. Run tests — fail fast before wasting time on a build
|
# 4. Run tests — fail fast before wasting time on a build
|
||||||
run_step "go test ./..." go test ./...
|
run_step "go test ./..." go test ./...
|
||||||
retVal=$?
|
|
||||||
GO_EXITCODE=$((GO_EXITCODE + retVal))
|
|
||||||
# 5. Build all main packages; output lands alongside source in each package dir
|
# 5. Build all main packages; output lands alongside source in each package dir
|
||||||
run_step "go build ./..." go build ./...
|
run_step "go build ./..." go build ./...
|
||||||
retVal=$?
|
|
||||||
GO_EXITCODE=$((GO_EXITCODE + retVal))
|
|
||||||
|
|
||||||
echo "✅ Done."
|
echo "✅ Done."
|
||||||
exit $GO_EXITCODE
|
|
||||||
|
|
||||||
|
|||||||
+2
@@ -12,3 +12,5 @@ MONGODB_CONFIG_FILE="none"
|
|||||||
# This image has no long-running daemon; suppress the startup banner and health loop
|
# This image has no long-running daemon; suppress the startup banner and health loop
|
||||||
ENTRYPOINT_MESSAGE="no"
|
ENTRYPOINT_MESSAGE="no"
|
||||||
HEALTH_ENABLED="no"
|
HEALTH_ENABLED="no"
|
||||||
|
# Tell __start_init_scripts this is a config-only init — no daemon process or PID file expected
|
||||||
|
SERVICE_USES_PID="no"
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# shellcheck shell=bash
|
# shellcheck shell=bash
|
||||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
##@Version : 202605292219-git
|
##@Version : 202506192219-git
|
||||||
# @@Author : Jason Hempstead
|
# @@Author : Jason Hempstead
|
||||||
# @@Contact : jason@casjaysdev.pro
|
# @@Contact : jason@casjaysdev.pro
|
||||||
# @@License : WTFPL
|
# @@License : WTFPL
|
||||||
@@ -9,9 +9,10 @@
|
|||||||
# @@Copyright : Copyright: (c) 2026 Jason Hempstead, Casjays Developments
|
# @@Copyright : Copyright: (c) 2026 Jason Hempstead, Casjays Developments
|
||||||
# @@Created : Friday, May 29, 2026 22:22 EDT
|
# @@Created : Friday, May 29, 2026 22:22 EDT
|
||||||
# @@File : 00-go.sh
|
# @@File : 00-go.sh
|
||||||
# @@Description : Go toolchain — configuration-only init (no daemon)
|
# @@Description : Go toolchain — placeholder init (no daemon)
|
||||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
# Tell the init framework this is a configuration service, not a daemon.
|
# This file must exist. __start_init_scripts spawns an infinite keep-alive loop
|
||||||
# This prevents __start_init_scripts from waiting for a PID or keep-alive loop.
|
# when init_count == 0 (no scripts in init.d/). Go is not a daemon — we just
|
||||||
export CONTAINER_INIT="yes"
|
# need one script so init_count >= 1. SERVICE_USES_PID is set in the env file
|
||||||
export SERVICE_USES_PID="no"
|
# (go.sh) which the parent shell reads; exports here are subshell-isolated and
|
||||||
|
# would not propagate back to the entrypoint anyway.
|
||||||
|
|||||||
Reference in New Issue
Block a user