Skip to content

Commit 75f916b

Browse files
committed
chore: Introduce cli image variable
Signed-off-by: Jan Bouska <[email protected]>
1 parent af2dff5 commit 75f916b

File tree

6 files changed

+53
-49
lines changed

6 files changed

+53
-49
lines changed

Containerfile

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,33 @@
1-
# Use the official Golang image as a base
2-
FROM golang:1.23
1+
# Build the manager binary
2+
FROM golang:1.23 AS builder
3+
ARG TARGETOS
4+
ARG TARGETARCH
35

4-
# Set the working directory
5-
WORKDIR /app
6+
WORKDIR /workspace
7+
# Copy the Go Modules manifests
8+
COPY go.mod go.mod
9+
COPY go.sum go.sum
10+
# cache deps before building and copying source so that we don't need to re-download as much
11+
# and so that source changes don't invalidate our downloaded layer
12+
RUN go mod download
613

7-
# Copy all files
8-
COPY . .
14+
# Copy the go source
15+
COPY cmd/main.go cmd/main.go
16+
COPY api/ api/
17+
COPY internal/ internal/
918

10-
# Download dependencies
11-
RUN go mod download && go mod verify
19+
# Build
20+
# the GOARCH has not a default value to allow the binary be built according to the host where the command
21+
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
22+
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
23+
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
24+
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go
1225

13-
# Build the application
14-
RUN CGO_ENABLED=0 go build -v -o app .
26+
# Use distroless as minimal base image to package the manager binary
27+
# Refer to https://github.com/GoogleContainerTools/distroless for more details
28+
FROM gcr.io/distroless/static:nonroot
29+
WORKDIR /
30+
COPY --from=builder /workspace/manager .
31+
USER 65532:65532
1532

16-
FROM scratch
17-
COPY --from=0 /app/app /app
18-
EXPOSE 8080
19-
CMD ["/app"]
33+
ENTRYPOINT ["/manager"]

Dockerfile

Lines changed: 0 additions & 33 deletions
This file was deleted.

cmd/main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ import (
2121
"flag"
2222
"os"
2323

24+
"github.com/sigstore/model-validation-controller/internal/constants"
25+
"github.com/sigstore/model-validation-controller/internal/utils"
26+
2427
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
2528
// to ensure that exec-entrypoint and run can make use of them.
2629
_ "k8s.io/client-go/plugin/pkg/client/auth"
@@ -70,6 +73,7 @@ func main() {
7073
"If set, the metrics endpoint is served securely via HTTPS. Use --metrics-secure=false to use HTTP instead.")
7174
flag.BoolVar(&enableHTTP2, "enable-http2", false,
7275
"If set, HTTP/2 will be enabled for the metrics and webhook servers")
76+
utils.StringFlagOrEnv(&constants.ModelTransparencyCliImage, "model-transparency-cli-image", "MODEL_TRANSPARENCY_CLI_IMAGE", constants.ModelTransparencyCliImage, "Model transparency CLI image to be used.")
7377
opts := zap.Options{
7478
Development: true,
7579
}

internal/constants/images.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
package constants
22

3-
var ()
3+
var (
4+
ModelTransparencyCliImage = "ghcr.io/sigstore/model-transparency-cli:v1.0.1"
5+
)

internal/utils/utils.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package utils
2+
3+
import (
4+
"flag"
5+
"os"
6+
)
7+
8+
// StringFlagOrEnv defines a string flag which can be set by an environment variable.
9+
// Precedence: flag > env var > default value.
10+
func StringFlagOrEnv(p *string, name string, envName string, defaultValue string, usage string) {
11+
envValue := os.Getenv(envName)
12+
if envValue != "" {
13+
defaultValue = envValue
14+
}
15+
flag.StringVar(p, name, defaultValue, usage)
16+
}

internal/webhooks/pod_webhook.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"net/http"
88

9+
"github.com/sigstore/model-validation-controller/internal/constants"
910
corev1 "k8s.io/api/core/v1"
1011
"sigs.k8s.io/controller-runtime/pkg/client"
1112
"sigs.k8s.io/controller-runtime/pkg/log"
@@ -84,7 +85,7 @@ func (p *podInterceptor) Handle(ctx context.Context, req admission.Request) admi
8485
pp.Spec.InitContainers = append(pp.Spec.InitContainers, corev1.Container{
8586
Name: modelValidationInitContainerName,
8687
ImagePullPolicy: corev1.PullAlways,
87-
Image: "ghcr.io/sigstore/model-transparency-cli:v1.0.1", // TODO: get image from operator config.
88+
Image: constants.ModelTransparencyCliImage,
8889
Command: []string{"/usr/local/bin/model_signing"},
8990
Args: args,
9091
VolumeMounts: vm,

0 commit comments

Comments
 (0)