From 5734acdd58feadbf8857fe79fa8f6568ab10921a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Sat, 6 Feb 2021 00:34:51 +0100 Subject: [PATCH] Add XCADDY_SKIP_BUILD option (#41) * feat: add XCADDY_NO_BUILD to not run go build * Rename XCADDY_NO_BUILD to XCADDY_SKIP_BUILD * fix rebase --- README.md | 3 ++- builder.go | 7 +++++++ cmd/xcaddy/main.go | 3 +++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 41bfe84..eb660e7 100644 --- a/README.md +++ b/README.md @@ -124,8 +124,9 @@ Because the subcommands and flags are constrained to benefit rapid plugin protot - `CADDY_VERSION` sets the version of Caddy to build. - `XCADDY_RACE_DETECTOR=1` enables the Go race detector in the build. -- `XCADDY_SKIP_CLEANUP=1` causes xcaddy to leave build artifacts on disk after exiting. - `XCADDY_SETCAP=1` will run `sudo setcap cap_net_bind_service=+ep` on the temporary binary before running it when in dev mode. +- `XCADDY_SKIP_BUILD=1` causes xcaddy to not compile the program, it is used in conjunction with build tools such as [GoReleaser](https://goreleaser.com). Implies `XCADDY_SKIP_CLEANUP=1`. +- `XCADDY_SKIP_CLEANUP=1` causes xcaddy to leave build artifacts on disk after exiting. --- diff --git a/builder.go b/builder.go index ede9f32..351a136 100644 --- a/builder.go +++ b/builder.go @@ -42,6 +42,7 @@ type Builder struct { TimeoutBuild time.Duration `json:"timeout_build,omitempty"` RaceDetector bool `json:"race_detector,omitempty"` SkipCleanup bool `json:"skip_cleanup,omitempty"` + SkipBuild bool `json:"skip_build,omitempty"` } // Build builds Caddy at the configured version with the @@ -77,6 +78,12 @@ func (b Builder) Build(ctx context.Context, outputFile string) error { } defer buildEnv.Close() + if b.SkipBuild { + log.Printf("[INFO] Skipping build as requested") + + return nil + } + // prepare the environment for the go command; for // the most part we want it to inherit our current // environment, with a few customizations diff --git a/cmd/xcaddy/main.go b/cmd/xcaddy/main.go index 6769ae5..b74af42 100644 --- a/cmd/xcaddy/main.go +++ b/cmd/xcaddy/main.go @@ -32,6 +32,7 @@ import ( var ( caddyVersion = os.Getenv("CADDY_VERSION") raceDetector = os.Getenv("XCADDY_RACE_DETECTOR") == "1" + skipBuild = os.Getenv("XCADDY_SKIP_BUILD") == "1" skipCleanup = os.Getenv("XCADDY_SKIP_CLEANUP") == "1" ) @@ -111,6 +112,7 @@ func runBuild(ctx context.Context, args []string) error { Plugins: plugins, Replacements: replacements, RaceDetector: raceDetector, + SkipBuild: skipBuild, SkipCleanup: skipCleanup, } err := builder.Build(ctx, output) @@ -216,6 +218,7 @@ func runDev(ctx context.Context, args []string) error { }, Replacements: replacements, RaceDetector: raceDetector, + SkipBuild: skipBuild, SkipCleanup: skipCleanup, } err = builder.Build(ctx, binOutput)