generated from pre-cursor/github-template-repository-basic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
65 lines (53 loc) · 1.84 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
VERSION:=$(shell semtag final -s minor -o)
# Git version information
GIT_COMMIT ?= $(shell git rev-parse --short HEAD)
GIT_DESCRIBE ?= $(shell git describe --tags --always --match "v*")
GIT_DIRTY=$(shell test -n "`git status --porcelain`" && echo "+CHANGES" || true)
VERSION_LABEL=$(shell semtag getlast | cut -c 2-)
# Docker image information
REGISTRY_NAME?=docker.io/acme
IMAGE_NAME=hello-world
IMAGE_TAG=$(REGISTRY_NAME)/$(IMAGE_NAME):$(VERSION)
#:help: help | Displays the GNU makefile help
.PHONY: help
help: ; @sed -n 's/^#:help://p' Makefile
#:help: all | Builds the Docker image and publishes it
.PHONY: all
all: build publish
#:help: build | Builds the Docker image
.PHONY: build
build:
@docker build --build-arg VERSION=$(VERSION_LABEL) --no-cache -t $(REGISTRY_NAME)/$(IMAGE_NAME):$(GIT_COMMIT) .
#:help: changelog | Build the changelog
.PHONY: changelog
changelog:
@git-chglog -o CHANGELOG.md --next-tag $(VERSION)
@git add CHANGELOG.md && git commit -m "Updated CHANGELOG"
@git push
#:help: clean | Cleans the Docker
.PHONY: clean
clean:
@rm -f $(NAME).tar
#:help: precommit | Lint the project files using pre-commit
.PHONY: precommit
precommit:
@pre-commit run --all-files
#:help: publish | Publishes the Docker image
.PHONY: publish
publish:
@docker build --build-arg VERSION=$(VERSION_LABEL) --no-cache -t $(IMAGE_TAG) .
@docker tag $(IMAGE_TAG) $(REGISTRY_NAME)/$(IMAGE_NAME):latest
@docker push $(IMAGE_TAG)
#:help: release | Release the product, setting the tag and pushing.
.PHONY: release
release:
@semtag final -s minor
@git push --follow-tags
#:help: load | Loads the Docker image from a tar-file
.PHONY: load
load:
@docker load < $(IMAGE_NAME).tar
#:help: save | Saves the Docker image to a tar-file
.PHONY: save
save:
@docker save $(REGISTRY_NAME)/$(IMAGE_NAME) > $(IMAGE_NAME).tar