Skip to content

Commit

Permalink
Merge pull request #51 from stripe/brandur-leaner-docker
Browse files Browse the repository at this point in the history
Leaner Docker image through the use of multi-stage builds
  • Loading branch information
brandur-stripe committed Mar 22, 2018
2 parents f44ea80 + 0aca127 commit 1644ab8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
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

0 comments on commit 1644ab8

Please sign in to comment.