ufo 1.7.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/docs/_docs/conventions.md +4 -0
  4. data/docs/_docs/helpers.md +1 -1
  5. data/docs/_docs/install.md +11 -11
  6. data/docs/_docs/settings.md +64 -23
  7. data/docs/_docs/structure.md +7 -2
  8. data/docs/_docs/tutorial-ufo-init.md +22 -16
  9. data/docs/_docs/tutorial-ufo-ship.md +19 -18
  10. data/docs/_docs/tutorial-ufo-ships.md +5 -5
  11. data/docs/_docs/tutorial-ufo-tasks-build.md +50 -63
  12. data/docs/_docs/ufo-destroy.md +2 -2
  13. data/docs/_docs/ufo-env.md +54 -0
  14. data/docs/_docs/ufo-init.md +7 -3
  15. data/docs/_docs/ufo-scale.md +2 -2
  16. data/docs/_docs/ufo-ship.md +8 -8
  17. data/docs/_docs/ufo-ships.md +4 -4
  18. data/docs/_docs/ufo-tasks-build.md +42 -26
  19. data/docs/_docs/ufo-tasks-register.md +3 -3
  20. data/docs/_docs/variables.md +48 -0
  21. data/docs/_includes/commands.html +1 -0
  22. data/docs/_includes/subnav.html +2 -0
  23. data/docs/bin/web +4 -0
  24. data/docs/img/tutorials/ecs-console-ufo-ship.png +0 -0
  25. data/docs/quick-start.md +22 -4
  26. data/lib/starter_project/bin/deploy +1 -1
  27. data/lib/starter_project/ufo/settings.yml +14 -6
  28. data/lib/starter_project/ufo/task_definitions.rb +13 -24
  29. data/lib/starter_project/ufo/variables/base.rb +6 -0
  30. data/lib/starter_project/ufo/variables/prod.rb +7 -0
  31. data/lib/starter_project/ufo/variables/stag.rb +7 -0
  32. data/lib/ufo.rb +3 -0
  33. data/lib/ufo/default/settings.yml +25 -0
  34. data/lib/ufo/defaults.rb +11 -10
  35. data/lib/ufo/dsl/task_definition.rb +31 -0
  36. data/lib/ufo/env.rb +18 -0
  37. data/lib/ufo/settings.rb +18 -12
  38. data/lib/ufo/version.rb +1 -1
  39. metadata +10 -4
  40. data/docs/img/tutorials/ufo-init.png +0 -0
  41. data/docs/img/tutorials/ufo-tasks-build.png +0 -0
@@ -5,13 +5,13 @@ title: ufo destroy
5
5
  Ufo provides a quick way to destroy an ECS service. In order to destroy an ECS service you must makes sure that the desired number of tasks is first set to 0. It is easy to forgot to do this and waste time. So as part of destroying the service ufo will scale the ECS service down to 0 automatically first and then destroy the service. Ufo also prompts you before destroying the service.
6
6
 
7
7
  ```
8
- ufo destroy hi-web-stag
8
+ ufo destroy hi-web
9
9
  ```
10
10
 
11
11
  If you would like to bypass the prompt you can use the `--sure` option.
12
12
 
13
13
  ```
14
- ufo destroy hi-web-stag --sure
14
+ ufo destroy hi-web --sure
15
15
  ```
16
16
 
17
17
  <a id="prev" class="btn btn-basic" href="{% link _docs/ufo-scale.md %}">Back</a>
