-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
263 lines (224 loc) · 7.38 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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Settings you might want to set externally ex: VERSION=0.0.1 make create
#
#
# S3 bucket to which deployment bundle will be uploaded when publishing
# or downloaded when deploying
#
ifeq ($(BUCKET_NAME),)
BUCKET_NAME?=cfn-andyspohn-com
endif
#
# Beanstalk will only download artifacts from S3 in the same region
#
ifeq ($(AWS_DEFAULT_REGION),)
AWS_DEFAULT_REGION?=us-east-1
endif
ifeq ($(MVN),)
MVN := "./mvnw"
endif
#
# By default the most recent Maven project version is used but for the deployment scenario
# you could set a prior version to deploy ex: "VERSION=1.0.1 make deploy-console"
#
ifeq ($(VERSION),)
VERSION := $(shell $(MVN) -q -Dexec.executable="echo" -Dexec.args='$${project.version}' --non-recursive org.codehaus.mojo:exec-maven-plugin:1.3.1:exec | sed -n '2p')
endif
#
# The sceptre deployment environment to use
#
ifeq ($(ENV),)
ENV := dev
endif
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Project naming convention settings. Probably don't want to mess with these
#
# Assume we're storing many projects in the same S3 bucket, start key prefix with project name
#
ifeq ($(TEMPLATE_NAME),)
TEMPLATE_NAME?=lucee-eb-example
endif
#
# If this version a snapshot add a dev prefix
#
ifeq ($(findstring -SNAPSHOT, $(VERSION)),-SNAPSHOT)
DEV_RELEASE?=/dev
endif
#
# Used to set security group rules. Defaults to your specific IP and requires that curl is installed locally
#
ifeq ($(ALLOWED_IP_CIDR),)
ALLOWED_IP_CIDR := $(shell curl -s http://checkip.amazonaws.com/)/32
endif
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Various housekeeping settings
#
# Check to ensure users have activated the python virtualenv before running sceptre commands
#
sceptre-exists: ; @which sceptre > /dev/null || echo "Run the following command to switch to deploy mode and then re-run your comand:\nsource packaging/deploy/bin/activate\n"
#
# Construct the S3 keyname based on the version (either detected from Maven or set externally) and dev status
#
KEY_NAME := $(TEMPLATE_NAME)$(DEV_RELEASE)/$(VERSION)
#
# Pass all the common args to every sceptre call to simplify
#
SCEPTRE_ARGS := --var "bucket_name=$(BUCKET_NAME)" --var "key_name=$(KEY_NAME)" --var "version=$(VERSION)" --var "allowed_ip_cidr=$(ALLOWED_IP_CIDR)" --dir "cloudformation"
version:
@echo $(VERSION)
help:
@echo ""
@echo "--- Cloudformation orchestration targets ---"
@echo "create: Create an application stack"
@echo "update: Update an application stack"
@echo "delete: Delete an application stack"
@echo "outputs: Display the stack outputs like the address to the load balancer"
@echo ""
@echo " --- Development Targets ---"
@echo "init: Run once after the project is first checked out to intialize the deployment toolchain"
@echo "clean: Remove all temporary build files"
@echo "package: Clean, build and then package all of the application artifacts"
@echo "tomcat-run: Package application artifacts and then run in a local Tomcat server"
@echo ""
@echo "--- S3 Operations ---"
@echo "upload: Package application artifacts and then upload them to the S3 bucket"
@echo "upload-only: Skip distribution bundle rebuild and just upload existing artifacts"
@echo ""
@echo "--- Packaging targets ---"
@echo "dist: Create a distribution package containing all app and doc artifacts"
@echo "docs: Generate documentation"
@echo ""
.PHONY: help
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Project initialization and build targets
#
# This is run once after the project is first checked out to intialize the deployment toolchain
#
init:
pip install --upgrade virtualenv
virtualenv packaging/deploy
packaging/deploy/bin/pip install --upgrade sceptre awscli awsebcli
.PHONY: init
#
# All temporary files are stored within each module's target/ directory. Remove them all
#
clean:
@$(MVN) clean
.PHONY: clean
#
# The Maven package step will compile, test and then package up code into artifacts
# https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html
#
package: clean
@$(MVN) package
.PHONY: package
#
# During development you can build and deploy to a local Tomcat instance of the same version as used by Beanstalk
#
tomcat-run:
@$(MVN) install
@$(MVN) --projects build/tomcat cargo:run
.PHONY: tomcat-run
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Targets that push files to S3
#
# Upload the local application artifacts and Cloudformation templates into S3 using version prefixes
#
upload-files:
@aws s3 sync cloudformation/templates/ s3://$(BUCKET_NAME)/$(KEY_NAME)/cloudformation/ --only-show-errors --acl public-read --delete
@aws s3 cp build/dist/target/ s3://$(BUCKET_NAME)/$(KEY_NAME)/ --recursive --include "*.zip" --only-show-errors --acl public-read
.PHONY: upload-files
#
# Just upload the files, don't rebuild
#
upload-only: upload-files
.PHONY: upload-only
#
# Rebuld the artifacts and then upload
#
upload: dist upload-files
.PHONY: upload
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Cloudformation orchestration targets
#
# Create an application stack
#
create: sceptre-exists
@sceptre $(SCEPTRE_ARGS) create-stack $(ENV) $(TEMPLATE_NAME)
.PHONY: create
#
# Update a stack. If a version other than the current code is desired set the version ex: VERSION=4.0.0 make update
#
update: sceptre-exists
@sceptre $(SCEPTRE_ARGS) update-stack $(ENV) $(TEMPLATE_NAME)
.PHONY: update
#
# Delete an application stack
#
delete: sceptre-exists
@sceptre $(SCEPTRE_ARGS) delete-stack $(ENV) $(TEMPLATE_NAME)
.PHONY: delete
#
# Get the outputs from the stack. The BeanstalkEndpointURL contains the URL to the load balancer
#
outputs: sceptre-exists
@sceptre $(SCEPTRE_ARGS) describe-stack-outputs $(ENV) $(TEMPLATE_NAME)
.PHONY: outputs
#
# Validate the Cloudformation main template
#
validate: sceptre-exists
@sceptre $(SCEPTRE_ARGS) validate-template $(ENV) $(TEMPLATE_NAME)
.PHONY: validate
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Packaging and documentation targets
#
# Run the all of the doc output profiles and dist module
#
dist:
@$(MVN) -P dist,pdf,html clean package
.PHONY: dist
#
# Activate all the output format profiles for the docs module
#
docs:
@$(MVN) -P pdf,html -pl docs package
@$(MVN) -P pdf,html -pl docs package
.PHONY: docs
#TODO: Put in support for "latest" version uploads
upload-docs: docs
@aws s3 sync docs/target/generated-docs/ s3://$(BUCKET_NAME)/$(TEMPLATE_NAME)/latest/docs --only-show-errors --acl public-read --delete
.PHONY: upload-docs
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Docker container wtih preloaded utilities
#
# If lucee-eb-demo/deploy is not available from a container registry build it locally
#
docker-build:
@docker build -t lucee-eb-demo/deploy packaging/docker/
.PHONY: docker-build
#
# Run the container with all build and deploy artifacts preloaded
#
docker-build-app:
@docker run -it --rm -w /src \
-v ~/.aws:/home/deploy/.aws -v $$(pwd):/src -v ~/.m2:/home/deploy/.m2 \
lucee-eb-demo/deploy
.PHONY: docker-build-app
#
# Run the container only to deploy artifacts
#
docker-deploy:
@docker run -it --rm \
-w /home/deploy \
-v ~/.aws:/home/deploy/.aws \
lucee-eb-demo/deploy
.PHONY: docker-deploy