-
Notifications
You must be signed in to change notification settings - Fork 2
/
common.mk
125 lines (111 loc) · 4.16 KB
/
common.mk
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
SHELL=/bin/bash
# Every phony target must directly or indirectly depend on this target. This
# implies that only targets that have no other dependencies must explicitly
# list this target as a dependency:
#
.PHONY: check_env
check_env:
@if ! test -n "$$project_root"; then \
echo -e "\nPlease run 'source environment' from the project root\n"; \
false; \
fi
.PHONY: check_venv
check_venv: check_env
@if ! test -n "$$VIRTUAL_ENV"; then \
echo -e "\nError: Run 'source .venv/bin/activate' first\n"; \
false; \
fi
.PHONY: check_python
check_python: check_venv
@if test "$$VIRTUAL_ENV/bin/python" != "$$(hash python && hash -t python)"; then \
echo -e "\nPATH lookup yields a 'python' executable from outside the virtualenv\n"; \
false; \
fi
@if test "$$VIRTUAL_ENV/bin/pip" != "$$(hash pip && hash -t pip)"; then \
echo -e "\nPATH lookup yields a 'pip' executable from outside the virtualenv\n"; \
false; \
fi
@if ! python -c "import sys, os; \
p = lambda v: tuple(map(int, v.split('.'))); \
v = os.environ['azul_python_version']; \
sys.exit(0 if sys.version_info[:3] == p(v) else 1)"; then \
echo -e "\nLooks like Python ${azul_python_version} is not installed\n"; \
false; \
fi
@if ! python -c "import sys; \
exec('try: import chalice\nexcept: sys.exit(1)\nelse: sys.exit(0)')"; then \
echo -e "\nLooks like some requirements are missing. Please run 'make requirements'\n"; \
false; \
fi
@if ! python -c "import sys, wheel as w; \
p = lambda v: tuple(map(int, v.split('.'))); \
sys.exit(0 if p(w.__version__) >= p('0.32.3') else 1)"; then \
echo -e "\nLooks like the `wheel` package is outdated or missing. See README for instructions on how to fix this.\n"; \
false; \
fi
@if ! python -c "import sys; \
from chalice import chalice_version as v; \
p = lambda v: tuple(map(int, v.split('.'))); \
sys.exit(0 if p(v) == p('1.30.0') else 1)"; then \
echo -e "\nLooks like chalice is out of date. Please run 'make requirements'\n"; \
false; \
fi
.PHONY: check_terraform
check_terraform: check_env
@if ! hash terraform; then \
echo -e "\nLooks like Terraform is not installed.\n"; \
false; \
fi
@if test "$$(terraform --version --json \
| python -c 'import json; print(json.load(open(0))["terraform_version"])')" \
!= \
"$$azul_terraform_version"; then \
echo -e "\nLooks like the wrong version of Terraform is installed.\n"; \
false; \
fi
.PHONY: check_docker
check_docker:
@if ! hash docker; then \
echo -e "\nLooks like Docker is not installed.\n"; \
false; \
fi
.PHONY: check_aws
check_aws: check_python
@if ! python -c "import os, sys, boto3 as b; \
expected = os.environ['AZUL_AWS_ACCOUNT_ID']; \
actual = b.client('sts').get_caller_identity()['Account']; \
sys.exit(0 if actual == expected else 1)"; then \
echo Looks like there is a mismatch between AZUL_AWS_ACCOUNT_ID \
and the currently active AWS credentials. ; \
echo Check the output from \'aws sts get-caller-identity\' against the \
value of that environment variable. ; \
false; \
fi
.PHONY: check_branch
check_branch: check_python
python $(project_root)/scripts/check_branch.py
.PHONY: git_clean_recursive
git_clean_recursive: check_env
git clean -Xdf
.PHONY: git_list_dirt_recursive
git_list_dirt_recursive: check_env
git clean -Xdn
# `grep` returns 1 if nothing matches. Here, this does not constitute an error.
define list_dirt
set -o pipefail \
&& git ls-files --ignored --others --directory --exclude-standard \
| (grep -v '/[^/]' || test $$? -eq 1)
endef
.PHONY: git_clean
git_clean: check_env
$(call list_dirt) | xargs -r rm -rv
.PHONY: git_list_dirt
git_list_dirt: check_env
@$(call list_dirt)
%.json: %.json.template.py check_python .FORCE
python $< $@
.FORCE:
# The template output file depends on the template file, of course, as well as
# the environment. To be safe we force the template creation. This is what
# the fake .FORCE target does. It still is necessary to declare a target's
# dependency on a template to ensure correct ordering.