From 5b7d4921c527afc82c6622a6c23070a7e977463d Mon Sep 17 00:00:00 2001 From: Maxime Guyot Date: Tue, 20 Mar 2018 09:45:10 +0100 Subject: [PATCH] Use multi-staging dockerfile and scratch image --- .travis.yml | 4 +++- Dockerfile | 27 +++++++++++++++++++++++---- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 928ca7d..c44f498 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,7 +24,9 @@ jobs: - stage: push install: skip script: - - ./scripts/build.sh + - VERSION=$(git rev-parse --short HEAD) + - docker build --tag "negz/kuberos:latest" . + - docker build --tag "negz/kuberos:${VERSION}" . - docker login -u "$DOCKER_USERNAME" -p "$DOCKER_PASSWORD" - ./scripts/push.sh diff --git a/Dockerfile b/Dockerfile index 34dcb9f..0a5738d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,25 @@ -FROM alpine:3.7 -MAINTAINER Nic Cope +FROM node:9.8-alpine as node +ADD frontend/ . +RUN npm install && npm run build + +FROM golang:1.10-alpine as golang +RUN apk --no-cache add git +WORKDIR /go/src/github.com/negz/kuberos/ +ENV CGO_ENABLED=0 + +ADD . . +COPY --from=node dist/ dist/frontend +COPY --from=node index.html dist/frontend/ -RUN apk update && apk add ca-certificates +RUN go get -u github.com/Masterminds/glide && \ + go get -u github.com/rakyll/statik && \ + glide install + +RUN cd statik && go generate && cd .. +RUN go build -o /kuberos ./cmd/kuberos + +FROM alpine:3.7 as ca-certificates +MAINTAINER Nic Cope -COPY "dist/kuberos" / \ No newline at end of file +RUN apk --no-cache add ca-certificates +COPY --from=golang /kuberos /