lib/hako/schedulers/ecs.rb in hako-0.10.0 vs lib/hako/schedulers/ecs.rb in hako-0.11.0

- old
+ new

@@ -224,28 +224,50 @@ task_definition = @ecs.describe_task_definition(task_definition: family).task_definition container_definitions = {} task_definition.container_definitions.each do |c| container_definitions[c.name] = c end + + if different_volumes?(task_definition.volumes) + return true + end if definitions.any? { |definition| different_definition?(definition, container_definitions.delete(definition[:name])) } return true end !container_definitions.empty? rescue Aws::ECS::Errors::ClientException # Task definition does not exist true end + def different_volumes?(actual_volumes) + if @volumes.size != actual_volumes.size + return true + end + actual_volumes.each do |actual_volume| + expected_volume = @volumes[actual_volume.name] + if expected_volume.nil? + return true + end + if expected_volume['source_path'] != actual_volume.host.source_path + return true + end + end + + false + end + def different_definition?(expected_container, actual_container) EcsDefinitionComparator.new(expected_container).different?(actual_container) end def register_task_definition(definitions) if task_definition_changed?(@app_id, definitions) @ecs.register_task_definition( family: @app_id, container_definitions: definitions, + volumes: volumes_definition, ).task_definition else :noop end end @@ -265,16 +287,26 @@ family = "#{@app_id}-oneshot" if task_definition_changed?(family, definitions) @ecs.register_task_definition( family: "#{@app_id}-oneshot", container_definitions: definitions, + volumes: volumes_definition, ).task_definition else :noop end end + def volumes_definition + @volumes.map do |name, volume| + { + name: name, + host: { source_path: volume['source_path'] }, + } + end + end + def front_container(front, front_port) environment = front.env.map { |k, v| { name: k, value: v } } { name: 'front', image: front.image_tag, @@ -283,10 +315,11 @@ links: front.links, port_mappings: [{ container_port: 80, host_port: front_port, protocol: 'tcp' }], essential: true, environment: environment, docker_labels: front.docker_labels, + mount_points: front.mount_points, } end def app_container(name, app) environment = app.env.map { |k, v| { name: k, value: v } } @@ -298,9 +331,10 @@ links: app.links, port_mappings: [], essential: true, environment: environment, docker_labels: app.docker_labels, + mount_points: app.mount_points, } end def run_task(task_definition, commands, env) environment = env.map { |k, v| { name: k, value: v } }