diff --git a/components/packaging/deb/Makefile b/components/packaging/deb/Makefile index 200b710102..d42b1b8bec 100644 --- a/components/packaging/deb/Makefile +++ b/components/packaging/deb/Makefile @@ -4,6 +4,7 @@ ENGINE_DIR:=$(CURDIR)/../../engine CLI_DIR:=$(CURDIR)/../../cli GITCOMMIT?=$(shell cd $(ENGINE_DIR) && git rev-parse --short HEAD) VERSION?=0.0.0-dev +DEB_VERSION=$(shell ./gen-deb-ver $(ENGINE_DIR) $(VERSION)) DOCKER_EXPERIMENTAL:=0 CHOWN:=docker run --rm -v $(CURDIR):/v -w /v alpine chown @@ -32,6 +33,7 @@ raspbian: raspbian-stretch debian-jessie ## build all raspbian deb packages ubuntu-xenial: ## build ubuntu xenial deb packages docker build -t debbuild-$@/$(ARCH) -f $(CURDIR)/$@/Dockerfile.$(ARCH) . docker run --rm -i \ + -e DEB_VERSION=$(DEB_VERSION) \ -e VERSION=$(VERSION) \ -e DOCKER_GITCOMMIT=$(GITCOMMIT) \ -v $(CURDIR)/debbuild/$@:/build \ @@ -45,6 +47,7 @@ ubuntu-xenial: ## build ubuntu xenial deb packages ubuntu-trusty: ## build ubuntu trusty deb packages docker build -t debbuild-$@/$(ARCH) -f $(CURDIR)/$@/Dockerfile.$(ARCH) . docker run --rm -i \ + -e DEB_VERSION=$(DEB_VERSION) \ -e VERSION=$(VERSION) \ -e DOCKER_GITCOMMIT=$(GITCOMMIT) \ -v $(CURDIR)/debbuild/$@:/build \ @@ -58,6 +61,7 @@ ubuntu-trusty: ## build ubuntu trusty deb packages ubuntu-artful: ## build ubuntu artful deb packages docker build -t debbuild-$@/$(ARCH) -f $(CURDIR)/$@/Dockerfile.$(ARCH) . docker run --rm -i \ + -e DEB_VERSION=$(DEB_VERSION) \ -e VERSION=$(VERSION) \ -e DOCKER_GITCOMMIT=$(GITCOMMIT) \ -v $(CURDIR)/debbuild/$@:/build \ @@ -71,6 +75,7 @@ ubuntu-artful: ## build ubuntu artful deb packages debian-buster: ## build debian buster deb packages docker build -t debbuild-$@/$(ARCH) -f $(CURDIR)/$@/Dockerfile.$(ARCH) . docker run --rm -i \ + -e DEB_VERSION=$(DEB_VERSION) \ -e VERSION=$(VERSION) \ -e DOCKER_GITCOMMIT=$(GITCOMMIT) \ -v $(CURDIR)/debbuild/$@:/build \ @@ -84,6 +89,7 @@ debian-buster: ## build debian buster deb packages debian-jessie: ## build debian jessie deb packages docker build -t debbuild-$@/$(ARCH) -f $(CURDIR)/$@/Dockerfile.$(ARCH) . docker run --rm -i \ + -e DEB_VERSION=$(DEB_VERSION) \ -e VERSION=$(VERSION) \ -e DOCKER_GITCOMMIT=$(GITCOMMIT) \ -v $(CURDIR)/debbuild/$@:/build \ @@ -97,6 +103,7 @@ debian-jessie: ## build debian jessie deb packages debian-stretch: ## build debian stretch deb packages docker build -t debbuild-$@/$(ARCH) -f $(CURDIR)/$@/Dockerfile.$(ARCH) . docker run --rm -i \ + -e DEB_VERSION=$(DEB_VERSION) \ -e VERSION=$(VERSION) \ -e DOCKER_GITCOMMIT=$(GITCOMMIT) \ -v $(CURDIR)/debbuild/$@:/build \ @@ -110,6 +117,7 @@ debian-stretch: ## build debian stretch deb packages debian-wheezy: ## build debian wheezy deb packages docker build -t debbuild-$@/$(ARCH) -f $(CURDIR)/$@/Dockerfile.$(ARCH) . docker run --rm -i \ + -e DEB_VERSION=$(DEB_VERSION) \ -e VERSION=$(VERSION) \ -e DOCKER_GITCOMMIT=$(GITCOMMIT) \ -v $(CURDIR)/debbuild/$@:/build \ @@ -123,6 +131,7 @@ debian-wheezy: ## build debian wheezy deb packages raspbian-jessie: ## build raspbian jessie deb packages docker build -t debbuild-$@/$(ARCH) -f $(CURDIR)/$@/Dockerfile.$(ARCH) . docker run --rm -i \ + -e DEB_VERSION=$(DEB_VERSION) \ -e VERSION=$(VERSION) \ -e DOCKER_GITCOMMIT=$(GITCOMMIT) \ -v $(CURDIR)/debbuild/$@:/build \ @@ -136,6 +145,7 @@ raspbian-jessie: ## build raspbian jessie deb packages raspbian-stretch: ## build raspbian stretch deb packages docker build -t debbuild-$@/$(ARCH) -f $(CURDIR)/$@/Dockerfile.$(ARCH) . docker run --rm -i \ + -e DEB_VERSION=$(DEB_VERSION) \ -e VERSION=$(VERSION) \ -e DOCKER_GITCOMMIT=$(GITCOMMIT) \ -v $(CURDIR)/debbuild/$@:/build \ diff --git a/components/packaging/deb/build-deb b/components/packaging/deb/build-deb index 713489bad5..179c2b088d 100755 --- a/components/packaging/deb/build-deb +++ b/components/packaging/deb/build-deb @@ -1,6 +1,12 @@ #!/usr/bin/env bash set -x set -e + +if [[ -z "$DEB_VERSION" ]]; then + echo "DEB_VERSION is required to build deb packages" + exit 1 +fi + # I want to rip this install-binaries script out so badly cd engine TMP_GOPATH="/go" bash hack/dockerfile/install-binaries.sh runc-dynamic containerd-dynamic proxy-dynamic tini @@ -15,36 +21,13 @@ echo VERSION AAA $VERSION VERSION=${VERSION:-$( cat engine/VERSION )} echo VERSION bbb $VERSION -export TZ=UTC -tilde='~' # ouch Bash 4.2 vs 4.3, you keel me -# git running in different directories, backwards compatible too -GIT_COMMAND="git --git-dir=/root/build-deb/engine/.git --work-tree=/root/build-deb/engine/" -debVersion="${VERSION//-/$tilde}" # using \~ or '~' here works in 4.3, but not 4.2; just ~ causes $HOME to be inserted, hence the $tilde -# if we have a "-dev" suffix or have change in Git, let's make this package version more complex so it works better -if [[ "$VERSION" == *-dev ]]; then - # TODO: Re-introduce git commit time into version number - todaysDate="$(date +'%Y%m%d.%H%M%S')" - # We're guaranteed to have DOCKER_GITCOMMIT in the env - gitVersion="git${todaysDate}.0.${DOCKER_GITCOMMIT}" - # gitVersion is now something like 'git20150128.112847.0.17e840a' - debVersion="$debVersion~$gitVersion" - - # $ dpkg --compare-versions 1.5.0 gt 1.5.0~rc1 && echo true || echo false - # true - # $ dpkg --compare-versions 1.5.0~rc1 gt 1.5.0~git20150128.112847.17e840a && echo true || echo false - # true - # $ dpkg --compare-versions 1.5.0~git20150128.112847.17e840a gt 1.5.0~dev~git20150128.112847.17e840a && echo true || echo false - # true - - # ie, 1.5.0 > 1.5.0~rc1 > 1.5.0~git20150128.112847.17e840a > 1.5.0~dev~git20150128.112847.17e840a -fi debSource="$(awk -F ': ' '$1 == "Source" { print $2; exit }' debian/control)" debMaintainer="$(awk -F ': ' '$1 == "Maintainer" { print $2; exit }' debian/control)" debDate="$(date --rfc-2822)" cat > "debian/changelog" <<-EOF -$debSource (${debVersion}-0~${DISTRO}) $SUITE; urgency=low +$debSource (${DEB_VERSION}-0~${DISTRO}) $SUITE; urgency=low * Version: $VERSION -- $debMaintainer $debDate EOF diff --git a/components/packaging/deb/gen-deb-ver b/components/packaging/deb/gen-deb-ver new file mode 100755 index 0000000000..2ea9f94b87 --- /dev/null +++ b/components/packaging/deb/gen-deb-ver @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +ENGINE_DIR="$1" +VERSION="$2" + +[[ $# < 2 ]] && echo 'not enough args' && exit 1 + +DATE_COMMAND="date" +if [[ $(uname) -eq "Darwin" ]]; then + DATE_COMMAND="docker run --rm alpine date" +fi + +TZ=UTC + +tilde='~' # ouch Bash 4.2 vs 4.3, you keel me +# git running in different directories, backwards compatible too +GIT_COMMAND="git -C $ENGINE_DIR" +debVersion="${VERSION//-/$tilde}" # using \~ or '~' here works in 4.3, but not 4.2; just ~ causes $HOME to be inserted, hence the $tilde +# if we have a "-dev" suffix or have change in Git, let's make this package version more complex so it works better +if [[ "$VERSION" == *-dev ]]; then + gitUnix="$($GIT_COMMAND log -1 --pretty='%at')" + gitDate="$($DATE_COMMAND --date "@$gitUnix" +'%Y%m%d.%H%M%S')" + gitCommit="$($GIT_COMMAND log -1 --pretty='%h')" + gitVersion="git${gitDate}.0.${gitCommit}" + debVersion="$debVersion~$gitVersion" + + # $ dpkg --compare-versions 1.5.0 gt 1.5.0~rc1 && echo true || echo false + # true + # $ dpkg --compare-versions 1.5.0~rc1 gt 1.5.0~git20150128.112847.17e840a && echo true || echo false + # true + # $ dpkg --compare-versions 1.5.0~git20150128.112847.17e840a gt 1.5.0~dev~git20150128.112847.17e840a && echo true || echo false + # true + + # ie, 1.5.0 > 1.5.0~rc1 > 1.5.0~git20150128.112847.17e840a > 1.5.0~dev~git20150128.112847.17e840a +fi + +echo "$debVersion"