Skip to content

Commit

Permalink
build distroless image (#16)
Browse files Browse the repository at this point in the history
* use distroless/static base image

* implement stat for readinessProbe
  • Loading branch information
kd7lxl authored Apr 20, 2021
1 parent babf17f commit ed5bcde
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
9 changes: 6 additions & 3 deletions build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.3
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.3 AS symlinker

RUN mkdir -p /opt/jsonnet && chown nobody /opt/jsonnet
ADD build/_output/bin/grafana-operator /usr/local/bin/grafana-operator
RUN cd /usr/local/bin/ && ln -sf grafana-operator stat

FROM gcr.io/distroless/static

USER nobody

ADD grafonnet-lib/grafonnet/ /opt/jsonnet/grafonnet

ADD build/_output/bin/grafana-operator /usr/local/bin/grafana-operator
COPY --from=symlinker /usr/local/bin/ /usr/local/bin/
16 changes: 16 additions & 0 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"os"
"path"
"runtime"
"strings"

Expand Down Expand Up @@ -141,6 +142,16 @@ func getSanitizedNamespaceList() []string {
return selected
}

func handleReadinessProbe(path string) int {
if fileInfo, err := os.Stat(path); err != nil {
fmt.Println(err)
return 1
} else {
fmt.Println(fileInfo)
return 0
}
}

func main() {
// The logger instantiated here can be changed to any logger
// implementing the logr.Logger interface. This logger will
Expand All @@ -149,6 +160,11 @@ func main() {

logf.SetLogger(zap.Logger())

// handles calls to `stat ready-file` from readiness probe without external dependencies
if path.Base(os.Args[0]) == "stat" {
os.Exit(handleReadinessProbe(os.Args[1]))
}

printVersion()

namespace, err := k8sutil.GetWatchNamespace()
Expand Down

0 comments on commit ed5bcde

Please sign in to comment.