From b3ab2b15a5f2a8583f9b834c4b61ba389a0e3577 Mon Sep 17 00:00:00 2001 From: Aaron Francis Fernandes <79958509+aaronfern@users.noreply.github.com> Date: Tue, 11 Jul 2023 11:00:35 +0530 Subject: [PATCH] Use distroless images and use user home dir to create files (#637) * Updated docker file to use distroless image and updated file created to be stored in user home directory --- build/Dockerfile | 8 +++----- pkg/server/httpAPI.go | 9 ++++++++- pkg/snapstore/utils.go | 10 +++++++++- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/build/Dockerfile b/build/Dockerfile index 4fd22f0f2..2efb71a39 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -19,10 +19,8 @@ COPY . . RUN make build -FROM alpine:3.18.2 +FROM gcr.io/distroless/static-debian11:nonroot AS backup-restore -RUN apk add --update bash curl - -COPY --from=builder /go/src/github.com/gardener/backup-restore/bin/etcdbrctl /usr/local/bin/etcdbrctl +COPY --from=builder /go/src/github.com/gardener/backup-restore/bin/etcdbrctl /etcdbrctl WORKDIR / -ENTRYPOINT ["/usr/local/bin/etcdbrctl"] +ENTRYPOINT ["/etcdbrctl"] diff --git a/pkg/server/httpAPI.go b/pkg/server/httpAPI.go index b7dc6ae7b..5173f9619 100644 --- a/pkg/server/httpAPI.go +++ b/pkg/server/httpAPI.go @@ -27,6 +27,7 @@ import ( "net/http/pprof" "net/url" "os" + "path/filepath" "strconv" "strings" "sync" @@ -389,7 +390,13 @@ func (h *HTTPHandler) serveLatestSnapshotMetadata(rw http.ResponseWriter, req *h func (h *HTTPHandler) serveConfig(rw http.ResponseWriter, req *http.Request) { inputFileName := miscellaneous.EtcdConfigFilePath - outputFileName := "/etc/etcd.conf.yaml" + dir, err := os.UserHomeDir() + if err != nil { + h.Logger.Warnf("Unable to get user home dir: %v", err) + rw.WriteHeader(http.StatusInternalServerError) + return + } + outputFileName := filepath.Join(dir, "etcd.conf.yaml") configYML, err := ioutil.ReadFile(inputFileName) if err != nil { h.Logger.Warnf("Unable to read etcd config file: %v", err) diff --git a/pkg/snapstore/utils.go b/pkg/snapstore/utils.go index e980641de..b065bc3b9 100644 --- a/pkg/snapstore/utils.go +++ b/pkg/snapstore/utils.go @@ -76,7 +76,15 @@ func GetSnapstore(config *brtypes.SnapstoreConfig) (brtypes.SnapStore, error) { if config.Container == "" { config.Container = defaultLocalStore } - return NewLocalSnapStore(path.Join(config.Container, config.Prefix)) + if strings.HasPrefix(config.Container, "../../../test/output") { + // To be used only by unit tests + return NewLocalSnapStore(path.Join(config.Container, config.Prefix)) + } + homeDir, err := os.UserHomeDir() + if err != nil { + return nil, err + } + return NewLocalSnapStore(path.Join(homeDir, config.Container, config.Prefix)) case brtypes.SnapstoreProviderS3: return NewS3SnapStore(config) case brtypes.SnapstoreProviderABS: