-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
70 lines (60 loc) · 2.64 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
66
67
68
69
70
#-include $(shell curl -sSL -o .build-harness "https://git.io/build-harness"; echo .build-harness)
### Git ###
ifneq ($(strip $(shell git status --porcelain 2>/dev/null)),)
IS_DIRTY = -dirty
endif
#CI_PROJECT_URL ?=
CI_PROJECT_NAME ?= $(shell basename $(PWD))
CI_COMMIT_SHA ?= $(shell git rev-parse --short HEAD)$(IS_DIRTY)
CI_COMMIT_TAG ?= $(shell git describe --abbrev=0 --tags 2>/dev/null)
ifneq ("$(CI_COMMIT_TAG)","")
TAG_REV = $(shell git rev-list -n 1 $(CI_COMMIT_TAG))
COUNT_SINCE_TAG = $(shell git rev-list `git describe --abbrev=0 --tags`..HEAD --count)
endif
GITREMOTE := $(shell git config --get remote.origin.url)
GITPROT := $(shell echo "$(GITREMOTE)" | sed -r "s|((.*)(\:\/\/))?((.*)\@)?([^\/:]*)(\:([0-9]+))?[:\/](.*)(\.git)|\2|")
GITUSER := $(shell echo "$(GITREMOTE)" | sed -r "s|((.*)(\:\/\/))?((.*)\@)?([^\/:]*)(\:([0-9]+))?[:\/](.*)(\.git)|\5|")
GITHOST := $(shell echo "$(GITREMOTE)" | sed -r "s|((.*)(\:\/\/))?((.*)\@)?([^\/:]*)(\:([0-9]+))?[:\/](.*)(\.git)|\6|")
GITPORT := $(shell echo "$(GITREMOTE)" | sed -r "s|((.*)(\:\/\/))?((.*)\@)?([^\/:]*)(\:([0-9]+))?[:\/](.*)(\.git)|\8|")
GITPATH := $(shell echo "$(GITREMOTE)" | sed -r "s|((.*)(\:\/\/))?((.*)\@)?([^\/:]*)(\:([0-9]+))?[:\/](.*)(\.git)|\9|")
##############
### Docker ###
##############
#DOCKER_REPOSITORY ?= $(CI_PROJECT_NAME)
DOCKER_REPOSITORY ?= $(GITPATH)
DOCKER_TAG ?= local
VENDOR ?= ITFL-Service Uni Bamberg
MAINTAINER ?= ITFL-Service <[email protected]>
CI_REGISTRY_IMAGE ?= $(DOCKER_REGISTRY)$(DOCKER_REPOSITORY)
CI_PIPELINE_ID ?= $(DOCKER_TAG)
###############################
.EXPORT_ALL_VARIABLES:
.PHONY: all
all: clean docker_build ## Build binary and docker image
.PHONY: clean
clean: ## Cleanup backup files and compiled binaries
@echo "Cleanup and *~"
@find . -type f -name '*~' -delete
# Dry run
git clean -dXn
# Interactive run
# @git clean -dXi
# Force run
# @git clean -dXf
.PHONY: docker_build
docker_build: ## Build docker image
@echo "Building $(CI_PROJECT_NAME)"
docker image build --pull \
--label gitlab-pipeline-id="$(CI_PIPELINE_ID)" \
--label maintainer="$(MAINTAINER)" \
--label org.label-schema.schema-version="1.0" \
--label org.label-schema.vendor="$(VENDOR)" \
--label org.label-schema.vcs-ref="$(CI_COMMIT_SHA)" \
--label org.label-schema.version="$(CI_COMMIT_TAG)" \
--label org.label-schema.vcs-url="$(CI_PROJECT_URL)" \
--label org.label-schema.name="$(CI_PROJECT_NAME)" \
--label org.label-schema.build-date=`date -u +"%Y-%m-%dT%H:%M:%SZ_%Z"` \
--tag $(CI_REGISTRY_IMAGE):$(CI_PIPELINE_ID) .
.PHONY: help
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' Makefile | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'