Skip to content

Commit cf94307

Browse files
committed
dockerfile: add extraBuildDirectives for directives at build stage
This PR adds the dockerfile: config option `extraBuildDirectives`, which adds additional docker directives at the end of the build stage. Motiviation is to change the certificate-chain, e.g. add addition certificates since they are generated only during build time and then copied to the final container.
1 parent 5ce89a8 commit cf94307

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ dockerfile:
156156
RUN toolbox-cmd
157157
extraBuildPackages:
158158
- linux-headers
159+
extraBuildDirectives:
160+
- |
161+
RUN wget -P /usr/local/share/ca-certificates/ http://example.com/some-custom-certificate.pem \
162+
&& update-ca-certificates
159163
extraDirectives:
160164
- 'LABEL mylabel=myvalue'
161165
- 'COPY --from=toolbox /bin/fancytool /usr/bin/fancytool'
@@ -182,6 +186,7 @@ With [go-api-declarations](https://github.com/sapcc/go-api-declarations)'s [`bin
182186
* `entrypoint` allows overwriting the final entrypoint.
183187
* `extraBuildStages` prepends additional build stages at the top of the Dockerfile. This is useful for bringing in precompiled assets from other images, or if a non-Go compilation step is required.
184188
* `extraBuildPackages` installs extra Alpine packages in the Docker layer where `make install` is executed. We always install `ca-certificates`, `gcc`, `git`, `make` and `musl-dev`.
189+
* `extraBuildDirectives` appends additional directives in the Docker layer after `make install` is executed.
185190
* `extraDirectives` appends additional directives near the end of the Dockerfile.
186191
* `extraIgnores` appends entries in `.dockerignore` to the default ones.
187192
* `extraPackages` installs extra Alpine packages in the final Docker layer. `ca-certificates` is always installed.

internal/core/config.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -234,16 +234,17 @@ type RenovateConfig struct {
234234

235235
// DockerfileConfig appears in type Configuration.
236236
type DockerfileConfig struct {
237-
Enabled bool `yaml:"enabled"`
238-
Entrypoint []string `yaml:"entrypoint"`
239-
ExtraBuildPackages []string `yaml:"extraBuildPackages"`
240-
ExtraBuildStages []string `yaml:"extraBuildStages"`
241-
ExtraDirectives []string `yaml:"extraDirectives"`
242-
ExtraIgnores []string `yaml:"extraIgnores"`
243-
ExtraPackages []string `yaml:"extraPackages"`
244-
RunAsRoot bool `yaml:"runAsRoot"`
245-
UseBuildKit bool `yaml:"useBuildKit"`
246-
WithLinkerdAwait bool `yaml:"withLinkerdAwait"`
237+
Enabled bool `yaml:"enabled"`
238+
Entrypoint []string `yaml:"entrypoint"`
239+
ExtraBuildDirectives []string `yaml:"extraBuildDirectives"`
240+
ExtraBuildPackages []string `yaml:"extraBuildPackages"`
241+
ExtraBuildStages []string `yaml:"extraBuildStages"`
242+
ExtraDirectives []string `yaml:"extraDirectives"`
243+
ExtraIgnores []string `yaml:"extraIgnores"`
244+
ExtraPackages []string `yaml:"extraPackages"`
245+
RunAsRoot bool `yaml:"runAsRoot"`
246+
UseBuildKit bool `yaml:"useBuildKit"`
247+
WithLinkerdAwait bool `yaml:"withLinkerdAwait"`
247248
}
248249

249250
type ControllerGen struct {

internal/dockerfile/Dockerfile.tmpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ RUN {{ if .UseBuildKit }}--mount=type=cache,target=/go/pkg/mod \
2020
--mount=type=cache,target=/root/.cache/go-build \
2121
{{ end }}make -C /src install PREFIX=/pkg GOTOOLCHAIN=local{{ if .Config.Golang.EnableVendoring }} GO_BUILDFLAGS='-mod vendor'{{ end }}
2222

23+
{{ range $dcfg.ExtraBuildDirectives -}}
24+
{{ . }}
25+
{{ end -}}
26+
2327
################################################################################
2428

2529
FROM alpine:{{ .Constants.DefaultAlpineImage }}

0 commit comments

Comments
 (0)