Class: GithubSnapBuilder::DockerBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/github_snap_builder/builder_implementations/docker.rb

Instance Method Summary collapse

Constructor Details

#initialize(logger, base) ⇒ DockerBuilder

Returns a new instance of DockerBuilder.



8
9
10
11
12
13
14
15
16
17
# File 'lib/github_snap_builder/builder_implementations/docker.rb', line 8

def initialize(logger, base)
	@logger = logger
	@base = base

	begin
		Docker.validate_version!
	rescue Excon::Error::Socket
		raise DockerVersionError
	end
end

Instance Method Details

#build(project_directory) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/github_snap_builder/builder_implementations/docker.rb', line 19

def build(project_directory)
	# Snapcraft will detect if it's in a docker container and default to
	# destructive mode.
	run(['sh', '-c', "apt update -qq && snapcraft"], {
		'Env' => ['SNAPCRAFT_MANAGED_HOST=yes'],
		'WorkingDir' => '/snapcraft',
		'HostConfig' => {
			'Binds' => ["#{project_directory}:/snapcraft"],
			'AutoRemove' => true,
		}
	})
end

#release(snap_path, token, channel) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/github_snap_builder/builder_implementations/docker.rb', line 32

def release(snap_path, token, channel)
	run(['sh', '-c', "snapcraft login --with /token && snapcraft push #{File.basename(snap_path).shellescape} --release=#{channel.shellescape}"], {
		'Env' => ['SNAPCRAFT_MANAGED_HOST=yes'],
		'WorkingDir' => '/snapcraft',
		'HostConfig' => {
			'Binds' => ["#{File.dirname(snap_path)}:/snapcraft"],
			'AutoRemove' => true,
		}
	}) do |container|
		container.store_file("/token", token)
	end
end