@@ -0,0 +1,54 @@
1
+ ---
2
+ title: UFO_ENV
3
+ ---
4
+
5
+ Ufo's behavior is controlled by the `UFO_ENV` environment variable. For example, the `UFO_ENV` variable is used to layer different ufo variable files together to make it easy to specify settings for different environments like production and staging. This is covered thoroughly in the [Variables]({% link _docs/variables.md %}) section. `UFO_ENV` defaults to `prod` when not set.
6
+
7
+ ### Setting UFO_ENV
8
+
9
+ The `UFO_ENV` can be set easily in several ways:
10
+
11
+ 1. At the CLI command invocation - This takes the highest precedence.
12
+ 2. Exported as an environment variable to your shell - This takes the second highest precedence.
13
+ 3. As a `aws_profile_ufo_env_map` value in your `ufo/settings.yml` file - This takes the lowest precedence.
14
+
15
+ ### At the CLI Command
16
+
17
+ ```sh
18
+ UFO_ENV=prod ufo ship hi-web --cluster prod
19
+ ```
20
+
21
+ ### As an environment variable
22
+
23
+ ```sh
24
+ export UFO_ENV=prod
25
+ ufo ship hi-web --cluster prod
26
+ ```
27
+
28
+ Most people will set `UFO_ENV` in their `~/.profile`.
29
+
30
+ ### In ufo/settings.yml
31
+
32
+ The most interesting way to set `UFO_ENV` is with the `aws_profile_ufo_env_map` in `ufo/settings.yml`. Let's say you have a `~/.ufo/settings.yml` with the following:
33
+
34
+ ```yaml
35
+ aws_profile_ufo_env_map:
36
+ default: dev
37
+ my-prod-profile: prod
38
+ my-stag-profile: stag
39
+ ```
40
+
41
+ In this case, when you set `AWS_PROFILE` to switch AWS profiles, ufo picks this up and maps the `AWS_PROFILE` value to the specified `UFO_ENV` using the `aws_profile_ufo_env_map` lookup. Example:
42
+
43
+ ```sh
44
+ AWS_PROFILE=my-prod-profile => UFO_ENV=prod
45
+ AWS_PROFILE=my-stag-profile => UFO_ENV=stag
46
+ AWS_PROFILE=default => UFO_ENV=dev
47
+ AWS_PROFILE=whatever => UFO_ENV=dev
48
+ ```
49
+
50
+ Notice how `AWS_PROFILE=whatever` results in `UFO_ENV=dev`. This is because the `default: dev` map is specially treated. If you set the `default` map, this becomes the default value when the profile map is not specified in the rest of `ufo/settings.yml`. More info on settings is available at [settings]({% link _docs/settings.md %}).
51
+
52
+ <a id="prev" class="btn btn-basic" href="{% link _docs/settings.md %}">Back</a>
53
+ <a id="next" class="btn btn-primary" href="{% link _docs/variables.md %}">Next Step</a>
54
+ <p class="keyboard-tip">Pro tip: Use the <- and -> arrow keys to move back and forward.</p>
@@ -11,7 +11,7 @@ Let's run the command in our newly clone project.
11
11
  ```sh
12
12
  git clone https://github.com/tongueroo/hi.git
13
13
  cd hi
14
- ufo init --app=hi --env stag --cluster=stag --image=tongueroo/hi
14
+ ufo init --app=hi --env prod --cluster=prod --image=tongueroo/hi
15
15
  ```
16
16
 
17
17
  You should see output similiar to this:
@@ -25,8 +25,12 @@ ufo
25
25
  ├── output
26
26
  ├── settings.yml
27
27
  ├── task_definitions.rb
28
- └── templates
29
- └── main.json.erb
28
+ ├── templates
29
+ └── main.json.erb
30
+ └── variables
31
+ ├── base.rb
32
+ ├── prod.rb
33
+ └── stag.rb
30
34
  ```
31
35
 
32
36
  The explanation of the folders and files were covered in detailed earlier at [Structure]({% link _docs/structure.md %}).
@@ -5,13 +5,13 @@ title: ufo scale
5
5
  Ufo provides a command to quickly scale up and down an ECS service. Here's an example of how you use it:
6
6
 
7
7
  ```sh
8
- ufo scale hi-web-stag 3
8
+ ufo scale hi-web
9
9
  ```
10
10
 
11
11
  You should get output similiar to below:
12
12
 
13
13
  ```sh
