generated from devops-infra/template-action
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Makefile
58 lines (49 loc) · 2.11 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
.PHONY: help build push
phony: help
# Release tag for the action
VERSION := v0.9.2
# GitHub Actions bogus variables
GITHUB_REF ?= refs/heads/null
GITHUB_SHA ?= aabbccddeeff
# Other variables and constants
CURRENT_BRANCH := $(shell echo $(GITHUB_REF) | sed 's/refs\/heads\///')
GITHUB_SHORT_SHA := $(shell echo $(GITHUB_SHA) | cut -c1-7)
RELEASE_BRANCH := master
DOCKER_USER_ID := christophshyper
DOCKER_ORG_NAME := devopsinfra
DOCKER_IMAGE := action-commit-push
DOCKER_NAME := $(DOCKER_ORG_NAME)/$(DOCKER_IMAGE)
BUILD_DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
# Some cosmetics
SHELL := bash
TXT_RED := $(shell tput setaf 1)
TXT_GREEN := $(shell tput setaf 2)
TXT_YELLOW := $(shell tput setaf 3)
TXT_RESET := $(shell tput sgr0)
define NL
endef
# Main actions
help: ## Display help prompt
$(info Available options:)
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "$(TXT_YELLOW)%-25s $(TXT_RESET) %s\n", $$1, $$2}'
build: ## Build Docker image
$(info $(NL)$(TXT_GREEN) == STARTING BUILD ==$(TXT_RESET))
$(info $(TXT_GREEN)Release tag:$(TXT_YELLOW) $(VERSION)$(TXT_RESET))
$(info $(TXT_GREEN)Current branch:$(TXT_YELLOW) $(CURRENT_BRANCH)$(TXT_RESET))
$(info $(TXT_GREEN)Commit hash:$(TXT_YELLOW) $(GITHUB_SHORT_SHA)$(TXT_RESET))
$(info $(TXT_GREEN)Build date:$(TXT_YELLOW) $(BUILD_DATE)$(TXT_RESET))
$(info $(NL)$(TXT_GREEN)Building Docker image:$(TXT_YELLOW) $(DOCKER_NAME):$(VERSION)$(TXT_RESET))
@docker build \
--build-arg BUILD_DATE=$(BUILD_DATE) \
--build-arg VCS_REF=$(GITHUB_SHORT_SHA) \
--build-arg VERSION=$(VERSION) \
--file=Dockerfile \
--tag=$(DOCKER_NAME):$(VERSION) .
push: ## Push to DockerHub
$(info $(NL)$(TXT_GREEN) == STARTING DEPLOYMENT == $(TXT_RESET))
$(info $(NL)$(TXT_GREEN)Logging-in to DockerHub$(TXT_RESET))
@echo $(DOCKER_TOKEN) | docker login -u $(DOCKER_USER_ID) --password-stdin
$(info $(NL)$(TXT_GREEN)Pushing Docker image:$(TXT_YELLOW) $(DOCKER_NAME):$(VERSION)$(TXT_RESET))
@docker tag $(DOCKER_NAME):$(VERSION) $(DOCKER_NAME):latest
@docker push $(DOCKER_NAME):$(VERSION)
@docker push $(DOCKER_NAME):latest