Class: DG::Docker

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

Constant Summary collapse

MATERIAL_NAME =
ENV['MATERIAL_NAME'] || 'BITBUCKET'
SUDO =
!!ENV["GO_REVISION_#{MATERIAL_NAME}"]
BASEPATH =
Dir.pwd
FIG_YML_PATH =
"#{BASEPATH}/fig.yml"
FIG_GEN_PATH =
"#{BASEPATH}/fig_gen.yml"

Class Method Summary collapse

Class Method Details

.buildObject



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

def build
  build_docker_image_with_tag
end

.debugObject



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

def debug
  generate_fig_yaml
  debug_app
end

.deployObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/dg/docker.rb', line 34

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

  puts "Triggering deploys for: #{deploy_stages.inspect}"

  deploy_stages.each do |deploy_stage|
    schedule_pipeline(project_name, deploy_stage, git_image_name)
  end
end

.deploy_stagesObject



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/dg/docker.rb', line 50

def deploy_stages
  @@deploy_stages_cached ||=
    begin
      generate_fig_yaml
      branch = ENV['GIT_BRANCH'] ||
        `git symbolic-ref --short -q HEAD`.strip

      run_with_output(
        "docker run --entrypoint=/bin/sh #{git_image_name} /u/app/deploy-to.sh", capture = true
      ).strip.split(',')
    end
end

.purgeObject



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

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

.pushObject



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

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

.runObject



63
64
65
66
# File 'lib/dg/docker.rb', line 63

def run
  generate_fig_yaml
  run_app
end

.testObject



68
69
70
71
# File 'lib/dg/docker.rb', line 68

def test
  generate_fig_yaml
  run_tests
end

.versionObject Also known as: v



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

def version
  puts "v#{DG::VERSION}"
end