-
Notifications
You must be signed in to change notification settings - Fork 26
/
docker_build.rb
97 lines (81 loc) · 2.86 KB
/
docker_build.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# frozen_string_literal: true
require "buildkite-builder"
module Buildkite::Config
class DockerBuild < Buildkite::Builder::Extension
module Step
def cache_from(build_context)
sources = []
if build_context.rebuild_id
sources << build_context.image_name_for(build_context.rebuild_id)
end
if build_context.pull_request
sources << build_context.image_name_for("pr-#{build_context.pull_request}")
end
if build_context.local_branch && build_context.local_branch !~ /:/
sources << build_context.image_name_for("br-#{build_context.local_branch}")
end
if build_context.base_branch
sources << build_context.image_name_for("br-#{build_context.base_branch}")
end
sources << build_context.image_name_for("br-main")
sources.grep(String).uniq
end
def build_push(build_context)
[
build_context.local_branch =~ /:/ ?
build_context.image_name_for("pr-#{build_context.pull_request}") :
build_context.image_name_for("br-#{build_context.local_branch}"),
]
end
end
def prepare
::Buildkite::Pipelines::Steps::Command.prepend(DockerBuild::Step)
end
dsl do
def builder(ruby)
build_context = context.extensions.find(BuildContext)
build_context.ruby = ruby
return unless build_context.ruby.build?
command do
label ":docker: #{build_context.ruby.prefix}#{build_context.ruby.version}"
key "docker-image-#{build_context.ruby.image_key}"
plugin :artifacts, {
download: ".dockerignore"
}
plugin :artifacts, {
download: %w[
.buildkite/.empty
.buildkite/docker-compose.yml
.buildkite/Dockerfile
.buildkite/Dockerfile.beanstalkd
.buildkite/mysql-initdb.d
.buildkite/runner
],
compressed: ".buildkite.tgz"
}
plugin :docker_compose, {
build: "base",
config: ".buildkite/docker-compose.yml",
env: %w[PRE_STEPS RACK],
"image-name" => build_context.ruby.image_name_for(build_context.build_id),
"cache-from" => cache_from(build_context),
push: build_push(build_context),
"image-repository" => build_context.image_base,
}
env({
BUNDLER: build_context.bundler,
RUBYGEMS: build_context.rubygems,
RUBY_IMAGE: build_context.ruby.ruby_image,
encrypted_0fb9444d0374_key: nil,
encrypted_0fb9444d0374_iv: nil
})
timeout_in_minutes 15
if build_context.ruby.soft_fail?
soft_fail true
end
agents queue: build_context.build_queue
end
end
end
end
end