This repository has been archived by the owner on Jul 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 378
/
Makefile
212 lines (184 loc) · 6.62 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
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# Setup variables
NAME = ecommerce-platform
PYENV := $(shell which pyenv)
JQ := $(shell which jq)
PYTHON_VERSION = 3.9.7
MAKEOPTS += -j4
# Service variables
SERVICES = $(shell tools/services 2>/dev/null)
SERVICES_ENVONLY = $(shell tools/services --env-only 2>/dev/null)
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-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 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
# setup for Cloud9 environments
setup-cloud9:
@echo "[*] Install required libraries"
sudo yum install -y @development zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel xz xz-devel libffi-devel findutils jq
@echo "[*] Resize Cloud 9 volume"
aws ec2 modify-volume --volume-id $$(aws ec2 describe-instances --instance-id $$(curl http://169.254.169.254/latest/meta-data/instance-id) | jq -r .Reservations[0].Instances[0].BlockDeviceMappings[0].Ebs.VolumeId) --size 20
while [ "$$(aws ec2 describe-volumes-modifications --volume-id $$(aws ec2 describe-instances --instance-id $$(curl http://169.254.169.254/latest/meta-data/instance-id) | jq -r .Reservations[0].Instances[0].BlockDeviceMappings[0].Ebs.VolumeId) --filters Name=modification-state,Values="optimizing","completed" | jq '.VolumesModifications | length')" != "1" ]; do sleep 1; done
if [ $$(readlink -f /dev/xvda) = "/dev/xvda" ]; then sudo growpart /dev/xvda 1; else sudo growpart /dev/nvme0n1 1; fi
sudo xfs_growfs -d /
@echo "[*] Install pyenv"
curl https://pyenv.run | bash
echo -e 'export PYENV_ROOT="$$HOME/.pyenv"\nexport PATH="$$PYENV_ROOT/bin:$$PATH"\neval "$$(pyenv init --path)"' >> ~/.profile
echo -e 'eval "$$(pyenv init -)"\neval "$$(pyenv virtualenv-init -)"' >> ~/.bashrc
@echo "[*] Install node 12"
sudo yum remove -y nodejs npm
curl -sL https://rpm.nodesource.com/setup_12.x | sudo bash -
sudo yum install -y nodejs
@echo "****************************"
@echo "* BEFORE CONTINUING PLEASE *"
@echo "* RUN THESE COMMANDS: *"
@echo
@echo " source ~/.profile "
@echo " exec /bin/bash "
@echo
@echo "* THEN CONTINUE WITH THE *"
@echo "* FOLLOWING COMMAND: *"
@echo
@echo " make setup "
@echo
@echo "****************************"
# 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:main