Skip to content

Commit

Permalink
refactor Dockerfile into multi-stage
Browse files Browse the repository at this point in the history
First stage does the build in a pristine alpine environment. Second
stage is a minimal image with just the necessary stuff to run the
compiled binary. Also added packages for gcc and musl-dev so cgo can do
its thang.

Signed-off-by: Andrew Hsu <andrewhsu@docker.com>
  • Loading branch information
andrewhsu committed Sep 25, 2018
1 parent 2c7e0a4 commit f859701
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
FROM golang:1.10.4-alpine3.8

COPY gosec /usr/local/bin
FROM golang:1.10.4-alpine3.8 as build
WORKDIR /go/src/github.com/securego/gosec
COPY . .
RUN apk add -U git make
RUN go get -u github.com/golang/dep/cmd/dep
RUN make

FROM golang:1.10.4-alpine3.8
RUN apk add -U gcc musl-dev
COPY --from=build /go/src/github.com/securego/gosec/gosec /usr/local/bin/gosec
ENTRYPOINT ["gosec"]
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ release: bootstrap
build-linux:
CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GOARCH=amd64 go build -ldflags $(BUILDFLAGS) -o $(BIN) ./cmd/gosec/

image: build-linux
image:
@echo "Building the Docker image..."
docker build -t $(IMAGE_REPO)/$(BIN):$(GIT_TAG) .
docker tag $(IMAGE_REPO)/$(BIN):$(GIT_TAG) $(IMAGE_REPO)/$(BIN):latest
Expand Down

0 comments on commit f859701

Please sign in to comment.