Skip to content
Snippets Groups Projects
Commit 0d07b9a9 authored by Marin Jankovski's avatar Marin Jankovski
Browse files

Merge branch '2667-increase-docker-timeout' into 'master'

Increase docker operations timeout

Closes #2667

See merge request !1846
parents 9665fbdb a0e27943
No related branches found
No related tags found
1 merge request!1846Increase docker operations timeout
require 'docker'
 
class DockerOperations
def self.set_timeout
timeout = ENV['DOCKER_TIMEOUT'] || 1200
Docker.options = { read_timeout: timeout, write_timeout: timeout }
end
def self.build(location, image, tag)
Docker.options[:read_timeout] = 600
set_timeout
Docker::Image.build_from_dir(location.to_s, { t: "#{image}:#{tag}", pull: true }) do |chunk|
if (log = JSON.parse(chunk)) && log.key?("stream")
puts log["stream"]
Loading
Loading
@@ -31,10 +36,12 @@ class DockerOperations
end
 
def self.get(namespace, tag)
set_timeout
Docker::Image.get("#{namespace}:#{tag}")
end
 
def self.push(namespace, tag)
set_timeout
image = get(namespace, tag)
image.push(Docker.creds, repo_tag: "#{namespace}:#{tag}") do |chunk|
puts chunk
Loading
Loading
@@ -42,6 +49,7 @@ class DockerOperations
end
 
def self.tag(initial_namespace, new_namespace, initial_tag, new_tag)
set_timeout
image = get(initial_namespace, initial_tag)
image.tag(repo: new_namespace, tag: new_tag, force: true)
end
Loading
Loading
require 'chef_helper'
require_relative '../../../lib/gitlab/docker_operations.rb'
 
describe 'docker', type: :rake do
before :all do
Loading
Loading
@@ -97,3 +98,21 @@ describe 'docker', type: :rake do
end
end
end
describe 'docker_operations' do
describe 'without docker operations timeout variable' do
it 'sets default value as timeout' do
DockerOperations.set_timeout
expect(Docker.options[:read_timeout]).to eq(1200)
end
end
describe 'with docker operations timeout variable specified' do
it 'sets provided value as timeout' do
allow(ENV).to receive(:[]).and_call_original
allow(ENV).to receive(:[]).with('DOCKER_TIMEOUT').and_return(500)
DockerOperations.set_timeout
expect(Docker.options[:read_timeout]).to eq(500)
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment