Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add XCADDY_NO_BUILD to not run go build #41

Merged
merged 3 commits into from
Feb 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

---

Expand Down
7 changes: 7 additions & 0 deletions builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions cmd/xcaddy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down