项目作者: turnerlabs

项目描述 :
A CLI tool for scaffolding out new AWS ECS/Fargate applications based on Terraform templates and Fargate CLI
高级语言: Go
项目地址: git://github.com/turnerlabs/fargate-create.git
创建时间: 2018-07-27T16:18:56Z
项目社区:https://github.com/turnerlabs/fargate-create

开源协议:Apache License 2.0

下载


fargate-create

A CLI tool for scaffolding out new AWS ECS/Fargate applications based on terraform-ecs-fargate and Fargate CLI.

Why?

The main design goal of this project is to create an easy and maintainable Fargate experience by separating infrastructure related concerns and application related concerns using tools that are optimized for each.

Installation

You can install the CLI with a curl utility script (macos/linux) or by downloading the binary from the releases page. Once installed you’ll get the fargate-create command.

  1. curl -s get-fargate-create.turnerlabs.io | sh
  2. `

Usage

Assuming you have a project with a Dockerfile

Specify your template’s input parameters in terraform.tfvars (or terraform.json). The default web application template’s input looks something like this. Note: any Terraform template can be used

  1. # app/env to scaffold
  2. app = "my-app"
  3. environment = "dev"
  4. internal = "true"
  5. container_port = "8080"
  6. replicas = "1"
  7. health_check = "/health"
  8. region = "us-east-1"
  9. aws_profile = "default"
  10. vpc = "vpc-123"
  11. private_subnets = "subnet-123,subnet-456"
  12. public_subnets = "subnet-789,subnet-012"
  13. tags = {
  14. application = "my-app"
  15. environment = "dev"
  16. }
  1. $ fargate-create
  2. scaffolding my-app dev
  3. Looking up AWS Account ID using profile: default
  4. downloading terraform template git@github.com:turnerlabs/terraform-ecs-fargate
  5. installing terraform template
  6. done

Now you have all the files you need to spin up something in Fargate. Note that the Terraform files can be edited or customized. You can also use your own Terraform template using the --template flag.

Infrastructure: provision using Terraform

  1. cd iac/base
  2. terraform init && terraform apply
  3. cd ../env/dev
  4. terraform init && terraform apply

Application: build/push using Docker and deploy using Fargate CLI

  1. docker-compose build
  2. login=$(aws ecr get-login --no-include-email) && eval "$login"
  3. docker-compose push
  4. fargate service deploy -f docker-compose.yml

To scaffold out additional environnments, simply change the environment input parameter in terraform.tfvars and re-run

  1. $ fargate-create
  2. scaffolding my-app prod
  3. Looking up AWS Account ID using profile: default
  4. downloading terraform template git@github.com:turnerlabs/terraform-ecs-fargate
  5. installing terraform template
  6. iac/base already exists, ignoring
  7. done

And then bring up the new environment (no need to apply base again since it’s shared):

  1. cd ../prod
  2. terraform init && terraform apply

You’ll end up with a directory structure that looks something like this:

  1. .
  2. |____iac
  3. | |____base
  4. | |____env
  5. | | |____dev
  6. | | |____prod

As changes are made to the various upstream templates over time, the upgrade command can be used to keep installed versions up to date.

  1. fargate-create upgrade

Stacks

The following stacks are popular configurations that can be used with fargate-create

Help

  1. Scaffold out new AWS ECS/Fargate applications based on Terraform templates and Fargate CLI
  2. Usage:
  3. fargate-create [flags]
  4. fargate-create [command]
  5. Examples:
  6. # Scaffold an environment using the latest default template
  7. fargate-create
  8. # Do not prompt for options
  9. fargate-create -y
  10. # Use a template stored in github
  11. fargate-create -t git@github.com:turnerlabs/terraform-ecs-fargate?ref=v0.4.3
  12. # Scaffold out files for various build systems
  13. fargate-create build circleciv2
  14. # keep your template up to date
  15. fargate-create upgrade
  16. # Use a template stored in s3
  17. AWS_ACCESS_KEY=xyz AWS_SECRET_KEY=xyz AWS_REGION=us-east-1 \
  18. fargate-create -t s3::https://s3.amazonaws.com/my-bucket/my-template
  19. # Use a template stored in your file system
  20. fargate-create -t ~/my-template
  21. # Use a specific input file
  22. fargate-create -f app.tfvars
  23. # Use a JSON input file
  24. fargate-create -f app.json
  25. Available Commands:
  26. build Scaffold out artifacts for various build systems
  27. help Help about any command
  28. upgrade Keep a terraform template up to date
  29. Flags:
  30. -f, --file string file specifying Terraform input variables, in either HCL or JSON format (default "terraform.tfvars")
  31. -h, --help help for fargate-create
  32. -d, --target-dir string target directory where code is outputted (default "iac")
  33. -t, --template string URL of a compatible Terraform template (default "git@github.com:turnerlabs/terraform-ecs-fargate")
  34. -v, --verbose Verbose output
  35. --version version for fargate-create
  36. -y, --yes don't ask questions and use defaults

CI/CD

Using this technique, it’s easy to codegen CI/CD pipelines for many popular build tools. The build command supports this.

  1. $ fargate-create build <provider>

The following providers are supported:

Extensibility

fargate-create can scaffold out any Terraform template (specified by --template) that meets the following requirements:

  • base and env/dev directory structure
  • a env/dev/main.tf with an s3 remote state backend
  • app and environment input variables

Your template can be downloaded from a variety of locations using a variety of protocols. The following are supported:

  • Local files (~/my-template)
  • Git (git@github.com:my-org/my-template)
  • Amazon S3 (s3::https://s3.amazonaws.com/my-bucket/my-template)
  • HTTP (http://server/my-template/)

Optionally:

  • add a fargate-create.yml (example here) to your template to drive custom configuration, prompting for defaults, etc.

An example of an extended template:

  1. $ fargate-create -f my-scheduledtask.tfvars -t git@github.com:turnerlabs/terraform-ecs-fargate-scheduled-task