14
- Scale hi-web-stag service in stag cluster to 3
14
+ Scale hi-web service in stag cluster to 3
15
15
  ```
16
16
 
17
17
  While scaling via this method is quick and convenient the [ECS Service AutoScaling](http://docs.aws.amazon.com/AmazonECS/latest/developerguide/service-auto-scaling.html) that is built into ECS is a much more powerful way to manage scaling your ECS service.
@@ -15,13 +15,13 @@ As you can see there are plenty of options for `ufo ship`. Let's demonstrate us
15
15
  When you are deploying to a service with the word 'web' in it, ufo by convention assumes that this is a web service that uses a load balancer in front of it. This is also covered a in the [Conventions]({% link _docs/conventions.md %}) page. If you would you like to create a service with the word web without an load balancer associated with it you can use the `--no-target-group-prompt` option:
16
16
 
17
17
  ```sh
18
- ufo ship hi-web-stag --no-target-group-prompt
18
+ ufo ship hi-web --no-target-group-prompt
19
19
  ```
20
20
 
21
21
  Or if you would like specify the target-group up front and not be bother with the prompted later you can use the `--target-group` option.
22
22
 
23
23
  ```sh
24
- ufo ship hi-web-stag --target-group=arn:aws:elasticloadbalancing:us-east-1:12345689:targetgroup/hi-web-prod/12345
24
+ ufo ship hi-web --target-group=arn:aws:elasticloadbalancing:us-east-1:12345689:targetgroup/hi-web-prod/12345
25
25
  ```
26
26
 
27
27
  #### Deploying Existing Task Definition
@@ -29,7 +29,7 @@ ufo ship hi-web-stag --target-group=arn:aws:elasticloadbalancing:us-east-1:12345
29
29
  Let's say you already have built an registered a task definition by some other means and only want to use ufo to deploy that already registered task definition. You can do this by skipping the task build and register phase. It probably also makes sense to skip the docker phase in this case.
30
30
 
31
31
  ```sh
32
- ufo ship hi-web-stag --no-docker --no-tasks
32
+ ufo ship hi-web --no-docker --no-tasks
33
33
  ```
34
34
 
35
35
  #### Waiting for Deployments to Complete
@@ -37,15 +37,15 @@ ufo ship hi-web-stag --no-docker --no-tasks
37
37
  By default when ufo updates the ECS service with the new task definition it does so asynchronuously. You then normally visit the ECS service console and then refresh until you see that the deployment is completed. You can also have ufo poll and wait for the deployment to be done with the `--wait` option
38
38
 
39
39
  ```sh
40
- ufo ship hi-web-stag --wait
40
+ ufo ship hi-web --wait
41
41
  ```
42
42
 
43
43
  You should see output similar to this:
44
44
 
45
45
  ```sh
46
- Shipping hi-web-stag...
47
- hi-web-stag service updated on stag cluster with task hi-web-stag
48
- Waiting for deployment of task definition hi-web-stag:8 to complete
46
+ Shipping hi-web...
47
+ hi-web service updated on cluster with task hi-web
48
+ Waiting for deployment of task definition hi-web:8 to complete
49
49
  ......
50
50
  Time waiting for ECS deployment: 31s.
51
51
  Software shipped!
@@ -56,7 +56,7 @@ Software shipped!
56
56
  Since ufo builds the Docker image every time there's a deployment you will end up with a long list of docker images. Ufo automatically cleans up older docker images at the end of the deploy process if you are using AWS ECR. By default ufo keeps the most recent 30 Docker images. This can be adjust with the `--ecr-keep` option.
57
57
 
58
58
  ```sh
59
- docker ship hi-web-stag --ecr-keep 2
59
+ docker ship hi-web --ecr-keep 2
60
60
  ```
61
61
 
62
62
  You should see something like this:
@@ -11,7 +11,7 @@ The `ufo ships` command allows you to deploy the *same* Docker image and task de
11
11
  Instead of using the [ufo ship]({% link _docs/ufo-ship.md %}) and build and deploying the code 3 times you can instead use `ufo ships`. This will result in the *same* Docker image and *same* task definition being deployed to all 3 services. Example usage:
12
12
 
13
13
  ```sh
14
- ufo ships hi-web-stag hi-worker-stag hi-clock-stag
14
+ ufo ships hi-web hi-worker hi-clock
15
15
  ```
