putpaws 0.1.5 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,31 +1,25 @@
1
- require 'json'
2
1
  require 'pathname'
2
+ require 'putpaws/config_file'
3
3
 
4
+ # A network part (.putpaws/infra.json: network.<name>).
5
+ # Parts do not belong to an environment; they are shared by all of them.
4
6
  class Putpaws::InfraNetworkConfig < Struct.new(
5
7
  :name, :subnets, :security_groups, :assign_public_ip,
6
8
  keyword_init: true)
7
- def self.load(path_prefix: '.putpaws')
8
- @infra_network_data ||= begin
9
- path = Pathname.new(path_prefix).join("infra.json").to_s
10
- data = File.exist?(path) ?
11
- JSON.parse(File.read(path), symbolize_names: true).to_h :
12
- {}
13
- data[:network] || {}
14
- end
9
+ def self.load(path_prefix: Putpaws::ConfigFile.root)
10
+ data = Putpaws::ConfigFile.read(Pathname.new(path_prefix).join("infra.json"))
11
+ data[:network] || {}
15
12
  end
16
13
 
17
- def self.all
18
- load.map{|k,v|
19
- data = v.slice(*self.members)
20
- new(data.merge(name: k.to_s))
14
+ def self.all(path_prefix: Putpaws::ConfigFile.root)
15
+ load(path_prefix: path_prefix).map{|k, v|
16
+ new(v.slice(*members).merge(name: k.to_s))
21
17
  }
22
18
  end
23
19
 
24
- def self.find(name)
25
- infra_network_data = load
26
- data = infra_network_data[name.to_sym]
20
+ def self.find(name, path_prefix: Putpaws::ConfigFile.root)
21
+ data = load(path_prefix: path_prefix)[name.to_sym]
27
22
  return nil unless data
28
- data = data.slice(*self.members)
29
- new(data.merge({name: name.to_s}))
23
+ new(data.slice(*members).merge(name: name.to_s))
30
24
  end
31
25
  end
@@ -1,35 +1,42 @@
1
- require 'json'
2
1
  require 'pathname'
2
+ require 'putpaws/config_file'
3
3
 
4
+ # A target part (.putpaws/infra.json: target.<name>): which task definition
5
+ # to start on which cluster. Parts do not belong to an environment.
4
6
  class Putpaws::InfraTargetConfig < Struct.new(
5
- :name,
7
+ :name,
6
8
  :scheduler_role,
7
9
  :cluster,
8
10
  :task_definition,
9
11
  :container_name,
10
12
  keyword_init: true)
11
- def self.load(path_prefix: '.putpaws')
12
- @infra_target_data ||= begin
13
- path = Pathname.new(path_prefix).join("infra.json").to_s
14
- data = File.exist?(path) ?
15
- JSON.parse(File.read(path), symbolize_names: true).to_h :
16
- {}
17
- data[:target] || {}
18
- end
13
+ def self.load(path_prefix: Putpaws::ConfigFile.root)
14
+ data = Putpaws::ConfigFile.read(Pathname.new(path_prefix).join("infra.json"))
15
+ data[:target] || {}
19
16
  end
20
17
 
21
- def self.all
22
- load.map{|k,v|
23
- data = v.slice(*self.members)
24
- new(data.merge(name: k.to_s))
18
+ def self.all(path_prefix: Putpaws::ConfigFile.root)
19
+ load(path_prefix: path_prefix).map{|k, v|
20
+ new(v.slice(*members).merge(name: k.to_s))
25
21
  }
26
22
  end
27
23
 
28
- def self.find(name)
29
- infra_target_data = load
30
- data = infra_target_data[name.to_sym]
24
+ def self.find(name, path_prefix: Putpaws::ConfigFile.root)
25
+ data = load(path_prefix: path_prefix)[name.to_sym]
31
26
  return nil unless data
32
- data = data.slice(*self.members)
33
- new(data.merge({name: name.to_s}))
27
+ new(data.slice(*members).merge(name: name.to_s))
28
+ end
29
+
30
+ def cluster_arn?
31
+ cluster.to_s.start_with?('arn:')
32
+ end
33
+
34
+ # Region of the cluster ARN. nil when `cluster` is a bare name.
35
+ def cluster_region
36
+ cluster_arn? ? cluster.to_s.split(':')[3] : nil
37
+ end
38
+
39
+ def cluster_name
40
+ cluster.to_s.split('/').last
34
41
  end
35
42
  end
@@ -0,0 +1,141 @@
1
+ require 'putpaws/config_file'
2
+
3
+ # A named launch (.putpaws/<environment>/launch.json): which task definition
4
+ # to start on which network, with which overrides. `ecs:run`, `ecs:shell` and
5
+ # the scheduler all refer to the same launches by name.
6
+ #
7
+ # Only what ECS lets you decide when starting a task can be written here.
8
+ # Image, sidecars and log destination belong to the task definition.
9
+ class Putpaws::LaunchConfig
10
+ FILENAME = 'launch.json'
11
+ FIELDS = %i[
12
+ target network
13
+ command container env
14
+ cpu memory ephemeral_storage
15
+ task_role capacity_provider
16
+ ]
17
+ REQUIRED = %i[target network]
18
+ INTEGER_FIELDS = %i[cpu memory ephemeral_storage]
19
+ STRING_FIELDS = %i[target network container task_role]
20
+ CAPACITY_PROVIDERS = %w[FARGATE FARGATE_SPOT]
21
+ NAME_PATTERN = /\A[A-Za-z0-9][A-Za-z0-9_\-]*\z/
22
+
23
+ attr_reader :name, :attributes
24
+
25
+ def self.path(application)
26
+ application.dir.join(FILENAME)
27
+ end
28
+
29
+ def self.load(application)
30
+ Putpaws::ConfigFile.read(path(application))
31
+ end
32
+
33
+ def self.all(application)
34
+ file = path(application)
35
+ load(application).map{|name, attrs|
36
+ new(name: name, attributes: attrs, context: "launch `#{name}` (#{file})")
37
+ }
38
+ end
39
+
40
+ def self.find(application, name)
41
+ attrs = load(application)[name.to_sym]
42
+ return nil unless attrs
43
+ new(name: name, attributes: attrs, context: "launch `#{name}` (#{path(application)})")
44
+ end
45
+
46
+ def self.find!(application, name)
47
+ find(application, name) or raise Putpaws::ConfigError,
48
+ "Launch not found: #{name} (#{path(application)})\n" +
49
+ "Available: #{names(application).join(', ')}"
50
+ end
51
+
52
+ def self.names(application)
53
+ load(application).keys.map(&:to_s)
54
+ end
55
+
56
+ # Save one launch under the given name. Other launches are kept as they are.
57
+ # Overwrites silently: ask the user first when the name already exists.
58
+ def self.save!(application, name, attributes)
59
+ unless name.to_s.match?(NAME_PATTERN)
60
+ raise Putpaws::ConfigError, "Invalid launch name: #{name} (letters, numbers, `-` and `_` only)"
61
+ end
62
+ attrs = normalize(attributes, context: "launch `#{name}`", required: true)
63
+ file = path(application)
64
+ data = load(application)
65
+ data[name.to_sym] = attrs
66
+ Putpaws::ConfigFile.write(file, data)
67
+ file
68
+ end
69
+
70
+ # Validate and normalize launch fields. Returns a Hash in FIELDS order
71
+ # without blank values. Unknown fields are an error: a setting that is
72
+ # silently ignored would look like it works.
73
+ def self.normalize(attributes, context:, required: false)
74
+ unless attributes.is_a?(Hash)
75
+ raise Putpaws::ConfigError, "#{context} must be a JSON object"
76
+ end
77
+ attrs = attributes.map{|k, v| [k.to_sym, v]}.to_h
78
+ unknown = attrs.keys - FIELDS
79
+ unless unknown.empty?
80
+ raise Putpaws::ConfigError,
81
+ "Unknown field #{unknown.map{|k| "`#{k}`"}.join(', ')} in #{context}. Available: #{FIELDS.join(', ')}"
82
+ end
83
+
84
+ normalized = {}
85
+ FIELDS.each do |field|
86
+ value = attrs[field]
87
+ next if blank?(value)
88
+ normalized[field] = normalize_field(field, value, context)
89
+ end
90
+ if required
91
+ missing = REQUIRED - normalized.keys
92
+ unless missing.empty?
93
+ raise Putpaws::ConfigError, "#{context} needs #{missing.map{|k| "`#{k}`"}.join(' and ')}"
94
+ end
95
+ end
96
+ normalized
97
+ end
98
+
99
+ def self.normalize_field(field, value, context)
100
+ if STRING_FIELDS.include?(field)
101
+ raise Putpaws::ConfigError, "`#{field}` must be a string in #{context}" unless value.is_a?(String)
102
+ value.strip
103
+ elsif INTEGER_FIELDS.include?(field)
104
+ unless value.is_a?(Integer) || value.to_s.match?(/\A\d+\z/)
105
+ raise Putpaws::ConfigError, "`#{field}` must be an integer in #{context}: #{value.inspect}"
106
+ end
107
+ value.to_i
108
+ elsif field == :command
109
+ valid = value.is_a?(String) || (value.is_a?(Array) && !value.empty? && value.all?{|x| x.is_a?(String)})
110
+ raise Putpaws::ConfigError, "`command` must be a string or an array of strings in #{context}" unless valid
111
+ value
112
+ elsif field == :env
113
+ raise Putpaws::ConfigError, "`env` must be an object like {\"NAME\": \"value\"} in #{context}" unless value.is_a?(Hash)
114
+ value.map{|k, v| [k.to_s, v.to_s]}.to_h
115
+ elsif field == :capacity_provider
116
+ provider = value.to_s.upcase
117
+ unless CAPACITY_PROVIDERS.include?(provider)
118
+ raise Putpaws::ConfigError,
119
+ "`capacity_provider` must be one of #{CAPACITY_PROVIDERS.join(' / ')} in #{context}: #{value.inspect}"
120
+ end
121
+ provider
122
+ end
123
+ end
124
+
125
+ def self.blank?(value)
126
+ value.nil? || (value.respond_to?(:empty?) && value.empty?) || (value.is_a?(String) && value.strip.empty?)
127
+ end
128
+
129
+ def initialize(name:, attributes:, context: nil)
130
+ @name = name.to_s
131
+ @attributes = self.class.normalize(attributes, context: context || "launch `#{name}`", required: true)
132
+ end
133
+
134
+ FIELDS.each do |field|
135
+ define_method(field){ attributes[field] }
136
+ end
137
+
138
+ def to_h
139
+ attributes.dup
140
+ end
141
+ end
@@ -0,0 +1,104 @@
1
+ require 'putpaws/config_file'
2
+ require 'putpaws/launch_config'
3
+ require 'putpaws/resolved_launch'
4
+ require 'putpaws/infra_network_config'
5
+ require 'putpaws/infra_target_config'
6
+
7
+ # Builds the launch that actually gets started. Later layers win, field by field:
8
+ #
9
+ # 1. defaults of the task definition (putpaws passes nothing)
10
+ # 2. the named launch of the environment (launch.json)
11
+ # 3. for a schedule: the overrides written in schedule.json
12
+ # 4. for a manual run: the command-line parameters
13
+ #
14
+ # `env` is merged name by name; every other field is replaced as a whole.
15
+ # `ecs:run`, `ecs:shell` and the scheduler all go through here.
16
+ class Putpaws::LaunchResolver
17
+ def self.resolve(application:, launch: nil, overrides: [])
18
+ new(application: application, launch: launch, overrides: overrides).resolve
19
+ end
20
+
21
+ attr_reader :application, :launch, :overrides
22
+
23
+ # launch: Putpaws::LaunchConfig or nil (assemble on the spot)
24
+ # overrides: a Hash, or an Array of Hashes applied in order
25
+ def initialize(application:, launch: nil, overrides: [])
26
+ @application = application
27
+ @launch = launch
28
+ @overrides = overrides.is_a?(Hash) ? [overrides] : overrides.compact
29
+ end
30
+
31
+ def path_prefix
32
+ application.path_prefix || Putpaws::ConfigFile.root
33
+ end
34
+
35
+ def resolve
36
+ attributes = merged_attributes
37
+ missing = Putpaws::LaunchConfig::REQUIRED - attributes.keys
38
+ unless missing.empty?
39
+ raise Putpaws::ConfigError,
40
+ "The launch has no #{missing.map{|k| "`#{k}`"}.join(' and ')}. " +
41
+ "Pass launch=<name> (see `launch:list`), or both target=<name> and network=<name>."
42
+ end
43
+
44
+ target = Putpaws::InfraTargetConfig.find(attributes[:target], path_prefix: path_prefix)
45
+ unless target
46
+ raise Putpaws::ConfigError, "target `#{attributes[:target]}` is not defined in #{infra_path}\n" +
47
+ "Available: #{Putpaws::InfraTargetConfig.all(path_prefix: path_prefix).map(&:name).join(', ')}"
48
+ end
49
+ network = Putpaws::InfraNetworkConfig.find(attributes[:network], path_prefix: path_prefix)
50
+ unless network
51
+ raise Putpaws::ConfigError, "network `#{attributes[:network]}` is not defined in #{infra_path}\n" +
52
+ "Available: #{Putpaws::InfraNetworkConfig.all(path_prefix: path_prefix).map(&:name).join(', ')}"
53
+ end
54
+ check_environment!(target)
55
+
56
+ Putpaws::ResolvedLaunch.new(
57
+ application: application,
58
+ attributes: attributes,
59
+ target: target,
60
+ network: network,
61
+ )
62
+ end
63
+
64
+ def merged_attributes
65
+ layers = []
66
+ layers << launch.attributes if launch
67
+ overrides.each do |layer|
68
+ layers << Putpaws::LaunchConfig.normalize(layer, context: "the overrides")
69
+ end
70
+ merged = layers.reduce({}) do |result, layer|
71
+ env = (result[:env] || {}).merge(layer[:env] || {})
72
+ result = result.merge(layer)
73
+ result[:env] = env unless env.empty?
74
+ result
75
+ end
76
+ # Keep a stable field order whatever the layers looked like.
77
+ Putpaws::LaunchConfig::FIELDS.select{|f| merged.key?(f)}.map{|f| [f, merged[f]]}.to_h
78
+ end
79
+
80
+ private
81
+
82
+ def infra_path
83
+ File.join(path_prefix.to_s, 'infra.json')
84
+ end
85
+
86
+ # Parts do not know environments, so a launch could point at the parts of
87
+ # another environment by mistake. Stop here when the cluster of the target
88
+ # is not the cluster of this environment.
89
+ def check_environment!(target)
90
+ if target.cluster.to_s.strip.empty?
91
+ raise Putpaws::ConfigError, "target `#{target.name}` has no `cluster` (#{infra_path})"
92
+ end
93
+ env_region = application.ecs_region || application.region
94
+ env_cluster = application.cluster.to_s.split('/').last
95
+ region = target.cluster_region
96
+ return if (region.nil? || region == env_region) && target.cluster_name == env_cluster
97
+
98
+ raise Putpaws::ConfigError,
99
+ "target `#{target.name}` does not belong to environment `#{application.name}`.\n" +
100
+ " target cluster: #{target.cluster}\n" +
101
+ " environment cluster: #{env_cluster} (region: #{env_region})\n" +
102
+ "Check `target` of the launch, or `region` / `cluster` in #{application.dir.join('application.json')}"
103
+ end
104
+ end
@@ -1,22 +1,27 @@
1
1
  require 'json'
2
2
  require 'fileutils'
3
3
  require 'pathname'
4
+ require 'putpaws/config_file'
5
+ require 'putpaws/application_config'
6
+ require 'putpaws/launch_config'
4
7
  require 'putpaws/provision/util'
5
8
 
6
9
  module Putpaws
7
10
  module Provision
8
- # Reflects provisioned resources into .putpaws/application.json and
9
- # .putpaws/infra.json. Only the keys of the target service are touched.
10
- # Shows a diff and asks for confirmation before writing.
11
+ # Reflects provisioned resources into the operation settings under
12
+ # .putpaws/. The service name is the environment name.
11
13
  #
12
- # One application entry and one infra.target entry are written per task
13
- # definition of the preset, keyed by the task definition family
14
- # (`<service_name>-<suffix>`). The entry whose suffix is the preset's
15
- # `service_task_definition` carries `service` so that ecs:deploy /
16
- # ecs:attach address the long-running service; the others are for
17
- # one-off tasks (ecs:run / ecs:shell / scheduler) and have `service: null`.
18
- # infra.network is written once per service as it does not depend on the
19
- # task definition.
14
+ # `up` writes only what it knows the right answer for, and never overrides
15
+ # a choice made by the user:
16
+ #
17
+ # <service_name>/application.json generated / updated (the keys putpaws knows; others are kept)
18
+ # infra.json network.<service_name> generated / updated
19
+ # infra.json target.<family> generated / updated, one per task definition of the preset
20
+ # <service_name>/launch.json a launch per task definition is ADDED when its name is absent;
21
+ # existing launches are never rewritten
22
+ # <service_name>/schedule.json never touched
23
+ #
24
+ # Updates show a diff and ask for confirmation before writing.
20
25
  class ConfigWriter
21
26
  attr_reader :config, :state, :prompt, :io
22
27
  def initialize(config:, state:, prompt:, io: $stdout)
@@ -26,18 +31,17 @@ module Putpaws
26
31
  @io = io
27
32
  end
28
33
 
29
- def application_entry(entry)
30
- family = config.task_definition_family(entry[:suffix])
34
+ # Operating what is running: one set per environment. Prefixes are the
35
+ # service name so that tasks of every task definition (-app / -web ...) are found.
36
+ def application_entry
31
37
  {
32
38
  region: config.region,
33
39
  cluster: config.cluster_name,
34
- service: service_entry?(entry) ? config.service_name : nil,
35
- task_name_prefix: family,
40
+ service: config.service_name,
41
+ task_name_prefix: config.service_name,
36
42
  log_group_prefix: config.log_group,
37
- build_log_group_prefix: config.build_log_group,
38
43
  build_project_name_prefix: config.build_project_name,
39
- network: config.service_name,
40
- target: family,
44
+ build_log_group_prefix: config.build_log_group,
41
45
  }
42
46
  end
43
47
 
@@ -60,45 +64,102 @@ module Putpaws
60
64
  }
61
65
  end
62
66
 
67
+ # The default launch of a task definition, named after its suffix.
68
+ def launch_entry(entry)
69
+ {
70
+ target: config.task_definition_family(entry[:suffix]),
71
+ network: config.service_name,
72
+ }
73
+ end
74
+
63
75
  def apply!
76
+ write_application
64
77
  write_key(path('infra.json'), [:network, config.service_name.to_sym], network_entry)
65
78
  config.preset.task_definitions.each do |entry|
66
79
  key = config.task_definition_family(entry[:suffix]).to_sym
67
- write_key(path('application.json'), [key], application_entry(entry))
68
80
  write_key(path('infra.json'), [:target, key], target_entry(entry))
69
81
  end
82
+ add_missing_launches
70
83
  end
71
84
 
72
- private
73
-
74
- def service_entry?(entry)
75
- entry[:suffix] == config.preset.service_task_definition
85
+ # Files of the 0.1.x layout are neither read nor deleted. Just say so.
86
+ def notify_legacy
87
+ ConfigFile.legacy_files(path_prefix: config.path_prefix).each do |file|
88
+ io.puts "[notice] #{file} is a legacy (0.1.x) file and is no longer read. Please delete it."
89
+ end
76
90
  end
77
91
 
92
+ private
93
+
78
94
  def path(basename)
79
95
  Pathname.new(config.path_prefix).join(basename)
80
96
  end
81
97
 
98
+ def environment_path(basename)
99
+ ApplicationConfig.dir_for(config.service_name, path_prefix: config.path_prefix).join(basename)
100
+ end
101
+
102
+ # Only the keys putpaws knows are compared and written, so optional keys
103
+ # added by hand (ecs_region / log_region / build_region) survive.
104
+ def write_application
105
+ file = environment_path(ApplicationConfig::FILENAME)
106
+ current = ConfigFile.read(file)
107
+ desired = current.merge(application_entry)
108
+ return if current == desired
109
+
110
+ show_diff(file, nil, current.empty? ? nil : current, desired)
111
+ return unless confirm(file)
112
+ backup(file)
113
+ ConfigFile.write(file, desired)
114
+ io.puts "Updated #{file}"
115
+ end
116
+
82
117
  def write_key(file, keys, entry)
83
- data = file.exist? ? JSON.parse(File.read(file), symbolize_names: true) : {}
118
+ data = ConfigFile.read(file)
84
119
  current = keys.reduce(data){|d, k| d.is_a?(Hash) ? d[k] : nil}
85
120
  return if current == entry
86
121
 
87
- io.puts "=== #{file} : #{keys.join('.')} ==="
122
+ show_diff(file, keys, current, entry)
123
+ return unless confirm(file)
124
+ backup(file)
125
+ parent = keys[0..-2].reduce(data){|d, k| d[k] ||= {}}
126
+ parent[keys.last] = entry
127
+ ConfigFile.write(file, data)
128
+ io.puts "Updated #{file}"
129
+ end
130
+
131
+ # Adding never overrides anything, so it is done without asking.
132
+ def add_missing_launches
133
+ file = environment_path(LaunchConfig::FILENAME)
134
+ data = ConfigFile.read(file)
135
+ added = []
136
+ config.preset.task_definitions.each do |entry|
137
+ name = entry[:suffix].to_sym
138
+ next if data.key?(name)
139
+ data[name] = launch_entry(entry)
140
+ added << name
141
+ end
142
+ return if added.empty?
143
+ ConfigFile.write(file, data)
144
+ io.puts "Added launch #{added.map{|n| "`#{n}`"}.join(', ')} to #{file}"
145
+ end
146
+
147
+ def show_diff(file, keys, current, entry)
148
+ io.puts keys ? "=== #{file} : #{keys.join('.')} ===" : "=== #{file} ==="
88
149
  io.puts "--- before"
89
150
  io.puts current ? JSON.pretty_generate(current) : "(none)"
90
151
  io.puts "+++ after"
91
152
  io.puts JSON.pretty_generate(entry)
92
- unless prompt.yes?("Update #{file}?")
93
- io.puts "Skipped updating #{file}"
94
- return
95
- end
153
+ end
96
154
 
97
- FileUtils.cp(file, "#{file}.bak") if file.exist?
98
- parent = keys[0..-2].reduce(data){|d, k| d[k] ||= {}}
99
- parent[keys.last] = entry
100
- Util.write_json(file, data)
101
- io.puts "Updated #{file}"
155
+ def confirm(file)
156
+ return true if prompt.yes?("Update #{file}?")
157
+ io.puts "Skipped updating #{file}"
158
+ false
159
+ end
160
+
161
+ def backup(file)
162
+ FileUtils.cp(file, "#{file}.bak") if File.exist?(file)
102
163
  end
103
164
  end
104
165
  end
@@ -6,6 +6,8 @@ module Putpaws
6
6
  module Provision
7
7
  class Preset
8
8
  BUILTIN_DIR = File.expand_path('presets', __dir__)
9
+ # Preselected on `ready`: Rails 8 with Thruster, app container only.
10
+ DEFAULT = 'rails'
9
11
 
10
12
  def self.local_dir(path_prefix: '.putpaws')
11
13
  Pathname.new(path_prefix).join('provisioning', 'presets')
@@ -0,0 +1,35 @@
1
+ {
2
+ "defaults": {
3
+ "cpu_architecture": "ARM64",
4
+ "cpu": "256",
5
+ "memory": "512",
6
+ "desired_count": 1,
7
+ "container_port": 8080,
8
+ "log_retention_days": 30,
9
+ "image_tag": "latest",
10
+ "assign_public_ip": "DISABLED",
11
+ "env": {
12
+ "RAILS_ENV": "production",
13
+ "RACK_ENV": "production",
14
+ "RAILS_LOG_TO_STDOUT": "1",
15
+ "HTTP_PORT": "8080"
16
+ },
17
+ "secrets": {
18
+ "RAILS_MASTER_KEY": "{ssm_parameter_prefix}/RAILS_MASTER_KEY"
19
+ }
20
+ },
21
+ "task_definitions": [
22
+ { "suffix": "app", "template": "taskdef-app.json.erb", "container_name": "app" }
23
+ ],
24
+ "service_task_definition": "app",
25
+ "devops_defaults": {
26
+ "source_type": "GITHUB",
27
+ "environment_images": {
28
+ "ARM64": "aws/codebuild/amazonlinux-aarch64-standard:3.0",
29
+ "X86_64": "aws/codebuild/standard:7.0"
30
+ },
31
+ "compute_type": "BUILD_GENERAL1_SMALL",
32
+ "privileged_mode": true,
33
+ "buildspec": "buildspec.yml"
34
+ }
35
+ }
@@ -0,0 +1,33 @@
1
+ {
2
+ "family": "<%= service_name %>-app",
3
+ "requiresCompatibilities": ["FARGATE"],
4
+ "networkMode": "awsvpc",
5
+ "runtimePlatform": {
6
+ "cpuArchitecture": "<%= cpu_architecture %>",
7
+ "operatingSystemFamily": "LINUX"
8
+ },
9
+ "cpu": "<%= cpu %>",
10
+ "memory": "<%= memory %>",
11
+ "executionRoleArn": "<%= execution_role_arn %>",
12
+ "taskRoleArn": "<%= task_role_arn %>",
13
+ "containerDefinitions": [
14
+ {
15
+ "name": "app",
16
+ "image": "<%= image %>",
17
+ "essential": true,
18
+ "portMappings": [
19
+ { "containerPort": <%= container_port %>, "protocol": "tcp" }
20
+ ],
21
+ "environment": <%= env_json %>,
22
+ "secrets": <%= secrets_json %>,
23
+ "logConfiguration": {
24
+ "logDriver": "awslogs",
25
+ "options": {
26
+ "awslogs-group": "<%= log_group %>",
27
+ "awslogs-region": "<%= region %>",
28
+ "awslogs-stream-prefix": "app"
29
+ }
30
+ }
31
+ }
32
+ ]
33
+ }
@@ -152,7 +152,9 @@ module Putpaws
152
152
  apply_resources(service_resources)
153
153
  state.mark_step!(:service, 'done')
154
154
 
155
- ConfigWriter.new(config: config, state: state, prompt: prompt, io: io).apply!
155
+ writer = ConfigWriter.new(config: config, state: state, prompt: prompt, io: io)
156
+ writer.apply!
157
+ writer.notify_legacy
156
158
 
157
159
  if missing_devops_requirements.any?
158
160
  io.puts "[stop point] Devops step is not ready. Fill in: #{missing_devops_requirements.join(', ')}"
@@ -166,7 +168,7 @@ module Putpaws
166
168
  ConfigWriter.new(config: config, state: state, prompt: prompt, io: io).apply!
167
169
 
168
170
  io.puts "All steps completed."
169
- io.puts "Verify with: bundle exec putpaws #{config.service_name} ecs:run cmd='echo ok' wait=true"
171
+ io.puts "Verify with: bundle exec putpaws #{config.service_name} ecs:run launch=#{config.preset.service_task_definition} cmd='echo ok' wait=true"
170
172
  end
171
173
 
172
174
  private
@@ -8,7 +8,7 @@ namespace :provision do
8
8
  prompt = Putpaws::Prompt.safe
9
9
  util = Putpaws::Provision::Util
10
10
 
11
- service_name = ENV['service'] || prompt.ask("Application name (Ex: awesome-api-staging):") do |q|
11
+ service_name = ENV['service'] || prompt.ask("Service name, which becomes the environment name (Ex: awesome-api-staging):") do |q|
12
12
  q.required(true)
13
13
  q.validate(/\A[a-z0-9][a-z0-9\-]*\z/, "lowercase letters, numbers and hyphens only")
14
14
  end
@@ -22,8 +22,10 @@ namespace :provision do
22
22
  end
23
23
 
24
24
  region = prompt.ask("Region:", default: 'ap-northeast-1')
25
- preset_choices = Putpaws::Provision::Preset.catalog.map{|e| ["#{e[:name]} (#{e[:source]})", e[:name]]}.to_h
26
- preset_name = prompt.select("Preset:", preset_choices)
25
+ preset_catalog = Putpaws::Provision::Preset.catalog
26
+ preset_choices = preset_catalog.map{|e| ["#{e[:name]} (#{e[:source]})", e[:name]]}.to_h
27
+ preset_default = (preset_catalog.index{|e| e[:name] == Putpaws::Provision::Preset::DEFAULT} || 0) + 1
28
+ preset_name = prompt.select("Preset:", preset_choices, default: preset_default)
27
29
 
28
30
  puts "--- Basic infra (existing resources; used to generate IAM policies) ---"
29
31
  vpc_id = prompt.ask("VPC ID:"){|q| q.required(true)}