From 1ebd8777a8bd3444b9ca47e3af4ef8950c066c3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20K=C3=A4ldstr=C3=B6m?= Date: Fri, 31 May 2019 21:23:29 +0300 Subject: [PATCH] Rework the build system to set the firecracker version only in one place, and make the image name reference the fc version --- Dockerfile | 6 +++--- Makefile | 13 ++++++++----- cmd/ignite/run/start.go | 3 ++- hack/FIRECRACKER_VERSION | 1 + hack/ldflags.sh | 4 ++++ pkg/version/version.go | 5 ++--- 6 files changed, 20 insertions(+), 12 deletions(-) create mode 100644 hack/FIRECRACKER_VERSION diff --git a/Dockerfile b/Dockerfile index 87fd2803b..021fb22ef 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,8 +4,8 @@ RUN apk add --no-cache iproute2 VOLUME /var/lib/firecracker -ARG FIRECRACKER_VERSION=v0.16.0 -ADD https://github.com/firecracker-microvm/firecracker/releases/download/${FIRECRACKER_VERSION}/firecracker /ignite/firecracker +ARG FIRECRACKER_VERSION +ADD https://github.com/firecracker-microvm/firecracker/releases/download/${FIRECRACKER_VERSION}/firecracker-${FIRECRACKER_VERSION} /ignite/firecracker # The ignite binary should be bind-mounted over /ignite/ignite RUN touch /ignite/ignite && \ @@ -13,4 +13,4 @@ RUN touch /ignite/ignite && \ ln -s /ignite/firecracker /usr/local/bin/firecracker && \ ln -s /ignite/ignite /usr/local/bin/ignite -ENTRYPOINT ["/ignite/ignite", "container"] \ No newline at end of file +ENTRYPOINT ["/ignite/ignite", "container"] diff --git a/Makefile b/Makefile index 783de475b..51e64fdad 100644 --- a/Makefile +++ b/Makefile @@ -1,16 +1,19 @@ UID_GID?=$(shell id -u):$(shell id -g) +FIRECRACKER_VERSION:=$(shell cat hack/FIRECRACKER_VERSION) +GO_VERSION=1.12 all: binary -build: - docker build -t ignite . - binary: - docker run -it --rm -v $(shell pwd):/build -w /build golang:1.12 sh -c "\ + docker run -it --rm -v $(shell pwd):/build -w /build golang:${GO_VERSION} sh -c "\ make ignite && \ chown ${UID_GID} bin/ignite" +# Make make execute this target although the file already exists. +.PHONY: bin/ignite ignite: bin/ignite bin/ignite: CGO_ENABLED=0 go build -mod=vendor -ldflags "$(shell ./hack/ldflags.sh)" -o bin/ignite ./cmd/ignite -.PHONY: bin/ignite +image: + docker build -t weaveworks/ignite:${FIRECRACKER_VERSION} \ + --build-arg FIRECRACKER_VERSION=${FIRECRACKER_VERSION} . diff --git a/cmd/ignite/run/start.go b/cmd/ignite/run/start.go index 353e022f9..f99c3fe57 100644 --- a/cmd/ignite/run/start.go +++ b/cmd/ignite/run/start.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/luxas/ignite/pkg/constants" "github.com/luxas/ignite/pkg/util" + "github.com/luxas/ignite/pkg/version" "os" "path/filepath" ) @@ -32,7 +33,7 @@ func Start(so *StartOptions) error { fmt.Sprintf("--stop-timeout=%d", constants.STOP_TIMEOUT+constants.IGNITE_TIMEOUT), "--privileged", "--device=/dev/kvm", - "ignite", + "weaveworks/ignite:"+version.GetFirecracker().String(), so.VM.ID, } diff --git a/hack/FIRECRACKER_VERSION b/hack/FIRECRACKER_VERSION new file mode 100644 index 000000000..49dd460a9 --- /dev/null +++ b/hack/FIRECRACKER_VERSION @@ -0,0 +1 @@ +v0.16.0 \ No newline at end of file diff --git a/hack/ldflags.sh b/hack/ldflags.sh index 7f7754713..b5a8e42fa 100755 --- a/hack/ldflags.sh +++ b/hack/ldflags.sh @@ -72,6 +72,10 @@ ldflags() { ) fi + # Set the desired Firecracker version + SCRIPT_DIR=$( dirname "${BASH_SOURCE[0]}" ) + ldflags+=($(ldflag "firecrackerVersion" "$(cat ${SCRIPT_DIR}/FIRECRACKER_VERSION)")) + # The -ldflags parameter takes a single string, so join the output. echo "${ldflags[*]-}" } diff --git a/pkg/version/version.go b/pkg/version/version.go index 4355328a4..8f7ba03da 100644 --- a/pkg/version/version.go +++ b/pkg/version/version.go @@ -12,6 +12,7 @@ var ( gitCommit = "" gitTreeState = "" buildDate = "" + firecrackerVersion = "" ) // Info stores information about a component's version @@ -50,8 +51,6 @@ func GetIgnite() Info { // GetFirecracker returns firecracker's version func GetFirecracker() Info { return Info{ - Major: "0", - Minor: "16", - GitVersion: "v0.16.0", + GitVersion: firecrackerVersion, } }