Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leaner Docker image through the use of multi-stage builds #51

Merged
merged 1 commit into from
Mar 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
README.md
LICENSE
Makefile
dist/
goreleaser.yml
openapi/
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ script:
- docker build -t "$DOCKER_REPO" .
- docker run -d --name stripe-mock-container -p 12111:12111 "$DOCKER_REPO"
- docker ps -a
- docker exec -it stripe-mock-container /bin/sh -c "cd /go/src/github.com/stripe/stripe-mock/; go test ./..."

deploy:
provider: script
Expand Down
30 changes: 25 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
FROM golang:1.9-alpine
# -*- mode: dockerfile -*-
#
# A multi-stage Dockerfile that builds a Linux target then creates a small
# final image for deployment.

ADD . /go/src/github.com/stripe/stripe-mock
#
# STAGE 1
#
# Uses a Go image to build a release binary.
#

RUN go install github.com/stripe/stripe-mock
FROM golang:1.9-alpine AS builder
WORKDIR /go/src/github.com/stripe/stripe-mock/
ADD ./ ./
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o stripe-mock .

EXPOSE 12111
#
# STAGE 2
#
# Use a tiny base image (alpine) and copy in the release target. This produces
# a very small output image for deployment.
#

ENTRYPOINT /go/bin/stripe-mock
FROM alpine:latest
RUN apk --no-cache add ca-certificates
WORKDIR /
COPY --from=builder /go/src/github.com/stripe/stripe-mock/stripe-mock .
ENTRYPOINT /stripe-mock
EXPOSE 12111