diff --git a/.travis.yml b/.travis.yml index eeac097..becc47f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,15 @@ language: go +services: + - docker + go: - "1.10.x" - master -script: go get -u github.com/golang/dep/cmd/dep && make vendor && make +script: + - docker --version + - go get -u github.com/golang/dep/cmd/dep && make vendor && make && make build + - docker images + - make build-multistage + - docker images diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7e38d28 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,27 @@ +FROM golang:1.11-alpine as builder + +# Install our build tools + +RUN apk add --update git make bash +RUN go get -u github.com/golang/dep/cmd/dep + +# Get sources + +RUN go get github.com/bloomberg/goldpinger/cmd/goldpinger +WORKDIR /go/src/github.com/bloomberg/goldpinger + +# Install our dependencies + +RUN make vendor + +# Build goldpinger + +RUN make bin/goldpinger + +# Build the asset container, copy over goldpinger + +FROM scratch +COPY --from=builder /go/src/github.com/bloomberg/goldpinger/bin/goldpinger /goldpinger +COPY ./static /static +ENTRYPOINT ["/goldpinger", "--static-file-path", "/static"] + diff --git a/Makefile b/Makefile index d0eb6f1..53f18d0 100644 --- a/Makefile +++ b/Makefile @@ -22,8 +22,11 @@ swagger: swagger generate server -t pkg -f ./swagger.yml --exclude-main -A goldpinger && \ swagger generate client -t pkg -f ./swagger.yml -A goldpinger +build-multistage: + sudo docker build -t $(tag) -f ./Dockerfile . + build: bin/$(bin) - sudo docker build -t $(tag) -f ./build/Dockerfile . + sudo docker build -t $(tag) -f ./build/Dockerfile-simple . tag: sudo docker tag $(tag) $(namespace)$(tag) diff --git a/README.md b/README.md index 7d314f1..e877ae3 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,8 @@ Oh, and it gives you the graph below for your cluster. Check out the [video expl - [Rationale](#rationale) - [Quick start](#quick-start) - [Building](#building) + - [Compiling using a multi-stage Dockerfile](#compiling-using-a-multi-stage-dockerfile) + - [Compiling locally](#compiling-locally) - [Installation](#installation) - [Authentication with Kubernetes API](#authentication-with-kubernetes-api) - [Example YAML](#example-yaml) @@ -46,9 +48,28 @@ Note, that in order to guarantee correct versions of dependencies, the project [ ## Building +The repo comes with two ways of building a `docker` image: compliling locally, and compliling using a multi-stage `Dockerfile` image. + +### Compiling using a multi-stage Dockerfile + +You will need `docker` version 17.05+ installed to support multi-stage builds. + +```sh +# step 1: launch the build +make build-multistage + +# step 2: push the image somewhere +namespace="docker.io/myhandle/" make tag +namespace="docker.io/myhandle/" make push +``` + +This was contributed via [@michiel](https://github.com/michiel) - kudos ! + +### Compiling locally + In order to build `Goldpinger`, you are going to need `go` version 1.10+, `dep`, and `docker`. -Building from source code consists of compiling the binary and building a [Docker image](./build/Dockerfile): +Building from source code consists of compiling the binary and building a [Docker image](./build/Dockerfile-simple): ```sh # step 0: check out the code into your $GOPATH diff --git a/build/Dockerfile b/build/Dockerfile-simple similarity index 100% rename from build/Dockerfile rename to build/Dockerfile-simple