lib/dockly/deb.rb in dockly-3.4.1 vs lib/dockly/deb.rb in dockly-4.0.0
- old
+ new
@@ -75,11 +75,10 @@
info "#{name}: could not find package: #{s3_url}"
false
end
def upload_to_s3
- info "uploading to s3"
return if s3_bucket.nil?
raise "Package wasn't created!" unless File.exist?(build_path)
info "uploading package to s3"
File.open(build_path, 'rb') do |file|
Dockly.s3.put_object(
@@ -179,62 +178,82 @@
package.attributes[:prefix] = nil
end
end
def add_docker_auth_config(package)
- return if (registry = get_registry).nil? || !registry.authentication_required?
+ return if (registry = get_registry).nil? || !should_auth?(registry)
info "adding docker config file"
registry.generate_config_file!
package.attributes[:prefix] = registry.auth_config_file || "~#{app_user}"
Dir.chdir(File.dirname(registry.config_file)) do
package.input(File.basename(registry.config_file))
end
package.attributes[:prefix] = nil
end
+ def should_auth?(registry)
+ registry.is_a?(Dockly::Docker::Registry) &&
+ registry.authentication_required?
+ end
+
def add_docker(package)
return if docker.nil? || docker.s3_bucket
info "adding docker image"
docker.generate!
- return unless docker.registry.nil?
+
+ return if get_registry
+
package.attributes[:prefix] = docker.package_dir
Dir.chdir(File.dirname(docker.tar_path)) do
package.input(File.basename(docker.tar_path))
end
package.attributes[:prefix] = nil
end
def get_registry
- if docker && registry = docker.registry
+ if docker && (registry = docker.registry)
registry
end
end
def post_startup_script
scripts = ["#!/bin/bash"]
bb = Dockly::BashBuilder.new
scripts << bb.normalize_for_dockly
- if get_registry
- scripts << bb.registry_import(docker.repo, docker.tag)
- elsif docker
- if docker.s3_bucket.nil?
- docker_output = File.join(docker.package_dir, docker.export_filename)
- if docker.tar_diff
- scripts << bb.file_diff_docker_import(docker.import, docker_output, docker.name, docker.tag)
- else
- scripts << bb.file_docker_import(docker_output, docker.name, docker.tag)
+
+ if docker
+ if (registry = docker.registry)
+ if registry.is_a?(Dockly::Docker::ECR)
+ scripts << bb.auth_ecr(registry.server_address)
end
+ scripts << bb.registry_import(docker.repo, docker.tag)
else
- if docker.tar_diff
- scripts << bb.s3_diff_docker_import(docker.import, docker.s3_url, docker.name, docker.tag)
- else
- scripts << bb.s3_docker_import(docker.s3_url, docker.name, docker.tag)
- end
+ scripts += collect_non_registry_scripts(bb)
end
- scripts << bb.docker_tag_latest(docker.repo, docker.tag)
end
+
scripts.join("\n")
+ end
+
+ def collect_non_registry_scripts(bb)
+ scripts = []
+
+ if docker.s3_bucket.nil?
+ docker_output = File.join(docker.package_dir, docker.export_filename)
+ if docker.tar_diff
+ scripts << bb.file_diff_docker_import(docker.import, docker_output, docker.name, docker.tag)
+ else
+ scripts << bb.file_docker_import(docker_output, docker.name, docker.tag)
+ end
+ else
+ if docker.tar_diff
+ scripts << bb.s3_diff_docker_import(docker.import, docker.s3_url, docker.name, docker.tag)
+ else
+ scripts << bb.s3_docker_import(docker.s3_url, docker.name, docker.tag)
+ end
+ end
+ scripts << bb.docker_tag_latest(docker.repo, docker.tag)
end
def add_startup_script(package, startup_script = "dockly-startup.sh")
ensure_present! :build_dir
startup_script_path = File.join(build_dir, startup_script)