diff options
| author | mo khan <mo.khan@gmail.com> | 2020-09-14 16:59:36 -0600 |
|---|---|---|
| committer | mo khan <mo.khan@gmail.com> | 2020-09-14 16:59:36 -0600 |
| commit | 853ae09d4c6d0220a3f77492065961e65f96e860 (patch) | |
| tree | 6986ed03dfa7545d483c980a31b0ce83582a2811 /lib/e2e/docker.rb | |
| parent | 0dc0c0cec97cbdea04e278143e4711cfa0d3bd03 (diff) | |
chore: move classes into lib dir
Diffstat (limited to 'lib/e2e/docker.rb')
| -rw-r--r-- | lib/e2e/docker.rb | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/e2e/docker.rb b/lib/e2e/docker.rb new file mode 100644 index 0000000..3c4d589 --- /dev/null +++ b/lib/e2e/docker.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +class Docker + DEFAULT_ENV = { + 'CI_DEBUG_TRACE' => 'true', + 'CI_PROJECT_DIR' => '/tmp/app', + 'SECURE_LOG_LEVEL' => 'debug' + }.freeze + attr_reader :pwd + + def initialize(pwd: Pathname.pwd) + @pwd = pwd + end + + def build(tag:) + Dir.chdir pwd do + system("docker build --network=host -t #{tag} .") + end + end + + def run(image:, project_path: Pathname.pwd, env: {}) + env_options = DEFAULT_ENV.merge(env).map { |(key, value)| "--env #{key}=#{value}" } + command = expand([:docker, :run, '-it', '--rm', "--volume=#{project_path}:/tmp/app", '--network=host', env_options, image, '/analyzer run']) + Dir.chdir pwd do + system(command, exception: true) + end + end + + private + + def expand(command) + command.flatten.map(&:to_s).join(' ') + end +end |
