forked from aws-samples/aws-serverless-ecommerce-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
188 lines (160 loc) · 5.08 KB
/
Makefile
File metadata and controls
188 lines (160 loc) · 5.08 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# Setup variables
NAME = ecommerce-platform
PYENV := $(shell which pyenv)
SPECCY := $(shell which speccy)
JQ := $(shell which jq)
PYTHON_VERSION = 3.8.1
MAKEOPTS += -j4
# Service variables
SERVICES = $(shell tools/services)
SERVICES_ENVONLY = $(shell tools/services --env-only)
export DOMAIN ?= ecommerce
export ENVIRONMENT ?= dev
# Colors
ccblue = \033[0;96m
ccend = \033[0m
###################
# SERVICE TARGETS #
###################
# Run pipeline on services
all:
@for service_line in $(shell tools/services --graph --env-only); do \
${MAKE} ${MAKEOPTS} $$(echo all-$$service_line | sed 's/,/ all-/g') QUIET=true || exit 1 ; \
done
all-%:
@${MAKE} lint-$*
@${MAKE} build-$*
@${MAKE} tests-unit-$*
@${MAKE} check-deps-$*
@${MAKE} package-$*
@${MAKE} deploy-$*
@${MAKE} tests-integ-$*
# Run CI on services
ci: $(foreach service,${SERVICES}, ci-${service})
ci-%:
@${MAKE} lint-$*
@${MAKE} build-$*
@${MAKE} tests-unit-$*
# All but for dependencies
deps-%:
@for service_line in $(shell tools/services --graph --env-only --deps-of $*); do \
${MAKE} ${MAKEOPTS} $$(echo all-$$service_line | sed 's/,/ all-/g') QUIET=true || exit 1 ; \
done
# Artifacts services
artifacts: $(foreach service,${SERVICES_ENVONLY}, all-${service})
artifacts-%:
@echo "[*] $(ccblue)artifacts $*$(ccend)"
@${MAKE} -C $* artifacts
# Build services
build: $(foreach service,${SERVICES}, build-${service})
build-%:
@echo "[*] $(ccblue)build $*$(ccend)"
@${MAKE} -C $* build
# Check-deps services
check-deps: $(foreach service,${SERVICES_ENVONLY}, check-deps-${service})
check-deps-%:
@echo "[*] $(ccblue)check-deps $*$(ccend)"
@${MAKE} -C $* check-deps
# Clean services
clean: $(foreach service,${SERVICES}, clean-${service})
clean-%:
@echo "[*] $(ccblue)clean $*$(ccend)"
@${MAKE} -C $* clean
deploy: $(foreach service,${SERVICES_ENVONLY}, deploy-${service})
deploy-%:
@echo "[*] $(ccblue)deploy $*$(ccend)"
@${MAKE} -C $* deploy
# Lint services
lint: $(foreach service,${SERVICES}, lint-${service})
lint-%:
@echo "[*] $(ccblue)lint $*$(ccend)"
@${MAKE} -C $* lint
# Package services
package: $(foreach service,${SERVICES_ENVONLY}, package-${service})
package-%:
@echo "[*] $(ccblue)package $*$(ccend)"
@${MAKE} -C $* package
# Teardown services
teardown:
@for service_line in $(shell tools/services --graph --reverse --env-only); do \
${MAKE} ${MAKEOPTS} $$(echo teardown-$$service_line | sed 's/,/ teardown-/g') QUIET=true || exit 1 ; \
done
teardown-%:
@echo "[*] $(ccblue)teardown $*$(ccend)"
@${MAKE} -C $* teardown
# Integration tests
tests-integ: $(foreach service,${SERVICES_ENVONLY}, tests-integ-${service})
tests-integ-%:
@echo "[*] $(ccblue)tests-integ $*$(ccend)"
@${MAKE} -C $* tests-integ
# Unit tests
tests-unit: $(foreach service,${SERVICES}, tests-unit-${service})
tests-unit-%:
@echo "[*] $(ccblue)tests-unit $*$(ccend)"
@${MAKE} -C $* tests-unit
# End-to-end tests
tests-e2e:
@tools/tests-e2e
# Performance tests
tests-perf:
@tools/tests-perf
#################
# SETUP TARGETS #
#################
# Validate that necessary tools are installed
validate: validate-pyenv validate-speccy validate-jq
# Validate that pyenv is installed
validate-pyenv:
ifndef PYENV
$(error Make sure pyenv is accessible in your path. You can install pyenv by following the instructions at 'https://github.com/pyenv/pyenv-installer'.)
endif
ifndef PYENV_SHELL
$(error Add 'pyenv init' to your shell to enable shims and autocompletion.)
endif
ifndef PYENV_VIRTUALENV_INIT
$(error Add 'pyenv virtualenv-init' to your shell to enable shims and autocompletion.)
endif
# Validate that speccy is installed
validate-speccy:
ifndef SPECCY
$(error 'speccy' not found. You can install speccy by following the instructions at 'https://github.com/wework/speccy'.)
endif
# Validate that jq is installed
validate-jq:
ifndef JQ
$(error 'jq' not found. You can install jq by following the instructions at 'https://stedolan.github.io/jq/download/'.)
endif
# setup: configure tools
setup: validate
@echo "[*] Download and install python $(PYTHON_VERSION)"
@pyenv install $(PYTHON_VERSION)
@pyenv local $(PYTHON_VERSION)
@echo "[*] Create virtualenv $(NAME) using python $(PYTHON_VERSION)"
@pyenv virtualenv $(PYTHON_VERSION) $(NAME)
@$(MAKE) activate
@$(MAKE) requirements
@${MAKE} npm-install
# Activate the virtual environment
activate: validate-pyenv
@echo "[*] Activate virtualenv $(NAME)"
$(shell eval "$$(pyenv init -)" && eval "$$(pyenv virtualenv-init -)" && pyenv activate $(NAME) && pyenv local $(NAME))
# Install python dependencies
requirements:
@echo "[*] Install Python requirements"
@pip install -r requirements.txt
# Install npm dependencies
npm-install:
@echo "[*] Install NPM tools"
@npm install -g speccy
# Create the entire pipeline
bootstrap-pipeline:
# Deploy in different environments
@${MAKE} all ENVIRONMENT=tests
@${MAKE} all ENVIRONMENT=staging
@${MAKE} all ENVIRONMENT=prod
# Deploy the pipeline
@${MAKE} all-pipeline
# Seed the git repository
@echo "[*] seed repository"
@git remote add aws $(shell aws ssm get-parameter --name /ecommerce/pipeline/repository/url | jq -r '.Parameter.Value')
@git push aws HEAD:master