Skip to content

Commit

Permalink
Add XCADDY_SKIP_BUILD option (#41)
Browse files Browse the repository at this point in the history
* feat: add XCADDY_NO_BUILD to not run go build

* Rename XCADDY_NO_BUILD to XCADDY_SKIP_BUILD

* fix rebase
  • Loading branch information
dunglas authored Feb 5, 2021
1 parent e7b19b1 commit 5734acd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
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

0 comments on commit 5734acd

Please sign in to comment.