16
16
 
17
17
  ### Shell expansion
@@ -19,14 +19,14 @@ ufo ships hi-web-stag hi-worker-stag hi-clock-stag
19
19
  Since the ECS service names are provided as a list you can shorten the command by using bash shell expansion 😁
20
20
 
21
21
  ```sh
22
- ufo ships hi-{web,worker,clock}-stag
22
+ ufo ships hi-{web,worker,clock}
23
23
  ```
24
24
 
25
25
  If you're new to shell expansion, run this to understand why above works just as well:
26
26
 
27
27
  ```sh
28
- $ echo hi-{web,worker,clock}-stag
29
- hi-web-stag hi-worker-stag hi-clock-stag
28
+ $ echo hi-{web,worker,clock}
29
+ hi-web hi-worker hi-clock
30
30
  ```
31
31
 
32
32
  ### Overriding convention
@@ -56,49 +56,56 @@ Here's an example of each of them:
56
56
  **task_definitions.rb**:
57
57
 
58
58
  ```
59
- # common variables
60
- common = {
61
- image: helper.full_image_name, # includes the git sha tongueroo/hi:ufo-[sha].
62
- cpu: 128,
63
- memory_reservation: 256,
64
- environment: helper.env_file(".env")
65
- # another example
66
- # environment: helper.env_vars(%Q{
67
- # RAILS_ENV=production
68
- # SECRET_KEY_BASE=secret
69
- # })
70
- }
71
-
72
- task_definition "hi-web-stag" do
59
+ task_definition "hi-web" do
73
60
  source "main" # will use ufo/templates/main.json.erb
74
- variables(common.dup.deep_merge(
61
+ variables(
75
62
  family: task_definition_name,
76
63
  name: "web",
77
64
  container_port: helper.dockerfile_port,
78
65
  command: ["bin/web"]
79
- ))
66
+ )
80
67
  end
81
68
 
82
- task_definition "hi-worker-stag" do
69
+ task_definition "hi-worker" do
83
70
  source "main" # will use ufo/templates/main.json.erb
84
- variables(common.dup.deep_merge(
71
+ variables(
85
72
  family: task_definition_name,
86
73
  name: "worker",
87
74
  command: ["bin/worker"]
88
- ))
75
+ )
89
76
  end
90
77
 
91
- task_definition "hi-clock-stag" do
78
+ task_definition "hi-clock" do
92
79
  source "main" # will use ufo/templates/main.json.erb
93
- variables(common.dup.deep_merge(
80
+ variables(
94
81
  family: task_definition_name,
95
82
  name: "clock",
96
83
  command: ["bin/clock"]
97
- ))
84
+ )
98
85
  end
99
86
  ```
100
87
 
101
- Ufo uses the ERB template in `main.json.erb` and combines it with the variables defined in the task definition declarations in `task_definitions.rb` and generates the raw AWS formatted task definition in the `output` folder. In this case there are 3 task_definitions so there will be 3 generated output files.
88
+ The shared variables are set in the variables folder:
89
+
90
+ **ufo/variables/base.rb**:
91
+
92
+ ```ruby
93
+ @image = helper.full_image_name # includes the git sha tongueroo/hi:ufo-[sha].
94
+ @cpu = 128
95
+ @memory_reservation = 256
96
+ @environment = helper.env_file(".env")
97
+ ```
98
+
99
+ **ufo/variables/prod.rb**:
100
+
101
+ ```ruby
102
+ @environment = helper.env_vars(%Q{
103
+ RAILS_ENV=production
104
+ SECRET_KEY_BASE=secret
105
+ })
106
+ ```
107
+
108
+ Ufo combines the `main.json.erb` template, `task_definitions.rb` definitions, and variables in the `ufo/variables` folder. It then generates the raw AWS formatted task definition in the `output` folder.
102
109
 
103
110
  To build the task definitions:
104
111
 
@@ -108,13 +115,22 @@ ufo tasks build
108
115
 
109
116
  You should see output similar to below:
110
117
 
