Skip to content
This repository has been archived by the owner on May 19, 2024. It is now read-only.

feat(Makefile): Add 'deploy' target #2

Closed
wants to merge 4 commits into from
Closed

feat(Makefile): Add 'deploy' target #2

wants to merge 4 commits into from

Conversation

Nr18
Copy link
Contributor

@Nr18 Nr18 commented Apr 27, 2018

No issue available

  • Add the deploy target to the Makefile to make it easier to deploy the application to a dev environment on CloudFormation.
  • Add the docs for the new target to the README.md file.
  • Update the README.md instructions so that the Markdown validator agrees with the styling.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Joris Conijn and others added 4 commits April 27, 2018 07:37
Add the deploy target to the Makefile to make it easier to deploy the application to a dev environment on CloudFormation.
Add the docs for the new target to the README.md file.
Update the README.md instructions so that the Markdown validator agrees with the styling.
- Improve feedback while running the commands
- Add `sam validate` on the template before deploying
@Nr18
Copy link
Contributor Author

Nr18 commented May 3, 2018

@heitorlessa i have used this setup in a small poc project and there i had the need to customize the Makefile to support custom parameters but the deployment process is something generic so i build something like this:

# Include project specific targets
EXTENSIONS=$(shell test -f Makefile.extension && echo 'Makefile.extension')
include $(EXTENSIONS)

...OTHER TARGETS...

_package_template: 
	$(info [+] Package template.yaml to packaged.yaml and upload the artifacts to $(BUCKET) with $(CAPABILITIES))
	@aws cloudformation package \
		--template-file $(BASE)/template.yaml \
		--output-template-file $(BASE)/packaged.yaml \
		--s3-bucket ${BUCKET} > /dev/null 2>&1

_validate_template: _package_template
	$(info [+] Validate template.yaml)
	@aws cloudformation validate-template \
		--template-body file://$(BASE)/packaged.yaml > /dev/null ; test "$$?" -eq 0 && echo '[+] Template is valid' || (echo '[!] Template is invalid!' && exit 1)

_deploy_template: _validate_template
	$(info [+] Deploy packaged.yaml -- This may take a while...)
	@aws cloudformation deploy \
		--no-fail-on-empty-changeset \
		--template-file $(BASE)/packaged.yaml \
		--stack-name $(NAME) \
		$($$(MAKE) _get_stack_capabilities) \
		$($$(MAKE) _get_stack_parameters) \
		; test "$$?" -eq 0 && echo '[+] Template has been deployed' || (echo '[!] Deployment of the template failed' && exit 1)

And then a Makefile.extension

NAME = my-stack-name
CAPABILITIES = CAPABILITY_IAM 
CODE_COVERAGE = 95

# Tags
COST_CENTER=Engineering
PRODUCT=Internal
ENVIRONMENT=Development
OWNER=Nr.18

_get_stack_capabilities:
	@echo --capabilities $(CAPABILITIES)

_get_stack_parameters:
	@echo --parameter-overrides \
		CostCenter=$(COST_CENTER) \
		Product=$(PRODUCT) \
		Environment=$(ENVIRONMENT) \
		Owner=$(OWNER)

The general idea behind this is that the Makefile stays the same and all customizations are done in the Makefile.extension file.

Should i include it?

@h1f1x
Copy link
Contributor

h1f1x commented May 24, 2018

I like the idea to have a sample for cloudformation deploy in a makefile.
Nevertheless, it seems to be out of the scope to provide a simple first example to work with. Your example might have problems, if someone don't use tags as parameter in the template. And for the clarity of configuration of the cloudformation template, the arguments and the stack name should better be in a seperate (config only) file!? For example see: https://github.com/cfn-sphere/cfn-sphere

I discussed with @heitorlessa about the idea to have some kind of advanced templates or examples. But we agreed to focus on the basics to enable others to build even more (advanced) solutions and own cookiecutter based setup templates (like the one with your Makefile extension).

Nevertheless I would like to have _*_template in the makefile, but without the Makefile.extension. This could be better documented as an advanced example for specific use cases.

@Nr18
Copy link
Contributor Author

Nr18 commented Jun 8, 2018

@heitorlessa i think we can close this one in favor of #9 right?

@heitorlessa
Copy link
Contributor

Yep, I'd say so. Let's close this as this would add additional complexity that people could easily get into trouble.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants