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
# File 'lib/dg/docker.rb', line 50

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

  run_with_output(
    "fig -f #{FIG_GEN_PATH} run deployto", capture = true
  ).strip.split(',')
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



60
61
62
63
# File 'lib/dg/docker.rb', line 60

def run
  generate_fig_yaml
  run_app
end

.testObject



65
66
67
68
# File 'lib/dg/docker.rb', line 65

def test
  generate_fig_yaml
  run_tests
end

.versionObject Also known as: v



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

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