diff --git a/0.X/Makefile b/0.X/Makefile index 2ac0193..ae59895 100644 --- a/0.X/Makefile +++ b/0.X/Makefile @@ -1,16 +1,18 @@ -REGISTRY_NAME?=docker.io/hashicorp -VERSION=1.7.0 -IMAGE_TAG_ENT=$(REGISTRY_NAME)/vault-enterprise:$(VERSION)_ent -IMAGE_TAG_OSS=$(REGISTRY_NAME)/vault:$(VERSION) +export REGISTRY_NAME?=docker.io/hashicorp +export VERSION=1.7.0 .PHONY: build ent-image oss-image build: ent-image oss-image +ent-image: export PROJECT_NAME=vault-enterprise +ent-image: export TAG_SUFFIX=_ent ent-image: - docker build --build-arg VAULT_VERSION=$(VERSION)+ent --no-cache -t $(IMAGE_TAG_ENT) . - docker tag $(IMAGE_TAG_ENT) $(REGISTRY_NAME)/vault-enterprise:latest + docker build --label version=$(VERSION) --build-arg VAULT_VERSION=$(VERSION)+ent --no-cache -t $(REGISTRY_NAME)/$(PROJECT_NAME):$(VERSION)$(TAG_SUFFIX) . + @../scripts/tag-images.sh +oss-image: export PROJECT_NAME=vault oss-image: - docker build --build-arg VAULT_VERSION=$(VERSION) --no-cache -t $(IMAGE_TAG_OSS) . - docker tag $(IMAGE_TAG_OSS) $(REGISTRY_NAME)/vault:latest + docker build --label version=$(VERSION) --build-arg VAULT_VERSION=$(VERSION) --no-cache -t $(REGISTRY_NAME)/$(PROJECT_NAME):$(VERSION) . + @../scripts/tag-images.sh + diff --git a/scripts/tag-images.sh b/scripts/tag-images.sh new file mode 100755 index 0000000..d52bc90 --- /dev/null +++ b/scripts/tag-images.sh @@ -0,0 +1,61 @@ +#!/bin/bash + +# * VERSION - Image version to tag i.e 1.7.0 or 1.7.0- +# * REGISTRY_NAME - Docker Registry Name i.e docker.io/hashicorp +# * PROJECT_NAME - Project name i.e vault or vault-enterprise + +# Introspects the docker label of an container to see what version 'latest' is +function get_latest_docker_version() { + # Arguments: + # $1 - Docker Org + # $2 - Docker Image Name + # + # + # Returns: + # 0 - success (version in the 'latest' container echoed) + # 1 - 'latest' tag does not exist or label could not be found + + docker pull "$1"/"$2":latest + local docker_latest=$(docker inspect --format="{{ index .Config.Labels.version }}" "$1"/"$2":latest) + if [ -z "$docker_latest" ]; then + return 1 + else + echo "$docker_latest" + return 0 + fi +} + +# Calculates the higher of two versions +function higher_version() { + # Arguments: + # $1 - first version to compare + # $2 - second version to compare + # + # Returns: + # higher version of two arguments + + higher_version=$(echo -e "$1\n$2" | sort -rV | head -n 1) + echo "$higher_version" +} + +# If this is not a pre-release, we determine if any of the 'latest' images need to be updated +function main() { + + : "${VERSION?"Need to set VERSION"}" + + : "${REGISTRY_NAME?"Need to set REGISTRY_NAME"}" + + : "${PROJECT_NAME?"Need to set PROJECT_NAME"}" + + DOCKER_TAG="$VERSION$TAG_SUFFIX" + + if [[ "${VERSION}" =~ [0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "Tagging a new latest docker image" + docker tag "$REGISTRY_NAME"/"$PROJECT_NAME":"$DOCKER_TAG" "$REGISTRY_NAME"/"$PROJECT_NAME":latest || return 1 + fi + # If it is a prerelease, we don't tag latest so we do nothing here + + return 0 +} +main "$@" +exit $? diff --git a/ubi/Makefile b/ubi/Makefile index 776f7ab..3635592 100644 --- a/ubi/Makefile +++ b/ubi/Makefile @@ -1,16 +1,20 @@ -REGISTRY_NAME?=docker.io/hashicorp -VERSION=1.7.0 -IMAGE_TAG_ENT=$(REGISTRY_NAME)/vault-enterprise:$(VERSION)-ubi-ent -IMAGE_TAG_OSS=$(REGISTRY_NAME)/vault:$(VERSION)-ubi +export REGISTRY_NAME?=docker.io/hashicorp +export VERSION=1.7.0 .PHONY: build ent-image oss-image build: ent-image oss-image +ent-image: export PROJECT_NAME=vault-enterprise +ent-image: export TAG_SUFFIX=-ubi-ent ent-image: - docker build --build-arg VAULT_VERSION=$(VERSION)+ent --no-cache -t $(IMAGE_TAG_ENT) . + docker build --label version=$(VERSION) --build-arg VAULT_VERSION=$(VERSION)+ent --no-cache -t $(REGISTRY_NAME)/$(PROJECT_NAME):$(VERSION)$(TAG_SUFFIX) . docker tag $(IMAGE_TAG_ENT) $(REGISTRY_NAME)/vault-enterprise:latest + @../scripts/tag-images.sh +oss-image: export PROJECT_NAME=vault +oss-image: export TAG_SUFFIX=-ubi oss-image: - docker build --build-arg VAULT_VERSION=$(VERSION) --no-cache -t $(IMAGE_TAG_OSS) . + docker build --label version=$(VERSION) --build-arg VAULT_VERSION=$(VERSION) --no-cache -t $(REGISTRY_NAME)/$(PROJECT_NAME):$(VERSION)$(TAG_SUFFIX) . docker tag $(IMAGE_TAG_OSS) $(REGISTRY_NAME)/vault:latest + @../scripts/tag-images.sh \ No newline at end of file