Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(packaging/docker): Support multiple architectures #762

Merged
merged 22 commits into from
Aug 1, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore(packaging): master tagging
Contrary to what has been done before, this reverts to something close to the
old behavior:

If a git tag is built, the name of the tag is used as the docker tag.
If the master branch is built, it is tagged as master-SHA, master and latest

If a regular branch is built, it is not pushed.
  • Loading branch information
sh0rez committed Aug 1, 2019
commit 20f4ce8562bc4a0eaadd8bf12a98b10802383374
55 changes: 21 additions & 34 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ BUILD_IMAGE_VERSION := 0.2.1

# Docker image info
IMAGE_PREFIX ?= grafana
IMAGE_TAG := $(shell ./tools/image-tag)

IMAGE_TAG := $(shell git describe --exact-match 2> /dev/null || git rev-parse --abbrev-ref HEAD)

# Version info for binaries
GIT_REVISION := $(shell git rev-parse --short HEAD)
Expand Down Expand Up @@ -79,9 +80,11 @@ BUILD_IMAGE = BUILD_IMAGE=$(IMAGE_PREFIX)/loki-build-image:$(BUILD_IMAGE_VERSION
ifeq ($(CI), true)
BUILD_OCI=img build --no-console $(OCI_PLATFORMS) --build-arg $(BUILD_IMAGE)
PUSH_OCI=img push
TAG_OCI=img tag
else
BUILD_OCI=docker build --build-arg $(BUILD_IMAGE)
PUSH_OCI=img push
PUSH_OCI=docker push
TAG_OCI=docker tag
endif

binfmt:
Expand Down Expand Up @@ -315,36 +318,20 @@ images: promtail-image loki-image loki-canary-image docker-driver

IMAGE_NAMES := grafana/loki grafana/promtail grafana/loki-canary

save-images:
@set -e; \
mkdir -p images; \
for image_name in $(IMAGE_NAMES); do \
echo ">> saving image $$image_name:$(IMAGE_TAG)"; \
docker save $$image_name:$(IMAGE_TAG) -o images/$$(echo $$image_name | tr "/" _):$(IMAGE_TAG); \
done

load-images:
@set -e; \
mkdir -p images; \
for image_name in $(IMAGE_NAMES); do \
docker load -i images/$$(echo $$image_name | tr "/" _):$(IMAGE_TAG); \
done

push-images:
@set -e; \
for image_name in $(IMAGE_NAMES); do \
docker push $$image_name:$(IMAGE_TAG); \
done

push-latest:
@set -e; \
for image_name in $(IMAGE_NAMES); do \
docker tag $$image_name:$(IMAGE_TAG) $$image_name:latest; \
docker tag $$image_name:$(IMAGE_TAG) $$image_name:master; \
docker push $$image_name:latest; \
docker push $$image_name:master; \
done

# push(app, optional tag)
# pushes the app, optionally tagging it differently before
define push
$(SUDO) $(TAG_OCI) $(IMAGE_PREFIX)/$(1):$(IMAGE_TAG) $(IMAGE_PREFIX)/$(1):$(if $(2),$(2),$(IMAGE_TAG))
$(SUDO) $(PUSH_OCI) $(IMAGE_PREFIX)/$(1):$(if $(2),$(2),$(IMAGE_TAG))
endef

# push-image(app)
# pushes the app, if branch==master also as :latest and :master
define push-image
$(call push,$(1))
$(if $(filter $(GIT_BRANCH),master), $(call push,promtail,master))
$(if $(filter $(GIT_BRANCH),master), $(call push,promtail,latest))
endef

# promtail
promtail-image:
Expand All @@ -355,7 +342,7 @@ promtail-debug-image:
$(SUDO) $(BUILD_OCI) -t $(IMAGE_PREFIX)/promtail:$(IMAGE_TAG)-debug -f cmd/promtail/Dockerfile.debug .

promtail-push: promtail-image
$(SUDO) $(PUSH_OCI) $(IMAGE_PREFIX)/promtail:$(IMAGE_TAG)
$(call push-image,promtail)

# loki
loki-image:
Expand All @@ -366,7 +353,7 @@ loki-debug-image:
$(SUDO) $(BUILD_OCI) -t $(IMAGE_PREFIX)/loki:$(IMAGE_TAG)-debug -f cmd/loki/Dockerfile.debug .

loki-push: loki-image
$(SUDO) $(PUSH_OCI) $(IMAGE_PREFIX)/loki:$(IMAGE_TAG)
$(call push-image,loki)

# loki-canary
loki-canary-image:
Expand Down
8 changes: 5 additions & 3 deletions tools/image-tag
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ set -o errexit
set -o nounset
set -o pipefail

WORKING_SUFFIX=$(if git status --porcelain | grep -qE '^(?:[^?][^ ]|[^ ][^?])\s'; then echo "-WIP"; else echo ""; fi)
BRANCH_PREFIX=$(git rev-parse --abbrev-ref HEAD)
echo "${BRANCH_PREFIX//\//-}-$(git rev-parse --short HEAD)$WORKING_SUFFIX"
BRANCH=$(git rev-parse --abbrev-ref HEAD)
SHA=$(git rev-parse --short HEAD)

# If this is a tag, use it, otherwise branch-hash
git describe --exact-match 2> /dev/null || echo "${BRANCH}-${SHA}"