-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
65 lines (46 loc) · 1.32 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
SHELL := bash
bold := $(shell tput bold)
norm := $(shell tput sgr0)
# gh-actions shim
ifdef GITHUB_REPOSITORY
REPO_NAME ?= $(shell echo '$(GITHUB_REPOSITORY)' | tr A-Z a-z)
endif
ifdef GITHUB_REF
ifneq (,$(findstring refs/heads/,$(GITHUB_REF)))
GIT_BRANCH := $(GITHUB_REF:refs/heads/%=%)
else ifneq (,$(findstring refs/tags/,$(GITHUB_REF)))
TAG_NAME := $(GITHUB_REF:refs/tags/%=%)
endif
endif
REPO_NAME ?= $(notdir $(abspath $(dir $(lastword $(MAKEFILE_LIST)))/..))/$(shell basename '$(PWD)')
$(info [REPO_NAME: $(REPO_NAME)])
$(info [GIT_BRANCH: $(GIT_BRANCH)])
$(info [TAG_NAME: $(TAG_NAME)])
.PHONY: all
all:
.PHONY: build
build:
@echo -e "🔨👷 $(bold)Building$(norm) 👷🔨"
docker build \
--pull \
-t '$(REPO_NAME)' \
.
.PHONY: test
test:
docker run --rm '$(REPO_NAME)' --version
.PHONY: publish
publish: docker-login
ifeq ($(GIT_BRANCH),main)
@echo -e "🚀🐳 $(bold)Publishing: $(REPO_NAME):latest$(norm) 🐳🚀"
docker push '$(REPO_NAME)'
else ifdef TAG_NAME
@echo -e "🚀🐳 $(bold)Publishing: $(REPO_NAME):$(TAG_NAME)$(norm) 🐳🚀"
docker tag '$(REPO_NAME)' '$(REPO_NAME):$(TAG_NAME)'
docker push '$(REPO_NAME):$(TAG_NAME)'
endif
.PHONY: docker-login
docker-login:
$(call docker_login)
define docker_login
echo -n '$(DOCKER_PASSWORD)' | docker login -u lifeofguenter --password-stdin
endef