-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
126 lines (98 loc) · 4.02 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# PROJECT_NAME defaults to name of the current directory.
PROJECT_NAME ?= $(notdir $(PWD))
# For now only support a single infra application deployment in the folder `infra/app/` within the repo
# In the future, support multiple apps, and which app is being operated
# on will be determined by the INFRA_APP_NAME Makefile argument
INFRA_APP_NAME ?= app
# Get the list of reusable terraform modules by getting out all the modules
# in infra/modules and then stripping out the "infra/modules/" prefix
MODULES := $(notdir $(wildcard infra/modules/*))
# Get the list of accounts and environments in a manner similar to MODULES above
ACCOUNTS := $(notdir $(wildcard infra/accounts/*))
ENVIRONMENTS := $(notdir $(wildcard infra/app/envs/*))
.PHONY : \
infra-validate-modules \
infra-validate-env-template \
infra-check-compliance \
infra-check-compliance-checkov \
infra-check-compliance-tfsec \
infra-lint \
infra-format \
release-build \
release-publish \
release-prepare \
image-registry-login \
db-migrate \
db-migrate-down \
db-migrate-create
# Validate all infra root and child modules.
infra-validate: \
infra-validate-modules \
# !! Uncomment the following line once you've set up the infra/project-config module
# infra-validate-env-template
# Validate all infra root and child modules.
# Validate all infra reusable child modules. The prerequisite for this rule is obtained by
# prefixing each module with the string "infra-validate-module-"
infra-validate-modules: $(patsubst %, infra-validate-module-%, $(MODULES))
infra-validate-module-%:
@echo "Validate library module: $*"
terraform -chdir=infra/modules/$* init -backend=false
terraform -chdir=infra/modules/$* validate
infra-validate-env-template:
@echo "Validate module: env-template"
terraform -chdir=infra/app/env-template init -backend=false
terraform -chdir=infra/app/env-template validate
infra-check-compliance: infra-check-compliance-checkov infra-check-compliance-tfsec
infra-check-compliance-checkov:
checkov --directory infra
infra-check-compliance-tfsec:
tfsec infra
infra-lint:
terraform fmt -recursive -check infra
infra-format:
terraform fmt -recursive infra
infra-test:
cd infra/test && go test -v -timeout 30m
########################
## Release Management ##
########################
# The application to be deployed.
# Must be the name of the directory.
# The directory must be relative to this Makefile
APP_NAME ?= default
# Include project name in image name so that image name
# does not conflict with other images during local development
IMAGE_NAME := $(PROJECT_NAME)-$(APP_NAME)
GIT_REPO_AVAILABLE := $(shell git rev-parse --is-inside-work-tree 2>/dev/null)
# Generate a unique tag based solely on the git hash.
# This will be the identifier used for deployment via terraform.
ifdef GIT_REPO_AVAILABLE
IMAGE_TAG := $(shell git rev-parse HEAD)
else
IMAGE_TAG := "unknown-dev.$(DATE)"
endif
# Generate an informational tag so we can see where every image comes from.
DATE := $(shell date -u '+%Y%m%d.%H%M%S')
INFO_TAG := $(DATE).$(USER)
release-build:
cd $(APP_NAME) && $(MAKE) release-build ENV_NAME=$(ENV_NAME) \
OPTS="--tag $(IMAGE_NAME):latest --tag $(IMAGE_NAME):$(IMAGE_TAG)"
release-publish:
./bin/publish-release.sh $(APP_NAME) $(IMAGE_NAME) $(IMAGE_TAG) $(INFRA_APP_NAME)
release-prepare:
# check the varaible against the list of enviroments and suggest one of the correct envs.
ifneq ($(filter $(ENV_NAME),$(ENVIRONMENTS)),)
./bin/prepare-release.sh $(PROJECT_NAME) $(APP_NAME) $(ENV_NAME) $(IMAGE_TAG) $(INFRA_APP_NAME)
else
@echo "The value for env_name must be one of these: $(ENVIRONMENTS)"
exit 1
endif
release-image-name: ## Prints the image name of the release image
@echo $(IMAGE_NAME)
release-image-tag: ## Prints the image tag of the release image
@echo $(IMAGE_TAG)
########################
## Scripts and Helper ##
########################
help: ## Prints the help documentation and info about each command
@grep -E '^[/a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'