From 8b7d46cb26de53e40a4f030878dd6c4c98506eeb Mon Sep 17 00:00:00 2001 From: Martin Linkhorst Date: Tue, 18 Jul 2017 20:13:51 +0200 Subject: [PATCH] chore: build image using multi-stage builds (#276) --- Dockerfile | 16 ++++++++++++---- Makefile | 5 +---- delivery.yaml | 18 ++++++++++++++++++ 3 files changed, 31 insertions(+), 8 deletions(-) create mode 100644 delivery.yaml diff --git a/Dockerfile b/Dockerfile index 1d2cac740c..fc44bae71a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,10 +12,18 @@ # See the License for the specific language governing permissions and # limitations under the License. -FROM alpine:3.5 +# builder image +FROM golang:1.8 as builder -RUN apk --update --no-cache add ca-certificates +WORKDIR /go/src/github.com/kubernetes-incubator/external-dns +COPY . . +RUN make test +RUN make build -COPY build/linux-amd64/external-dns /external-dns +# final image +FROM registry.opensource.zalan.do/stups/alpine:latest +MAINTAINER Team Teapot @ Zalando SE -ENTRYPOINT ["/external-dns"] +COPY --from=builder /go/src/github.com/kubernetes-incubator/external-dns/build/external-dns /bin/external-dns + +ENTRYPOINT ["/bin/external-dns"] diff --git a/Makefile b/Makefile index 05255829f2..0a3ebaa3fd 100644 --- a/Makefile +++ b/Makefile @@ -56,11 +56,8 @@ build/$(BINARY): $(SOURCES) build.push: build.docker docker push "$(IMAGE):$(VERSION)" -build.docker: build/linux-amd64/$(BINARY) +build.docker: docker build --rm --tag "$(IMAGE):$(VERSION)" . -build/linux-amd64/$(BINARY): $(SOURCES) - CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o build/linux-amd64/$(BINARY) $(BUILD_FLAGS) -ldflags "$(LDFLAGS)" . - clean: @rm -rf build diff --git a/delivery.yaml b/delivery.yaml new file mode 100644 index 0000000000..dd51149415 --- /dev/null +++ b/delivery.yaml @@ -0,0 +1,18 @@ +build_steps: +- desc: Install docker + cmd: | + apt-get update + apt-get install -y apt-transport-https ca-certificates curl software-properties-common + curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - + add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" + apt-get update + apt-get install -y docker-ce +- desc: Build and push docker image + cmd: | + image=registry-write.opensource.zalan.do/teapot/external-dns:$(git describe --always --dirty --tags) + docker build --tag $image . + IS_PR_BUILD=${CDP_PULL_REQUEST_NUMBER+"true"} + if [[ ${CDP_TARGET_BRANCH} == "master" && ${IS_PR_BUILD} != "true" ]] + then + docker push $image + fi