111
- <img src="/img/tutorials/ufo-tasks-build.png" class="doc-photo" />
118
+ ```sh
119
+ $ ufo tasks build
120
+ Building Task Definitions...
121
+ Generating Task Definitions:
122
+ ufo/output/hi-web.json
123
+ ufo/output/hi-worker.json
124
+ ufo/output/hi-clock.json
125
+ Task Definitions built in ufo/output.
126
+ $
127
+ ```
112
128
 
113
- Let's take a look at one of the generated files: `ufo/output/hi-web-stag.json`.
129
+ Let's take a look at one of the generated files: `ufo/output/hi-web.json`.
114
130
 
115
131
  ```json
116
132
  {
117
- "family": "hi-web-stag",
133
+ "family": "hi-web",
118
134
  "containerDefinitions": [
119
135
  {
120
136
  "name": "web",
@@ -11,9 +11,9 @@ ufo tasks register
11
11
  You should see something similiar to this:
12
12
 
13
13
  ```sh
14
- hi-clock-stag task definition registered.
15
- hi-web-stag task definition registered.
16
- hi-worker-stag task definition registered.
14
+ hi-clock task definition registered.
15
+ hi-web task definition registered.
16
+ hi-worker task definition registered.
17
17
  ```
18
18
 
19
19
  You can verify that the task definitions have been registered properly by viewing the AWS ECS Console Task Definitions page. You should see something similar to this:
@@ -0,0 +1,48 @@
1
+ ---
2
+ title: Shared Variables
3
+ ---
4
+
5
+ Often times, you end up using the set of common variables across your task definitions for a project. Ufo supports a shared variables concept to help with this. You specify variables files in the `ufo/variables` folder and they are made availale to your `ufo/task_definitions.rb` as well as your `ufo/templates` files.
6
+
7
+ For example, given `config/variables/base.rb`:
8
+
9
+ ```
10
+ @image = helper.full_image_name # includes the git sha tongueroo/hi:ufo-[sha].
11
+ @cpu = 128
12
+ @memory_reservation = 256
13
+ @environment = helper.env_file(".env")
14
+ ```
15
+
16
+ You can now use @image in your `ufo/templates/main.json.erb` without having to explicitly declaring them in the `ufo/task_definitions.rb` file. Variables are automatically made available to all templates and the `task_definition.rb` file also.
17
+
18
+ ### Layering
19
+
20
+ Shared variables also support a concept called layering. The `config/variables/base.rb` file is treated specially and will always be evaluated. Additionally, ufo will also evaluate the `config/variables/[UFO_ENV].rb` according to what UFO_ENV's value is. Thanks layering, you can easily override variables to suite different environments like production or staging. For example:
21
+
22
+ `config/variables/base.rb`:
23
+
24
+ ```ruby
25
+ @cpu = 128
26
+ ```
27
+
28
+ When `ufo ship` is ran with `UFO_ENV=prod` he `config/variables/prod.rb` will be evaluated and layered on top of the variables defined in `base.rb:
29
+
30
+ `config/variables/prod.rb`:
31
+
32
+ ```ruby
33
+ @cpu = 256
34
+ ```
35
+
36
+ When `ufo ship` is ran with `UFO_ENV=stag` he `config/variables/stag.rb` will be evaluated and layered on top of the variables defined in `base.rb:
37
+
38
+
39
+ `config/variables/stag.rb`:
40
+
41
+ ```ruby
42
+ @cpu = 192
43
+ ```
44
+
45
+
46
+ <a id="prev" class="btn btn-basic" href="{% link _docs/ufo-env.md %}">Back</a>
47
+ <a id="next" class="btn btn-primary" href="{% link _docs/helpers.md %}">Next Step</a>
48
+ <p class="keyboard-tip">Pro tip: Use the <- and -> arrow keys to move back and forward.</p>
@@ -35,6 +35,7 @@ ufo destroy
35
35
  {
36
36
  "name": "<%= @name %>",
37
37
  "image": "<%= @image %>",
38
+ <% if @cpu %>
38
39
  "cpu": <%= @cpu %>,
39
40
  <% end %>
40
41
  "command": <%= @command.to_json %>,
@@ -33,6 +33,8 @@
33
33
  </ul>
34
34
  </li>
35
35
  <li><a href="{% link _docs/settings.md %}">Settings</a></li>
36
+ <li><a href="{% link _docs/ufo-env.md %}">UFO_ENV</a></li>
37
+ <li><a href="{% link _docs/variables.md %}">Shared Variables</a></li>
36
38
  <li><a href="{% link _docs/helpers.md %}">Helpers</a></li>
37
39
  <li><a href="{% link _docs/conventions.md %}">Conventions</a></li>
38
40
  <li><a href="{% link _docs/run-in-pieces.md %}">Run In Pieces</a></li>
@@ -0,0 +1,4 @@
1
+ #!/bin/bash -ex
2
+
3
+ bundle exec jekyll clean
4
+ exec bundle exec jekyll serve
@@ -8,14 +8,32 @@ In a hurry? No sweat! Here's a quick start to using ufo that takes only a few mi
8
8
  brew cask install boltopslabs/software/bolts
9
9
  git clone https:///github.com/tongueroo/hi.git
10
10
  cd hi
11
- ufo init --app=hi --env stag --cluster=stag --image=tongueroo/hi
12
- ufo ship hi-web-stag
11
+ ufo init --app=hi --env prod --cluster=prod --image=tongueroo/hi
12
+ ufo ship hi-web
13
13
  ```
