Skip to content

Commit

Permalink
docker multistage build
Browse files Browse the repository at this point in the history
  • Loading branch information
hunterlong committed Nov 6, 2018
1 parent 41f944c commit b2fdaa5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
24 changes: 22 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
19 changes: 6 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b2fdaa5

Please sign in to comment.