Skip to content

Commit fe540ae

Browse files
authored
Properly calculate image tag in GitHub Actions (#3423)
Signed-off-by: Chris Marchbanks <[email protected]>
1 parent df64c73 commit fe540ae

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

.github/workflows/test-build-deploy.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,13 @@ jobs:
142142
- name: Integration Tests
143143
run: |
144144
export CORTEX_IMAGE_PREFIX="${IMAGE_PREFIX:-quay.io/cortexproject/}"
145-
export CORTEX_IMAGE="${CORTEX_IMAGE_PREFIX}cortex:${TAG:-$(./tools/image-tag)}"
145+
export IMAGE_TAG=$(make image-tag)
146+
export CORTEX_IMAGE="${CORTEX_IMAGE_PREFIX}cortex:$IMAGE_TAG"
146147
export CORTEX_CHECKOUT_DIR="/go/src/github.com/cortexproject/cortex"
147148
echo "Running integration tests with image: $CORTEX_IMAGE"
148149
go test -tags=requires_docker -timeout 1800s -v -count=1 ./integration/...
149150
env:
150151
IMAGE_PREFIX: ${{ secrets.IMAGE_PREFIX }}
151-
TAG: ${{ github.event.push.tag_name }}
152152

153153
integration-configs-db:
154154
needs: build
@@ -241,11 +241,11 @@ jobs:
241241
if [ -n "$QUAY_REGISTRY_PASSWORD" ]; then
242242
docker login -u "$QUAY_REGISTRY_USER" -p "$QUAY_REGISTRY_PASSWORD" quay.io;
243243
fi
244-
IMAGE_TAG=$GIT_TAG ./push-images $NOQUAY
244+
export IMAGE_TAG=$(make image-tag)
245+
./push-images $NOQUAY
245246
env:
246247
DOCKER_REGISTRY_USER: ${{secrets.DOCKER_REGISTRY_USER}}
247248
DOCKER_REGISTRY_PASSWORD: ${{ secrets.DOCKER_REGISTRY_PASSWORD }}
248249
QUAY_REGISTRY_USER: ${{secrets.QUAY_REGISTRY_USER}}
249250
QUAY_REGISTRY_PASSWORD: ${{secrets.QUAY_REGISTRY_PASSWORD}}
250-
GIT_TAG: ${{github.event.release.tag_name}}
251251
NOQUAY: ${{secrets.NOQUAY}}

Makefile

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,26 @@ GOPROXY_VALUE=$(shell go env GOPROXY)
1212
# Boiler plate for building Docker containers.
1313
# All this must go at top of file I'm afraid.
1414
IMAGE_PREFIX ?= quay.io/cortexproject/
15-
# Use CIRCLE_TAG if present for releases.
16-
IMAGE_TAG ?= $(if $(CIRCLE_TAG),$(CIRCLE_TAG),$(shell ./tools/image-tag))
15+
16+
# For a tag push GITHUB_REF will look like refs/tags/<tag_name>,
17+
# If finding refs/tags/ does not equal emptystring then use
18+
# the tag we are at as the image tag.
19+
ifneq (,$(findstring refs/tags/, $(GITHUB_REF)))
20+
GIT_TAG := $(shell git tag --points-at HEAD)
21+
endif
22+
# Keep circle-ci compatability for now.
23+
ifdef CIRCLE_TAG
24+
GIT_TAG := $(CIRCLE_TAG)
25+
endif
26+
IMAGE_TAG ?= $(if $(GIT_TAG),$(GIT_TAG),$(shell ./tools/image-tag))
1727
GIT_REVISION := $(shell git rev-parse --short HEAD)
1828
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
1929
UPTODATE := .uptodate
2030

31+
.PHONY: image-tag
32+
image-tag:
33+
@echo $(IMAGE_TAG)
34+
2135
# Support gsed on OSX (installed via brew), falling back to sed. On Linux
2236
# systems gsed won't be installed, so will use sed as expected.
2337
SED ?= $(shell which gsed 2>/dev/null || which sed)

0 commit comments

Comments
 (0)