Skip to content

Commit

Permalink
Add optional deploy of bucket map
Browse files Browse the repository at this point in the history
  • Loading branch information
reweeden committed Feb 4, 2022
1 parent 0e0e155 commit 2f1605b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CONFIG.example
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ CODE_PREFIX = $(STACK_NAME)/
CONFIG_BUCKET = REQUIRED!
# Object prefix for artifacts in the config bucket
CONFIG_PREFIX = $(STACK_NAME)/
# Uncomment the following line to use an existing bucket map rather than uploading one
# BUCKET_MAP_OBJECT_KEY =

# String that will be prepended to bucket names after looking them up in the bucket map
BUCKETNAME_PREFIX =
Expand Down
30 changes: 23 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ EMPTY = $(DIR)/empty
# Output artifacts
DIST = $(SOURCES:lambda=$(DIR)/code)
DIST_RESOURCES = $(RESOURCES:lambda=$(DIR)/code)
BUCKET_MAP_OBJECT_KEY = $(CONFIG_PREFIX)bucket-map.yaml

DATE := $(shell date --utc "+%b %d %Y, %T %Z")
DATE_SHORT := $(shell date --utc "+%Y%m%dT%H%M%S")
Expand Down Expand Up @@ -77,11 +78,12 @@ $(DIR)/thin-egress-app-code.zip: $(DIST) $(DIST_RESOURCES) | $(DIR)/code
find $(DIR)/code -type f -exec sed -i "s/<BUILD_ID>/${BUILD_ID}/g" {} \;
cd $(DIR)/code && zip -r ../thin-egress-app-code.zip .

$(DIR)/bucket-map.yaml: config/bucket-map-template.yaml
cp $< $@

$(DIR)/thin-egress-app.yaml: cloudformation/thin-egress-app.yaml | $(DIR)
cp cloudformation/thin-egress-app.yaml $(DIR)/thin-egress-app.yaml
sed -i -e "s/asf.public.code/${CODE_BUCKET}/" $(DIR)/thin-egress-app.yaml
# sed -i -e "s/<CODE_ARCHIVE_PATH_FILENAME>/${CODE_DIR}\\/code-${BUILD_ID}.zip/" $(DIR)/thin-egress-app.yaml
# sed -i -e "s/<DEPENDENCY_ARCHIVE_PATH_FILENAME>/${CODE_DIR}\\/dependencies-${BUILD_ID}.zip/" $(DIR)/thin-egress-app.yaml
sed -i -e "s/<BUILD_ID>/${BUILD_ID}/g" $(DIR)/thin-egress-app.yaml
sed -i -e "s/^Description:.*/Description: \"TEA snapshot, version: ${BUILD_ID} built ${DATE}\"/" $(DIR)/thin-egress-app.yaml

Expand All @@ -90,16 +92,14 @@ $(DIR)/thin-egress-app.yaml: cloudformation/thin-egress-app.yaml | $(DIR)
# Deployment #
##############
# TODO(reweeden): Terraform?
# TODO(reweeden): Bucket map

# Empty targets so we don't re-deploy stuff that is unchanged. Technically they
# might not be empty, but their purpose is the same.
# https://www.gnu.org/software/make/manual/html_node/Empty-Targets.html

$(EMPTY)/.deploy-dependencies: $(DIR)/thin-egress-app-dependencies.zip | $(EMPTY)
@echo "Deploying dependencies"
$(AWS) s3 cp --profile=$(AWS_PROFILE) \
$(DIR)/thin-egress-app-dependencies.zip \
$(AWS) s3 cp --profile=$(AWS_PROFILE) $< \
s3://$(CODE_BUCKET)/$(CODE_PREFIX)dependencies-$(S3_ARTIFACT_TAG).zip

@echo $(S3_ARTIFACT_TAG) > $(EMPTY)/.deploy-dependencies
Expand All @@ -112,8 +112,21 @@ $(EMPTY)/.deploy-code: $(DIR)/thin-egress-app-code.zip | $(EMPTY)

@echo $(S3_ARTIFACT_TAG) > $(EMPTY)/.deploy-code

$(EMPTY)/.deploy-bucket-map: $(DIR)/bucket-map.yaml | $(EMPTY)
@echo "Deploying bucket map"
$(AWS) s3 cp --profile=$(AWS_PROFILE) $< \
s3://$(CONFIG_BUCKET)/$(BUCKET_MAP_OBJECT_KEY)

@touch $(EMPTY)/.deploy-bucket-map

# Optionally upload a bucket map if the user hasn't specified one
BUCKET_MAP_REQUIREMENT =
ifneq ($(BUCKET_MAP_OBJECT_KEY), $(CONFIG_PREFIX)/bucket-map.yaml)
BUCKET_MAP_REQUIREMENT = $(EMPTY)/.deploy-bucket-map
endif

.PHONY: $(EMPTY)/.deploy-stack
$(EMPTY)/.deploy-stack: $(DIR)/thin-egress-app.yaml $(EMPTY)/.deploy-dependencies $(EMPTY)/.deploy-code | $(EMPTY)
$(EMPTY)/.deploy-stack: $(DIR)/thin-egress-app.yaml $(EMPTY)/.deploy-dependencies $(EMPTY)/.deploy-code $(BUCKET_MAP_REQUIREMENT) | $(EMPTY)
@echo "Deploying stack '$(STACK_NAME)'"
$(AWS) cloudformation deploy --profile=$(AWS_PROFILE) \
--stack-name $(STACK_NAME) \
Expand All @@ -122,7 +135,7 @@ $(EMPTY)/.deploy-stack: $(DIR)/thin-egress-app.yaml $(EMPTY)/.deploy-dependencie
--parameter-overrides \
LambdaCodeS3Key="$(CODE_PREFIX)code-`cat $(EMPTY)/.deploy-code`.zip" \
LambdaCodeDependencyArchive="$(CODE_PREFIX)dependencies-`cat $(EMPTY)/.deploy-dependencies`.zip" \
BucketMapFile=$(CONFIG_PREFIX)bucket_map_customheaders.yaml \
BucketMapFile=$(BUCKET_MAP_OBJECT_KEY) \
URSAuthCredsSecretName=$(URS_CREDS_SECRET_NAME) \
AuthBaseUrl=$(URS_URL) \
ConfigBucket=$(CONFIG_BUCKET) \
Expand Down Expand Up @@ -165,6 +178,9 @@ deploy-code: $(EMPTY)/.deploy-code
.PHONY: deploy-dependencies
deploy-dependencies: $(EMPTY)/.deploy-dependencies

.PHONY: deploy-bucket-map
deploy-bucket-map: $(EMPTY)/.deploy-bucket-map

.PHONY: deploy-stack
deploy-stack: $(EMPTY)/.deploy-stack

Expand Down
7 changes: 7 additions & 0 deletions config/bucket-map-template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
MAP:
# See examples
# BROWSE:
# PLATFORM-A: platform-a-bucket
#
# PUBLIC_BUCKETS:
# - platform-a-bucket

0 comments on commit 2f1605b

Please sign in to comment.