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
This commit is contained in:
Kévin Dunglas 2021-02-06 00:34:51 +01:00 committed by GitHub
parent e7b19b13a2
commit 5734acdd58
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 1 deletions

View file

@ -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. - `CADDY_VERSION` sets the version of Caddy to build.
- `XCADDY_RACE_DETECTOR=1` enables the Go race detector in the 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_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.
--- ---

View file

@ -42,6 +42,7 @@ type Builder struct {
TimeoutBuild time.Duration `json:"timeout_build,omitempty"` TimeoutBuild time.Duration `json:"timeout_build,omitempty"`
RaceDetector bool `json:"race_detector,omitempty"` RaceDetector bool `json:"race_detector,omitempty"`
SkipCleanup bool `json:"skip_cleanup,omitempty"` SkipCleanup bool `json:"skip_cleanup,omitempty"`
SkipBuild bool `json:"skip_build,omitempty"`
} }
// Build builds Caddy at the configured version with the // 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() defer buildEnv.Close()
if b.SkipBuild {
log.Printf("[INFO] Skipping build as requested")
return nil
}
// prepare the environment for the go command; for // prepare the environment for the go command; for
// the most part we want it to inherit our current // the most part we want it to inherit our current
// environment, with a few customizations // environment, with a few customizations

View file

@ -32,6 +32,7 @@ import (
var ( var (
caddyVersion = os.Getenv("CADDY_VERSION") caddyVersion = os.Getenv("CADDY_VERSION")
raceDetector = os.Getenv("XCADDY_RACE_DETECTOR") == "1" raceDetector = os.Getenv("XCADDY_RACE_DETECTOR") == "1"
skipBuild = os.Getenv("XCADDY_SKIP_BUILD") == "1"
skipCleanup = os.Getenv("XCADDY_SKIP_CLEANUP") == "1" skipCleanup = os.Getenv("XCADDY_SKIP_CLEANUP") == "1"
) )
@ -111,6 +112,7 @@ func runBuild(ctx context.Context, args []string) error {
Plugins: plugins, Plugins: plugins,
Replacements: replacements, Replacements: replacements,
RaceDetector: raceDetector, RaceDetector: raceDetector,
SkipBuild: skipBuild,
SkipCleanup: skipCleanup, SkipCleanup: skipCleanup,
} }
err := builder.Build(ctx, output) err := builder.Build(ctx, output)
@ -216,6 +218,7 @@ func runDev(ctx context.Context, args []string) error {
}, },
Replacements: replacements, Replacements: replacements,
RaceDetector: raceDetector, RaceDetector: raceDetector,
SkipBuild: skipBuild,
SkipCleanup: skipCleanup, SkipCleanup: skipCleanup,
} }
err = builder.Build(ctx, binOutput) err = builder.Build(ctx, binOutput)