Skip to content

Commit

Permalink
allow to use gcp-get-secret as stand-alone image
Browse files Browse the repository at this point in the history
  • Loading branch information
mvanholsteijn committed May 1, 2021
1 parent eb9e0f7 commit 72adcba
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
11 changes: 9 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
FROM golang:1.16
FROM alpine:3 as ca
RUN apk add --no-cache ca-certificates


FROM golang:1.16 as go

WORKDIR /gcp-get-secret
ADD . /gcp-get-secret
RUN go mod download
RUN CGO_ENABLED=0 GOOS=linux go build -o gcp-get-secret -ldflags '-extldflags "-static"' .

FROM scratch
COPY --from=0 /gcp-get-secret/gcp-get-secret /
COPY --from=ca /etc/ssl/certs/ /etc/ssl/certs/
COPY --from=go /gcp-get-secret/gcp-get-secret /

ENTRYPOINT [ "/gcp-get-secret" ]
16 changes: 12 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,6 @@ func (m *Main) replaceDestinationReferencesWithURL(refs []GoogleSecretRef, env m

// execute the `command` with the environment set to actual values from the parameter store
func (m *Main) execProcess() {
program, err := exec.LookPath(m.command[0])
if err != nil {
log.Fatalf("could not find program %s on path, %s", m.command[0], err)
}

refs, err := m.environmentToGoogleSecretReferences(os.Environ())
if err != nil {
Expand All @@ -368,6 +364,18 @@ func (m *Main) execProcess() {

newEnv = m.replaceDestinationReferencesWithURL(refs, newEnv)

if len(m.command) == 1 && m.command[0] == "noop" {
if m.verbose {
log.Printf("INFO: noop")
}
return
}

program, err := exec.LookPath(m.command[0])
if err != nil {
log.Fatalf("could not find program %s on path, %s", m.command[0], err)
}

err = syscall.Exec(program, m.command, m.updateEnvironment(os.Environ(), newEnv))
if err != nil {
log.Fatal(err)
Expand Down

0 comments on commit 72adcba

Please sign in to comment.