Skip to content
This repository has been archived by the owner on Dec 5, 2023. It is now read-only.

Commit

Permalink
Merge pull request #58 from microservices-demo/multistage-build
Browse files Browse the repository at this point in the history
Multistage docker build
  • Loading branch information
vlal authored Jan 29, 2018
2 parents a7ea691 + a49f19e commit 1968fe0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
21 changes: 7 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ GROUP = weaveworksdemos

TAG=$(TRAVIS_COMMIT)

default: build
default: docker


pre:
Expand Down Expand Up @@ -48,17 +48,14 @@ dockerruntest: dockertestdb dockerdev
docker run -d --name my$(TESTDB) -h my$(TESTDB) $(TESTDB)
docker run -d --name $(INSTANCE)-dev -p 8084:8084 --link my$(TESTDB) -e MONGO_HOST="my$(TESTDB):27017" $(INSTANCE)-dev

docker: build
cp -rf bin docker/user/
docker build -t $(NAME) -f docker/user/Dockerfile-release docker/user/
docker:
docker build -t $(NAME) -f docker/user/Dockerfile-release .

dockerlocal: build
cp -rf bin docker/user/
docker build -t $(INSTANCE)-local -f docker/user/Dockerfile-release docker/user/
dockerlocal:
docker build -t $(INSTANCE)-local -f docker/user/Dockerfile-release .

dockertravisbuild: build
cp -rf bin docker/user/
docker build -t $(NAME):$(TAG) -f docker/user/Dockerfile-release docker/user/
dockertravisbuild:
docker build -t $(NAME):$(TAG) -f docker/user/Dockerfile-release .
docker build -t $(DBNAME):$(TAG) -f docker/user-db/Dockerfile docker/user-db/
if [ -z "$(DOCKER_PASS)" ]; then \
echo "This is a build triggered by an external PR. Skipping docker push."; \
Expand Down Expand Up @@ -88,7 +85,3 @@ clean: cleandocker
rm -rf bin
rm -rf docker/user/bin
rm -rf vendor

build: deps
mkdir -p bin
CGO_ENABLED=0 go build -a -installsuffix cgo -o bin/$(INSTANCE) main.go
12 changes: 11 additions & 1 deletion docker/user/Dockerfile-release
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
FROM golang:1.7-alpine

COPY . /go/src/github.com/microservices-demo/user/
WORKDIR /go/src/github.com/microservices-demo/user/

RUN apk update
RUN apk add git
RUN go get -v github.com/Masterminds/glide
RUN glide install && CGO_ENABLED=0 go build -a -installsuffix cgo -o /user main.go

FROM alpine:3.4

ENV SERVICE_USER=myuser \
Expand All @@ -15,7 +25,7 @@ ENV MONGO_HOST user-db

WORKDIR /
EXPOSE 80
COPY bin/user /
COPY --from=0 /user /

RUN chmod +x /user && \
chown -R ${SERVICE_USER}:${SERVICE_GROUP} /user && \
Expand Down

0 comments on commit 1968fe0

Please sign in to comment.