Skip to content

Commit 59cca09

Browse files
Support podman in tasks/build.rake
Support podman in addition to docker in tasks/build.rake via the DOCKER environment variable.
1 parent 04116c0 commit 59cca09

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

tasks/build.rake

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,28 +49,43 @@ DEP_BUILD_ORDER = [
4949
'trapperkeeper-comidi-metrics',
5050
].freeze
5151

52+
# somewhat annoyingly, with --format=json there are differences between
53+
# podman and docker. Docker will output one JSON record per line, but podman
54+
# will put everything into an array. Do something simple that can handle both.
55+
def non_empty(output)
56+
if output.strip.empty?
57+
return true
58+
end
59+
60+
begin
61+
return !JSON.parse(output).empty?
62+
rescue JSON::ParseError => e
63+
return false
64+
end
65+
end
66+
5267
def image_exists
53-
!`docker images -q #{@image}`.strip.empty?
68+
non_empty(`${DOCKER-docker} images -q #{@image} --format=json`)
5469
end
5570

5671
def container_exists
57-
!`docker container ls --all --filter 'name=#{@container}' --format json`.strip.empty?
72+
non_empty(`${DOCKER-docker} container ls --all --filter 'name=#{@container}' --format=json`)
5873
end
5974

6075
def teardown
6176
if container_exists
6277
puts "Stopping #{@container}"
63-
run_command("docker stop #{@container}", silent: false, print_command: true)
64-
run_command("docker rm #{@container}", silent: false, print_command: true)
78+
run_command("${DOCKER-docker} stop #{@container}", silent: false, print_command: true)
79+
run_command("${DOCKER-docker} rm #{@container}", silent: false, print_command: true)
6580
end
6681
end
6782

6883
def start_container(ezbake_dir)
69-
run_command("docker run -d --name #{@container} -v .:/code -v #{ezbake_dir}:/deps #{@image} /bin/sh -c 'tail -f /dev/null'", silent: false, print_command: true)
84+
run_command("${DOCKER-docker} run -d --name #{@container} -v .:/code -v #{ezbake_dir}:/deps #{@image} /bin/sh -c 'tail -f /dev/null'", silent: false, print_command: true)
7085
end
7186

7287
def run(cmd)
73-
run_command("docker exec #{@container} /bin/bash --login -c '#{cmd}'", silent: false, print_command: true)
88+
run_command("${DOCKER-docker} exec #{@container} /bin/bash --login -c '#{cmd}'", silent: false, print_command: true)
7489
end
7590

7691
namespace :vox do
@@ -89,7 +104,7 @@ namespace :vox do
89104
# delete all containers and do `docker rmi ezbake-builder`
90105
unless image_exists
91106
puts "Building ezbake-builder image"
92-
run_command("docker build -t ezbake-builder .", silent: false, print_command: true)
107+
run_command("${DOCKER-docker} build -t ezbake-builder .", silent: false, print_command: true)
93108
end
94109

95110
libs_to_build_manually = {}

0 commit comments

Comments
 (0)