summaryrefslogtreecommitdiff
path: root/lib/jive/docker.rb
blob: 584afe67990e202006cba848a3035ad1bd6b9297 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# frozen_string_literal: true

module Jive
  class Docker
    attr_reader :shell

    def initialize(shell = ::Jive.shell)
      @shell = shell
    end

    def build(path)
      shell.execute([
        "docker",
        "build",
        "--network=host",
        "-t", image_tag_for(path),
        "."
      ], env: { "DOCKER_BUILDKIT" => "1" })
    end

    def launch(path)
      shell.execute([
        "docker",
        "run",
        "--network=host",
        '--entrypoint=""',
        "-it", image_tag_for(path),
        "/bin/bash -l"
      ])
    end

    def size(path)
      shell.execute([
        :docker, "image", "inspect", '--format="{{.Size}}"',
        image_tag_for(path)
      ])
    end

    private

    def image_tag_for(path)
      "#{path.basename.to_s.downcase}:latest"
    end
  end
end