summaryrefslogtreecommitdiff
path: root/qa/qa/service/docker_run/node_js.rb
blob: 642f1d1a33a5d366ef74690b180b2b31b4626e7d (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
# frozen_string_literal: true

module QA
  module Service
    module DockerRun
      class NodeJs < Base
        def initialize(volume_host_path)
          @image = 'node:12.11.1-alpine'
          @name = "qa-node-#{SecureRandom.hex(8)}"
          @volume_host_path = volume_host_path

          super()
        end

        def publish!
          # When we run the tests via gitlab-qa, we use docker-in-docker
          # which means that host of a volume mount would be the host that
          # started the gitlab-qa QA container (e.g., the CI runner),
          # not the gitlab-qa container itself. That means we can't
          # mount a volume from the file system inside the gitlab-qa
          # container.
          #
          # Instead, we copy the files into the container.
          shell <<~CMD.tr("\n", ' ')
            docker run -d --rm
            --network #{network}
            --hostname #{host_name}
            --name #{@name}
            --volume #{@volume_host_path}:/home/node
            #{@image} sh -c "sleep 60"
          CMD
          shell "docker cp #{@volume_host_path}/. #{@name}:/home/node"
          shell "docker exec -t #{@name} sh -c 'cd /home/node && npm publish'"
        end
      end
    end
  end
end