-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
66 lines (48 loc) · 2.23 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
APP_NAME := $(shell git remote -v | awk '/origin/ && /fetch/ { sub(/\.git/, ""); n=split($$2, origin, "/"); print origin[n]}')
BUILD_DATESTAMP := $(shell date -u '+%Y%m%dT%H%M%SZ')
GIT_BRANCH := $(shell git branch --show-current)
GIT_SHA1 := $(shell git log --pretty=format:'%h' -n 1)
GIT_URL := $(shell git remote get-url origin | sed 's/https:\/\/.*\@github.com/https:\/\/github.com/')
BUILD_DIR ?= deployment/kubernetes
BUILD_ENV ?= $(TMP_DIR)/build-env
ifndef BUILD_TAG
BUILD_TAG := localbuild://${USER}@$(shell uname -n | sed "s/'//g")
endif
ORG_NAME ?= answerbook
RELEASE_BRANCHES ?= main
RELEASE_DIR ?= release
TMP_DIR ?= tmp
DOCKER_RUN ?= docker run --rm -i
DOCKER_RUN_BUILD_ENV ?= $(DOCKER_RUN) --env-file=$(BUILD_ENV)
ENVSUBST_COMMAND ?= $(DOCKER_RUN_BUILD_ENV) -v $(PWD):/data:Z bhgedigital/envsubst envsubst "$$(printf '$${%s} ' $$(cut -f1 -d'=' ${BUILD_ENV}))"
GH_COMMAND ?= $(DOCKER_RUN) -e GITHUB_TOKEN -v $(PWD):/data:Z -w /data us.gcr.io/logdna-k8s/gh:latest gh
KUBEVAL_COMMAND ?= $(DOCKER_RUN) -v $(PWD):/data:Z garethr/kubeval --ignore-missing-schemas
YAMLLINT_COMMAND ?= $(DOCKER_RUN) -v $(PWD):/data:Z cytopia/yamllint:latest
BUILD_ARTIFACTS := $(wildcard $(BUILD_DIR)/*.yaml.envsubst)
RELEASE_ARTIFACTS := $(patsubst $(BUILD_DIR)/%.envsubst, $(RELEASE_DIR)/%, $(BUILD_ARTIFACTS))
RELEASE_VERSION := $(BUILD_DATESTAMP)
VERSIONS_FILES = $(wildcard versions/wave*.mk)
include $(VERSIONS_FILES)
export
.PHONY:build clean debug-% lint publish test
DRAFT =
ifneq ($(GIT_BRANCH), $(filter $(RELEASE_BRANCHES), $(GIT_BRANCH)))
DRAFT = --draft
endif
$(RELEASE_DIR) $(TMP_DIR):
@mkdir -p $(@)
$(RELEASE_DIR)/%: $(BUILD_DIR)/%.envsubst $(BUILD_ENV) | $(RELEASE_DIR)
$(ENVSUBST_COMMAND) < $(<) > $(@)
$(BUILD_ENV): $(TMP_DIR)
@env | awk '!/TOKEN/ && /^(GIT|BUILD|WAVE)/ { print }' | sort > $(@)
build: $(RELEASE_ARTIFACTS)
clean:
rm -rf $(RELEASE_DIR) $(TMP_DIR)
debug-%: ## Debug a variable by calling `make debug-VARIABLE`
@echo $(*) = $($(*))
lint: $(RELEASE_ARTIFACTS)
$(YAMLLINT_COMMAND) /data/$(RELEASE_DIR)
publish: $(RELEASE_ARTIFACTS)
$(GH_COMMAND) release create --repo $(ORG_NAME)/$(APP_NAME) $(DRAFT) $(RELEASE_VERSION) $(RELEASE_ARTIFACTS)
test: $(RELEASE_ARTIFACTS)
$(KUBEVAL_COMMAND) -d /data/$(RELEASE_DIR)