Skip to content

Commit

Permalink
Use distroless images and use user home dir to create files (#637)
Browse files Browse the repository at this point in the history
* Updated docker file to use distroless image and updated file created to be stored in user home directory
  • Loading branch information
aaronfern authored Jul 11, 2023
1 parent 73bded8 commit b3ab2b1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
8 changes: 3 additions & 5 deletions build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
9 changes: 8 additions & 1 deletion pkg/server/httpAPI.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"net/http/pprof"
"net/url"
"os"
"path/filepath"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 9 additions & 1 deletion pkg/snapstore/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit b3ab2b1

Please sign in to comment.