-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
51 lines (42 loc) · 1.7 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# Don't print executed commands as they include the GitHub Package key
.SILENT:
# ==============================================================================
# Configuration
# ==============================================================================
DOCKER_IMAGE := ghcr.io/apiaframework/docs-generator
DOCKER_BUILD_CMD = docker build $(DOCKER_BUILD_ARGS) .
# ==============================================================================
# Main Targets
# ==============================================================================
# image ID within the targets by running the build again with the -q option. The
# second run with the -q option will be very fast thanks to layer caching.
.PHONY: docker-build
docker-build:
$(DOCKER_BUILD_CMD)
# ==============================================================================
# Release
# ==============================================================================
DOCKER_TAG_NAME ?= $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null)
DOCKER_TAG_VERSION ?= $(shell git describe --tags --exact-match 2>/dev/null)
ifeq ($(DOCKER_TAG_NAME),master)
DOCKER_TAG_NAME = latest
endif
ifeq ($(DOCKER_TAG_NAME),main)
DOCKER_TAG_NAME = latest
endif
.PHONY: docker-image
docker-image: docker-build
$(eval IMAGE := $(shell $(DOCKER_BUILD_CMD) -q))
ifeq ($(DOCKER_TAG_NAME),latest)
docker tag "$(IMAGE)" "$(DOCKER_IMAGE):$(DOCKER_TAG_NAME)"
endif
.PHONY: docker-release
docker-release: docker-image
ifeq ($(DOCKER_TAG_NAME),latest)
docker push "$(DOCKER_IMAGE):$(DOCKER_TAG_NAME)"
endif
ifneq ($(DOCKER_TAG_VERSION),)
docker tag "$(DOCKER_IMAGE):$(DOCKER_TAG_NAME)" \
"$(DOCKER_IMAGE):$(DOCKER_TAG_VERSION)" && \
docker push "$(DOCKER_IMAGE):$(DOCKER_TAG_VERSION)"
endif