Class: Docker

Inherits:
Object
  • Object
show all
Defined in:
lib/docker.rb

Constant Summary collapse

MATERIAL_NAME =
ENV['MATERIAL_NAME'] || 'BITBUCKET'
SUDO =
!!ENV["GO_REVISION_#{MATERIAL_NAME}"]
BASEPATH =
Dir.pwd
GIT_COMMIT =
ENV['GO_REVISION_BITBUCKET'] || `git rev-parse HEAD`.strip
FIG_YML_PATH =
"#{BASEPATH}/fig.yml"
FIG_GEN_PATH =
"#{BASEPATH}/fig_gen.yml"

Class Method Summary collapse

Class Method Details

.buildObject



16
17
18
# File 'lib/docker.rb', line 16

def build
  build_docker_image_with_tag
end

.debugObject



20
21
22
23
# File 'lib/docker.rb', line 20

def debug
  generate_fig_yaml
  debug_app
end

.deployObject



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/docker.rb', line 33

def deploy
  required_envs = %w(GO_HOST GO_USER GO_PWD)
  unless required_envs.reduce{ |acc, e| acc && ENV[e] }
    error!(
      RuntimeError.new("Environment variables {#{required_envs.join(', ')}} must be set"),
      'triggering pipeline'
    )
  end
  deploy_stages.each do |deploy_stage|
    schedule_pipeline(project_name, deploy_stage, git_image_name)
  end
end

.deploy_stagesObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/docker.rb', line 46

def deploy_stages
  candidates = Dir['deploy-to*']
  if candidates.size == 1
    script = candidates.first
    if File.executable?(script)
      branch = ENV['GIT_BRANCH'] ||
        `git symbolic-ref --short -q HEAD`.strip
      return `./#{script} #{branch}`.strip.split(',')
    else
      error!(
        RuntimeError.new(
          %(Deploy-to script: "#{script}" must be executable! (e.g. chmod +x #{script}))
        ),
        "determining stage to deploy to"
      )
    end
  else
    error!(
      RuntimeError.new(
        "There must be a deploy-to* script " +
        "(e.g. deploy-to.{rb|sh|js}): #{candidates.size} found"
      ),
      "determining stage to deploy to"
    )
  end
end

.purgeObject



25
26
27
# File 'lib/docker.rb', line 25

def purge
  run_with_output("docker rm $(docker ps -a -q) && docker rmi $(docker images -q)")
end

.pushObject



29
30
31
# File 'lib/docker.rb', line 29

def push
  run_with_output("docker push #{git_image_name.tr(':',' ')}")
end

.runObject



73
74
75
76
# File 'lib/docker.rb', line 73

def run
  generate_fig_yaml
  run_app
end

.testObject



78
79
80
81
# File 'lib/docker.rb', line 78

def test
  generate_fig_yaml
  run_tests
end

.versionObject Also known as: v



83
84
85
# File 'lib/docker.rb', line 83

def version
  puts "v#{VERSION}"
end