mirror of
https://github.com/dockersrc/go
synced 2026-06-24 20:01:07 -04:00
✨ Default workflow: no-args runs tidy→fmt→vet→test→build ✨
Replace the service-lifecycle init script with a lean Go-native default workflow. Running the container with no arguments now automatically formats, vets, tests, and builds the mounted project. - rootfs/usr/local/etc/docker/init.d/00-go.sh: stripped from 979 lines of daemon-lifecycle boilerplate to 3 lines that export CONTAINER_INIT=yes and SERVICE_USES_PID=no, telling the init framework this is a configuration-only container (no daemon, no keep-alive loop) - rootfs/usr/local/bin/go-workflow: new script — runs the canonical Go workflow in order: go mod tidy → gofmt -w . → go vet ./... → go test ./... → go build ./...; exits 1 with a clear usage message if no go.mod is found in /app - rootfs/usr/local/bin/entrypoint.sh: no-args path in both the init block and the * case now exec go-workflow instead of __no_exit; verified: default workflow, explicit commands, sh -c passthrough, and missing go.mod error all behave correctly - README.md: document the default workflow prominently; update one-shot examples; add golangci-lint --timeout note; add tail null long-running pattern README.md rootfs/usr/local/bin/entrypoint.sh rootfs/usr/local/bin/go-workflow rootfs/usr/local/etc/docker/init.d/00-go.sh
This commit is contained in:
@@ -506,9 +506,9 @@ if [ "$START_SERVICES" = "yes" ] || [ -z "$1" ]; then
|
||||
echo "$$" >"$ENTRYPOINT_PID_FILE"
|
||||
__start_init_scripts "/usr/local/etc/docker/init.d"
|
||||
CONTAINER_INIT="${CONTAINER_INIT:-no}"
|
||||
# Only block in monitoring mode when no user command was given
|
||||
# No user command: run default Go workflow instead of blocking
|
||||
if [ $# -eq 0 ]; then
|
||||
__no_exit
|
||||
__exec_command go-workflow
|
||||
exit $?
|
||||
fi
|
||||
fi
|
||||
@@ -643,8 +643,13 @@ procs)
|
||||
;;
|
||||
# Launch shell
|
||||
*/bin/sh | */bin/bash | bash | sh | shell)
|
||||
shell_bin="$(type -P "${1}" 2>/dev/null || echo "/bin/bash")"
|
||||
shift 1
|
||||
__exec_command "${@:-/bin/bash -l}"
|
||||
if [ $# -gt 0 ]; then
|
||||
__exec_command "$shell_bin" "$@"
|
||||
else
|
||||
__exec_command "$shell_bin" -l
|
||||
fi
|
||||
exit $?
|
||||
;;
|
||||
# execute commands
|
||||
@@ -676,11 +681,8 @@ start)
|
||||
# Execute primary command
|
||||
*)
|
||||
if [ $# -eq 0 ]; then
|
||||
if [ ! -f "$ENTRYPOINT_PID_FILE" ]; then
|
||||
echo "$$" >"$ENTRYPOINT_PID_FILE"
|
||||
[ "$START_SERVICES" = "no" ] && [ "$CONTAINER_INIT" = "yes" ] || __start_init_scripts "/usr/local/etc/docker/init.d"
|
||||
fi
|
||||
__no_exit
|
||||
# No args: run the default Go workflow (tidy → fmt → vet → test → build)
|
||||
__exec_command go-workflow
|
||||
else
|
||||
__exec_command "$@"
|
||||
fi
|
||||
|
||||
Executable
+47
@@ -0,0 +1,47 @@
|
||||
#!/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."
|
||||
Reference in New Issue
Block a user