mirror of
https://github.com/dockersrc/go
synced 2026-06-24 14:01:08 -04:00
8dc2fd894b
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
45 lines
1.3 KiB
Bash
Executable File
45 lines
1.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# shellcheck shell=bash
|
|
# Default Go workflow: tidy → fmt → vet → test → build
|
|
# Runs automatically when `docker run casjaysdev/go` is called with no args.
|
|
# Working directory is expected to be a Go module root (go.mod must exist).
|
|
set -euo pipefail
|
|
|
|
# Resolve the working directory — prefer /app if mounted, else cwd
|
|
WORK_DIR="${GOWORKDIR:-${PWD}}"
|
|
cd "$WORK_DIR"
|
|
|
|
# Require a go.mod so we fail fast with a clear message instead of cryptic go errors
|
|
if [ ! -f "go.mod" ]; then
|
|
echo "Error: no go.mod found in ${WORK_DIR}" >&2
|
|
echo "Mount your project with: docker run --rm -v \"\$(pwd)\":/app casjaysdev/go" >&2
|
|
exit 1
|
|
fi
|
|
|
|
MODULE="$(awk '/^module /{print $2}' go.mod)"
|
|
echo ""
|
|
echo "▶ Go workflow: ${MODULE}"
|
|
echo " Working dir: ${WORK_DIR}"
|
|
echo ""
|
|
|
|
run_step() {
|
|
local label="$1"; shift
|
|
echo "── ${label}"
|
|
"$@"
|
|
echo ""
|
|
}
|
|
|
|
# 1. Sync module graph and go.sum before anything reads them
|
|
run_step "go mod tidy" go mod tidy
|
|
# 2. Format all Go source files in place
|
|
run_step "gofmt -w ." gofmt -w .
|
|
# 3. Catch suspicious constructs
|
|
run_step "go vet ./..." go vet ./...
|
|
# 4. Run tests — fail fast before wasting time on a build
|
|
run_step "go test ./..." go test ./...
|
|
# 5. Build all main packages; output lands alongside source in each package dir
|
|
run_step "go build ./..." go build ./...
|
|
|
|
echo "✅ Done."
|
|
|