From c852fa6598f9de7028ce3a77aa60bff032b73b75 Mon Sep 17 00:00:00 2001 From: Tom Denham Date: Fri, 19 Aug 2016 14:21:01 -0700 Subject: [PATCH] Pass through version into build container Fixes #147 --- Dockerfile | 4 +++- Makefile | 8 +++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1a71e4be2..7c62aeabc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,6 +6,8 @@ ENV GOPATH /go ENV PATH $GOPATH/bin:/usr/local/go/bin:/opt/cni/bin:$PATH RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH" RUN mkdir -p /opt/cni/bin +ARG CALICO_CNI_VERSION +ENV CALICO_CNI_VERSION ${CALICO_CNI_VERSION} # Add source files. ADD glide.yaml glide.lock Makefile /go/src/github.com/projectcalico/calico-cni/ @@ -29,7 +31,7 @@ RUN set -ex \ make \ && go get -u github.com/Masterminds/glide \ && cd /go/src/github.com/projectcalico/calico-cni \ - && make binary \ + && make binary CALICO_CNI_VERSION=$CALICO_CNI_VERSION \ && mv dist/calico* /opt/cni/bin \ && rm -rf /go /root/.glide \ && apk del .build-deps diff --git a/Makefile b/Makefile index 987b8e08b..eed30a5b0 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,8 @@ LOCAL_IP_ENV?=$(shell ip route get 8.8.8.8 | head -1 | cut -d' ' -f8) K8S_VERSION=1.3.1 CALICO_NODE_VERSION=0.20.0 +CALICO_CNI_VERSION?=$(shell git describe --tags --dirty) + # Ensure that the dist directory is always created MAKE_SURE_DIST_EXIST := $(shell mkdir -p dist) @@ -33,12 +35,12 @@ vendor: # Build the Calico network plugin dist/calico: $(SRCFILES) vendor CGO_ENABLED=0 go build -v -o dist/calico \ - -ldflags "-X main.VERSION=$(shell git describe --tags --dirty)" calico.go; + -ldflags "-X main.VERSION=$(CALICO_CNI_VERSION)" calico.go; # Build the Calico ipam plugin dist/calico-ipam: $(SRCFILES) vendor CGO_ENABLED=0 go build -v -o dist/calico-ipam \ - -ldflags "-X main.VERSION=$(shell git describe --tags --dirty)" ipam/calico-ipam.go; + -ldflags "-X main.VERSION=$(CALICO_CNI_VERSION)" ipam/calico-ipam.go; .PHONY: test # Run the unit tests. @@ -56,7 +58,7 @@ $(BUILD_CONTAINER_MARKER): Dockerfile.build touch $@ $(DEPLOY_CONTAINER_MARKER): Dockerfile - docker build -f Dockerfile -t $(DEPLOY_CONTAINER_NAME) . + docker build -f Dockerfile --build-arg CALICO_CNI_VERSION=$(CALICO_CNI_VERSION) -t $(DEPLOY_CONTAINER_NAME) . touch $@ # Run the tests in a container. Useful for CI