Skip to content

Commit

Permalink
WIP: enable debugger in built images
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Hall <[email protected]>
  • Loading branch information
imjasonh committed Jun 12, 2024
1 parent 3d18274 commit 90b57ca
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 20 deletions.
1 change: 1 addition & 0 deletions docs/resources/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Sample resource in the Terraform provider scaffolding.
### Optional

- `base_image` (String) base image to use
- `enable_debugger` (Boolean) Enable a debugger in the built image
- `env` (List of String) Extra environment variables to pass to the go build
- `ldflags` (List of String) Extra ldflags to pass to the go build
- `platforms` (List of String) Which platform to use when pulling a multi-platform base. Format: all | <os>[/<arch>[/<variant>]][,platform]*
Expand Down
50 changes: 30 additions & 20 deletions internal/provider/resource_ko_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,21 +119,29 @@ func resourceBuild() *schema.Resource {
Elem: &schema.Schema{Type: schema.TypeString},
ForceNew: true, // Any time this changes, don't try to update in-place, just create it.
},
"enable_debugger": {
Description: "Enable a debugger in the built image",
Optional: true,
Type: schema.TypeBool,
Default: false,
ForceNew: true, // Any time this changes, don't try to update in-place, just create it.
},
},
}
}

type buildOptions struct {
ip string
workingDir string
imageRepo string // The image's repo, either from the KO_DOCKER_REPO env var, or provider-configured dockerRepo/repo, or image resource's repo.
platforms []string
baseImage string
sbom string
auth *authn.Basic
bare bool // If true, use the "bare" namer that doesn't append the importpath.
ldflags []string // Extra ldflags to pass to the go build.
env []string // Extra environment variables to pass to the go build.
ip string
workingDir string
imageRepo string // The image's repo, either from the KO_DOCKER_REPO env var, or provider-configured dockerRepo/repo, or image resource's repo.
platforms []string
baseImage string
sbom string
auth *authn.Basic
bare bool // If true, use the "bare" namer that doesn't append the importpath.
ldflags []string // Extra ldflags to pass to the go build.
env []string // Extra environment variables to pass to the go build.
enableDebugger bool
}

var (
Expand All @@ -151,6 +159,7 @@ var (
func (o *buildOptions) makeBuilder(ctx context.Context) (*build.Caching, error) {
bo := []build.Option{
build.WithTrimpath(true),
// TODO build.WithDebugger(o.enableDebugger),
build.WithPlatforms(o.platforms...),
build.WithConfig(map[string]build.Config{
o.ip: {
Expand Down Expand Up @@ -290,16 +299,17 @@ func fromData(d *schema.ResourceData, po *Opts) buildOptions {
}

return buildOptions{
ip: d.Get("importpath").(string),
workingDir: d.Get("working_dir").(string),
imageRepo: repo,
platforms: defaultPlatform(toStringSlice(d.Get("platforms").([]interface{}))),
baseImage: getString(d, "base_image", po.bo.BaseImage),
sbom: d.Get("sbom").(string),
auth: po.auth,
bare: bare,
ldflags: toStringSlice(d.Get("ldflags").([]interface{})),
env: toStringSlice(d.Get("env").([]interface{})),
ip: d.Get("importpath").(string),
workingDir: d.Get("working_dir").(string),
imageRepo: repo,
platforms: defaultPlatform(toStringSlice(d.Get("platforms").([]interface{}))),
baseImage: getString(d, "base_image", po.bo.BaseImage),
sbom: d.Get("sbom").(string),
auth: po.auth,
bare: bare,
ldflags: toStringSlice(d.Get("ldflags").([]interface{})),
env: toStringSlice(d.Get("env").([]interface{})),
enableDebugger: d.Get("enable_debugger").(bool),
}
}

Expand Down

0 comments on commit 90b57ca

Please sign in to comment.