From b2fdaa5c14e658d2471c916ced3c70921af7ec77 Mon Sep 17 00:00:00 2001 From: Hunter Long Date: Mon, 5 Nov 2018 19:26:37 -0800 Subject: [PATCH] docker multistage build --- Dockerfile | 24 ++++++++++++++++++++++-- Makefile | 19 ++++++------------- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/Dockerfile b/Dockerfile index 84bf4892..9f22ccb3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,31 @@ +FROM golang:1.11-alpine as base +MAINTAINER "Hunter Long (https://github.com/hunterlong)" ARG VERSION -FROM hunterlong/statup:base-v${VERSION} +ENV DEP_VERSION v0.5.0 +RUN apk add --no-cache libstdc++ gcc g++ make git ca-certificates linux-headers wget curl jq +RUN curl -L -s https://github.com/golang/dep/releases/download/$DEP_VERSION/dep-linux-amd64 -o /go/bin/dep && \ + chmod +x /go/bin/dep +RUN curl -L -s https://assets.statup.io/sass -o /usr/local/bin/sass && \ + chmod +x /usr/local/bin/sass +WORKDIR /go/src/github.com/hunterlong/statup +ADD . /go/src/github.com/hunterlong/statup +RUN make dep +RUN make dev-deps +RUN make install + +# Statup :latest Docker Image +FROM alpine:latest MAINTAINER "Hunter Long (https://github.com/hunterlong)" -RUN apk --no-cache add curl jq +ARG VERSION ENV IS_DOCKER=true ENV STATUP_DIR=/app +RUN apk --no-cache add curl jq + +COPY --from=base /usr/local/bin/sass /usr/local/bin/sass +COPY --from=base /go/bin/statup /usr/local/bin/statup + WORKDIR /app VOLUME /app EXPOSE 8080 diff --git a/Makefile b/Makefile index b44807fc..fefcbf65 100644 --- a/Makefile +++ b/Makefile @@ -31,10 +31,10 @@ travis-test: dev-deps cypress-install test coverage build-all: build-mac build-linux build-windows build-alpine compress # build all docker tags -docker-build-all: docker-build-base docker-build-dev docker-build-latest +docker-build-all: docker-build-dev docker-build-latest # push all docker tags built -docker-publish-all: docker-push-base docker-push-dev docker-push-latest +docker-publish-all: docker-push-dev docker-push-latest # build Statup for local arch build: compile @@ -129,22 +129,15 @@ build-alpine: compile # # build :latest docker tag -docker-build-latest: docker-build-base +docker-build-latest: docker build --build-arg VERSION=$(VERSION) -t hunterlong/statup:latest --no-cache -f Dockerfile . - docker tag hunterlong/statup:latest hunterlong/statup:latest-v$(VERSION) + docker tag hunterlong/statup:latest hunterlong/statup:v$(VERSION) # build :dev docker tag -docker-build-dev: docker-build-base +docker-build-dev: docker build --build-arg VERSION=$(VERSION) -t hunterlong/statup:dev --no-cache -f dev/Dockerfile-dev . docker tag hunterlong/statup:dev hunterlong/statup:dev-v$(VERSION) -# build :base and base-v{VERSION} docker tag -docker-build-base: clean - wget -q https://assets.statup.io/sass && chmod +x sass - $(XGO) --targets=linux/amd64 -ldflags="-X main.VERSION=$(VERSION) -linkmode external -extldflags -static" -out alpine ./cmd - docker build -t hunterlong/statup:base --no-cache -f dev/Dockerfile-base . - docker tag hunterlong/statup:base hunterlong/statup:base-v$(VERSION) - # build Cypress UI testing :cypress docker tag docker-build-cypress: clean GOPATH=$(GOPATH) xgo -out statup -go 1.10.x -ldflags "-X main.VERSION=$(VERSION) -X main.COMMIT=$(TRAVIS_COMMIT)" --targets=linux/amd64 ./cmd @@ -181,7 +174,7 @@ docker-push-cypress: # push the :latest tag to Docker hub docker-push-latest: docker push hunterlong/statup:latest - docker push hunterlong/statup:latest-v$(VERSION) + docker push hunterlong/statup:v$(VERSION) docker-run-mssql: docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=PaSsW0rD123' -p 1433:1433 -d microsoft/mssql-server-linux