lib/hako/schedulers/ecs.rb in hako-0.4.0 vs lib/hako/schedulers/ecs.rb in hako-0.5.0
- old
+ new
@@ -12,37 +12,30 @@
def initialize(app_id, options)
@app_id = app_id
@cluster = options.fetch('cluster', DEFAULT_CLUSTER)
@desired_count = options.fetch('desired_count') { validation_error!('desired_count must be set') }
- @cpu = options.fetch('cpu') { validation_error!('cpu must be set') }
- @memory = options.fetch('memory') { validation_error!('memory must be set') }
region = options.fetch('region') { validation_error!('region must be set') }
@role = options.fetch('role', nil)
@ecs = Aws::ECS::Client.new(region: region)
@elb = EcsElb.new(app_id, Aws::ElasticLoadBalancing::Client.new(region: region), options.fetch('elb', nil))
@ec2 = Aws::EC2::Client.new(region: region)
end
- def deploy(containers, env, app_port, force: false)
+ def deploy(containers, force: false)
@force_mode = force
app = containers.fetch('app')
front = containers.fetch('front')
- front_env = {
- 'AWS_DEFAULT_REGION' => front.config.s3.region,
- 'S3_CONFIG_BUCKET' => front.config.s3.bucket,
- 'S3_CONFIG_KEY' => front.config.s3.key(@app_id),
- }
front_port = determine_front_port
- task_definition = register_task_definition(app, env, front.config, front_env, front_port)
+ task_definition = register_task_definition(containers, front_port)
if task_definition == :noop
Hako.logger.info "Task definition isn't changed"
task_definition = @ecs.describe_task_definition(task_definition: @app_id).task_definition
else
Hako.logger.info "Registered task definition: #{task_definition.task_definition_arn}"
- upload_front_config(@app_id, front, app_port)
- Hako.logger.info "Uploaded front configuration to s3://#{front.config.s3.bucket}/#{front.config.s3.key(@app_id)}"
+ upload_front_config(@app_id, front, app.port)
+ Hako.logger.info "Uploaded front configuration to s3://#{front.s3.bucket}/#{front.s3.key(@app_id)}"
end
service = create_or_update_service(task_definition.task_definition_arn, front_port)
if service == :noop
Hako.logger.info "Service isn't changed"
else
@@ -50,14 +43,14 @@
wait_for_ready(service)
end
Hako.logger.info 'Deployment completed'
end
- def oneshot(app, env, commands)
+ def oneshot(app, commands)
task_definition = register_task_definition_for_oneshot(app)
Hako.logger.info "Registered task definition: #{task_definition.task_definition_arn}"
- task = run_task(task_definition, env, commands)
+ task = run_task(task_definition, app.env, commands)
Hako.logger.info "Started task: #{task.task_arn}"
exit_code = wait_for_task(task)
Hako.logger.info 'Oneshot task finished'
exit_code
end
@@ -195,13 +188,13 @@
def different_definition?(expected_container, actual_container)
EcsDefinitionComparator.new(expected_container).different?(actual_container)
end
- def register_task_definition(app, env, front_config, front_env, front_port)
- front_def = front_container(front_config, front_env, front_port)
- app_def = app_container(app, env)
+ def register_task_definition(containers, front_port)
+ front_def = front_container(containers.fetch('front'), front_port)
+ app_def = app_container(containers.fetch('app'))
if task_definition_changed?(front_def, app_def)
@ecs.register_task_definition(
family: @app_id,
container_definitions: [front_def, app_def],
).task_definition
@@ -215,41 +208,41 @@
family: "#{@app_id}-oneshot",
container_definitions: [
{
name: 'oneshot',
image: app.image_tag,
- cpu: @cpu,
- memory: @memory,
+ cpu: app.cpu,
+ memory: app.memory,
links: [],
port_mappings: [],
environment: [],
},
],
).task_definition
end
- def front_container(front_config, env, front_port)
- environment = env.map { |k, v| { name: k, value: v } }
+ def front_container(front, front_port)
+ environment = front.env.map { |k, v| { name: k, value: v } }
{
name: 'front',
- image: front_config.container.image_tag,
- cpu: 100,
- memory: 100,
+ image: front.image_tag,
+ cpu: front.cpu,
+ memory: front.memory,
links: ['app:app'],
port_mappings: [{ container_port: 80, host_port: front_port, protocol: 'tcp' }],
essential: true,
environment: environment,
- docker_labels: front_config.container.docker_labels,
+ docker_labels: front.docker_labels,
}
end
- def app_container(app, env)
- environment = env.map { |k, v| { name: k, value: v } }
+ def app_container(app)
+ environment = app.env.map { |k, v| { name: k, value: v } }
{
name: 'app',
image: app.image_tag,
- cpu: @cpu,
- memory: @memory,
+ cpu: app.cpu,
+ memory: app.memory,
links: [],
port_mappings: [],
essential: true,
environment: environment,
docker_labels: app.docker_labels,