Skip to content

Commit

Permalink
Allow static files to be published into final image
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
  • Loading branch information
alexellis committed Apr 13, 2022
1 parent 1e91dec commit c6c867d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
10 changes: 5 additions & 5 deletions template/golang-http/Dockerfile
Expand Up @@ -26,16 +26,16 @@ ENV CGO_ENABLED=${CGO_ENABLED}
# Run a gofmt and exclude all vendored code.
RUN test -z "$(gofmt -l $(find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./function/vendor/*"))" || { echo "Run \"gofmt -s -w\" on your Golang code"; exit 1; }


WORKDIR /go/src/handler/function
RUN mkdir -p /go/src/handler/function/static

RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} go test ./... -cover

WORKDIR /go/src/handler
RUN CGO_ENABLED=${CGO_ENABLED} GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
go build --ldflags "-s -w" -a -installsuffix cgo -o handler .

FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine:3.14
FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine:3.15
# Add non root user and certs
RUN apk --no-cache add ca-certificates \
&& addgroup -S app && adduser -S -g app app
Expand All @@ -46,9 +46,9 @@ RUN mkdir -p /home/app \

WORKDIR /home/app

COPY --from=build --chown=app /go/src/handler/handler .
COPY --from=build --chown=app /usr/bin/fwatchdog .
COPY --from=build --chown=app /go/src/handler/function/ .
COPY --from=build --chown=app /go/src/handler/handler .
COPY --from=build --chown=app /usr/bin/fwatchdog .
COPY --from=build --chown=app /go/src/handler/function/static static

USER app

Expand Down
10 changes: 6 additions & 4 deletions template/golang-middleware/Dockerfile
Expand Up @@ -26,14 +26,16 @@ ENV CGO_ENABLED=${CGO_ENABLED}
RUN test -z "$(gofmt -l $(find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./function/vendor/*"))" || { echo "Run \"gofmt -s -w\" on your Golang code"; exit 1; }

WORKDIR /go/src/handler/function
RUN mkdir -p /go/src/handler/function/static

RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} go test ./... -cover

WORKDIR /go/src/handler
RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
go build --ldflags "-s -w" -a -installsuffix cgo -o handler .

FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine:3.14
FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine:3.15 as ship

# Add non root user and certs
RUN apk --no-cache add ca-certificates \
&& addgroup -S app && adduser -S -g app app
Expand All @@ -44,9 +46,9 @@ RUN mkdir -p /home/app \

WORKDIR /home/app

COPY --from=build --chown=app /go/src/handler/handler .
COPY --from=build --chown=app /usr/bin/fwatchdog .
COPY --from=build --chown=app /go/src/handler/function/ .
COPY --from=build --chown=app /go/src/handler/handler .
COPY --from=build --chown=app /usr/bin/fwatchdog .
COPY --from=build --chown=app /go/src/handler/function/static static

USER app

Expand Down

0 comments on commit c6c867d

Please sign in to comment.