14
14
 
15
15
  You should see something similar to this:
16
16
 
17
- <img src="/img/tutorials/ufo-init.png" class="doc-photo" />
18
-
17
+ ```
18
+ $ ufo init --app=hi --env prod --cluster=prod --image=tongueroo/hi
19
+ Setting up ufo project...
20
+ created: ./bin/deploy
21
+ created: ./Dockerfile
22
+ created: ./ufo/settings.yml
23
+ created: ./ufo/task_definitions.rb
24
+ created: ./ufo/templates/main.json.erb
25
+ created: ./ufo/variables/base.rb
26
+ created: ./ufo/variables/prod.rb
27
+ created: ./ufo/variables/stag.rb
28
+ created: ./.env
29
+ Starter ufo files created.
30
+ $ ufo ship hi-web
31
+ Building docker image with:
32
+ docker build -t tongueroo/hi:ufo-2017-09-10T15-00-19-c781aaf -f Dockerfile .
33
+ ....
34
+ Software shipped!
35
+ $
36
+ ```
19
37
  Congratulations! You have successfully deployed code to AWS ECS with ufo. It was really that simple 😁
20
38
 
21
39
  Note: This quick start does require that you have a docker working on your environment. For docker installation instructions refer to to the official [docker installation guide](https://docs.docker.com/engine/installation/).
@@ -4,4 +4,4 @@
4
4
  # be overridden.
5
5
 
6
6
  # Only build one docker image and deploys it to multiple ECS services
7
- ufo ships <%= @app %>-{web,clock,worker}-<%= @env %> --cluster <%= @cluster %>
7
+ ufo ships <%= @app %>-{web,clock,worker} --cluster <%= @cluster %>
@@ -2,9 +2,17 @@
2
2
  image: <%= @image %>
3
3
  # clean_keep: 30
4
4
  # ecr_keep: 30
5
- service_cluster:
6
- default: <%= @cluster %> # default cluster
7
- # can override the default cluster for each service. CLI overrides all of these settings.
8
- <%= @app %>-web-<%= @env %>:
9
- <%= @app %>-clock-<%= @env %>:
10
- <%= @app %>-worker-<%= @env %>:
5
+
6
+ # aws_profile_ufo_env_map:
7
+ # default: prod
8
+ # # More examples:
9
+ # aws_profile1: prod
10
+ # aws_profile2: stag
11
+ # aws_profile3: dev
12
+
13
+ # ufo_env_cluster_map:
14
+ # default: prod
15
+ # # More examples:
16
+ # aws_profile1: prod
17
+ # aws_profile2: stag
18
+ # aws_profile3: dev