Merge pull request #4216 from mengqiy/updatedockerfilegen

update the dockerfile gen command
This commit is contained in:
Kubernetes Prow Robot
2021-09-29 13:51:22 -07:00
committed by GitHub
2 changed files with 10 additions and 6 deletions

View File

@@ -122,15 +122,17 @@ func AddGenerateDockerfile(cmd *cobra.Command) {
Use: "gen [DIR]",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return ioutil.WriteFile(filepath.Join(args[0], "Dockerfile"), []byte(`FROM golang:1.15-alpine as builder
return ioutil.WriteFile(filepath.Join(args[0], "Dockerfile"), []byte(`FROM golang:1.16-alpine as builder
ENV CGO_ENABLED=0
WORKDIR /go/src/
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN go build -tags netgo -ldflags '-w' -v -o /usr/local/bin/function ./
RUN go build -ldflags '-w -s' -v -o /usr/local/bin/function ./
FROM alpine:latest
COPY --from=builder /usr/local/bin/function /usr/local/bin/function
CMD ["function"]
ENTRYPOINT ["function"]
`), 0600)
},
}

View File

@@ -45,15 +45,17 @@ func TestCommand_dockerfile(t *testing.T) {
t.FailNow()
}
expected := `FROM golang:1.15-alpine as builder
expected := `FROM golang:1.16-alpine as builder
ENV CGO_ENABLED=0
WORKDIR /go/src/
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN go build -tags netgo -ldflags '-w' -v -o /usr/local/bin/function ./
RUN go build -ldflags '-w -s' -v -o /usr/local/bin/function ./
FROM alpine:latest
COPY --from=builder /usr/local/bin/function /usr/local/bin/function
CMD ["function"]
ENTRYPOINT ["function"]
`
if !assert.Equal(t, expected, string(b)) {
t.FailNow()