mirror of
https://github.com/dockersrc/go
synced 2026-06-24 20:01:07 -04:00
dad20b0a43
- CONTAINER_NAME was hardcoded to "alpine" instead of "go"; the startup
message said "alpine" for the same reason
- HEALTH_ENABLED was hard-assigned to "yes" after env files were sourced,
silently overriding the HEALTH_ENABLED="no" set in env/go.sh; changed
to ${HEALTH_ENABLED:-yes} so the env file value is respected
- go-workflow used retval (lowercase) to capture the go vet exit code but
then read retVal (uppercase) in the accumulator; the vet failure was
silently dropped and the gofmt exit code was summed twice instead
- rootfs/usr/local/bin/entrypoint.sh: fix CONTAINER_NAME default, startup
message label, and HEALTH_ENABLED hard-override
- rootfs/usr/local/bin/go-workflow: fix retval/retVal case mismatch so
go vet exit code is correctly propagated
rootfs/usr/local/bin/entrypoint.sh
rootfs/usr/local/bin/go-workflow
60 lines
1.6 KiB
Bash
Executable File
60 lines
1.6 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
|
|
GO_EXITCODE=0
|
|
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
|
|
local exitCode=0
|
|
echo "── ${label}"
|
|
"$@"
|
|
exitCode=$?
|
|
echo ""
|
|
return $exitCode
|
|
}
|
|
|
|
# 1. Sync module graph and go.sum before anything reads them
|
|
run_step "go mod tidy" go mod tidy
|
|
retVal=$?
|
|
GO_EXITCODE=$((GO_EXITCODE + retVal))
|
|
# 2. Format all Go source files in place
|
|
run_step "gofmt -w ." gofmt -w .
|
|
retVal=$?
|
|
GO_EXITCODE=$((GO_EXITCODE + retVal))
|
|
# 3. Catch suspicious constructs
|
|
run_step "go vet ./..." go vet ./...
|
|
retVal=$?
|
|
GO_EXITCODE=$((GO_EXITCODE + retVal))
|
|
# 4. Run tests — fail fast before wasting time on a build
|
|
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
|
|
run_step "go build ./..." go build ./...
|
|
retVal=$?
|
|
GO_EXITCODE=$((GO_EXITCODE + retVal))
|
|
|
|
echo "✅ Done."
|
|
exit $GO_EXITCODE
|
|
|