Skip to content

Commit 527be1e

Browse files
committed
chore(builder): change DRYCC_BUILD_TYPE to DRYCC_STACK
1 parent a0a9c45 commit 527be1e

8 files changed

Lines changed: 131 additions & 77 deletions

File tree

boot.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,8 @@ import (
77

88
"github.com/codegangsta/cli"
99
storagedriver "github.com/docker/distribution/registry/storage/driver"
10-
_ "github.com/docker/distribution/registry/storage/driver/azure"
1110
"github.com/docker/distribution/registry/storage/driver/factory"
12-
_ "github.com/docker/distribution/registry/storage/driver/gcs"
1311
_ "github.com/docker/distribution/registry/storage/driver/s3-aws"
14-
_ "github.com/docker/distribution/registry/storage/driver/swift"
1512
"github.com/drycc/builder/pkg"
1613
"github.com/drycc/builder/pkg/cleaner"
1714
"github.com/drycc/builder/pkg/conf"

charts/builder/templates/builder-deployment.yaml

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,26 +60,16 @@ spec:
6060
# Set GIT_LOCK_TIMEOUT to number of minutes you want to wait to git push again to the same repository
6161
- name: "GIT_LOCK_TIMEOUT"
6262
value: "10"
63-
- name: "SLUGBUILDER_IMAGE_NAME"
63+
- name: SLUGBUILDER_IMAGE_PULL_POLICY
6464
valueFrom:
6565
configMapKeyRef:
6666
name: slugbuilder-config
67-
key: image
68-
- name: SLUG_BUILDER_IMAGE_PULL_POLICY
69-
valueFrom:
70-
configMapKeyRef:
71-
name: slugbuilder-config
72-
key: pullpolicy
73-
- name: "DOCKERBUILDER_IMAGE_NAME"
74-
valueFrom:
75-
configMapKeyRef:
76-
name: dockerbuilder-config
77-
key: image
78-
- name: DOCKER_BUILDER_IMAGE_PULL_POLICY
67+
key: pull_policy
68+
- name: DOCKERBUILDER_IMAGE_PULL_POLICY
7969
valueFrom:
8070
configMapKeyRef:
8171
name: dockerbuilder-config
82-
key: pullpolicy
72+
key: pull_policy
8373
# This var needs to be passed so that the minio client (https://github.com/minio/mc) will work in Alpine linux
8474
- name: "DOCKERIMAGE"
8575
value: "1"
@@ -120,6 +110,12 @@ spec:
120110
- name: objectstore-creds
121111
mountPath: /var/run/secrets/drycc/objectstore/creds
122112
readOnly: true
113+
- name: slugbuilder-config
114+
mountPath: /etc/slugbuilder
115+
readOnly: true
116+
- name: dockerbuilder-config
117+
mountPath: /etc/dockerbuilder
118+
readOnly: true
123119
volumes:
124120
- name: builder-key-auth
125121
secret:
@@ -130,3 +126,9 @@ spec:
130126
- name: objectstore-creds
131127
secret:
132128
secretName: objectstorage-keyfile
129+
- name: slugbuilder-config
130+
configMap:
131+
name: slugbuilder-config
132+
- name: dockerbuilder-config
133+
configMap:
134+
name: dockerbuilder-config

pkg/gitreceive/build.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,7 @@ func build(
142142
return fmt.Errorf("running %s (%s)", strings.Join(tarCmd.Args, " "), err)
143143
}
144144

145-
bType := getBuildType(tmpDir, appConf)
146-
usingDockerfile := bType == buildTypeDockerbuilder
145+
stack := getStack(tmpDir, appConf)
147146

148147
appTgzdata, err := ioutil.ReadFile(absAppTgz)
149148
if err != nil {
@@ -165,7 +164,7 @@ func build(
165164
return fmt.Errorf("error build builder pod node selector %s", err)
166165
}
167166

168-
if usingDockerfile {
167+
if strings.Contains(stack["name"], "container") {
169168
buildPodName = dockerBuilderPodName(appName, gitSha.Short())
170169
registryLocation := conf.RegistryLocation
171170
registryEnv := make(map[string]string)
@@ -187,7 +186,7 @@ func build(
187186
gitSha.Short(),
188187
slugName,
189188
conf.StorageType,
190-
conf.DockerBuilderImage,
189+
stack["image"],
191190
conf.RegistryHost,
192191
conf.RegistryPort,
193192
registryEnv,
@@ -222,7 +221,7 @@ func build(
222221
gitSha.Short(),
223222
buildPackURL,
224223
conf.StorageType,
225-
conf.SlugBuilderImage,
224+
stack["image"],
226225
slugBuilderImagePullPolicy,
227226
builderPodNodeSelector,
228227
)
@@ -297,7 +296,7 @@ func build(
297296
}
298297
log.Debug("Done")
299298

300-
procType, err := getProcFile(storageDriver, tmpDir, slugBuilderInfo.AbsoluteProcfileKey(), bType)
299+
procType, err := getProcFile(storageDriver, tmpDir, slugBuilderInfo.AbsoluteProcfileKey(), stack)
301300
if err != nil {
302301
return err
303302
}
@@ -306,10 +305,10 @@ func build(
306305

307306
quit := progress("...", conf.SessionIdleInterval())
308307
log.Info("Launching App...")
309-
if !usingDockerfile {
308+
if stack["name"] != "container" {
310309
image = slugBuilderInfo.AbsoluteSlugObjectKey()
311310
}
312-
release, err := hooks.CreateBuild(client, conf.Username, conf.App(), image, gitSha.Short(), procType, usingDockerfile)
311+
release, err := hooks.CreateBuild(client, conf.Username, conf.App(), image, gitSha.Short(), procType, stack["name"] == "container")
313312
quit <- true
314313
<-quit
315314
if controller.CheckAPICompat(client, err) != nil {
@@ -351,7 +350,7 @@ func prettyPrintJSON(data interface{}) (string, error) {
351350
return formatted.String(), nil
352351
}
353352

354-
func getProcFile(getter storage.ObjectGetter, dirName, procfileKey string, bType buildType) (dryccAPI.ProcessType, error) {
353+
func getProcFile(getter storage.ObjectGetter, dirName, procfileKey string, stack map[string]string) (dryccAPI.ProcessType, error) {
355354
procType := dryccAPI.ProcessType{}
356355
if _, err := os.Stat(fmt.Sprintf("%s/Procfile", dirName)); err == nil {
357356
rawProcFile, err := ioutil.ReadFile(fmt.Sprintf("%s/Procfile", dirName))
@@ -363,7 +362,7 @@ func getProcFile(getter storage.ObjectGetter, dirName, procfileKey string, bType
363362
}
364363
return procType, nil
365364
}
366-
if bType != buildTypeSlugbuilder {
365+
if stack["name"] == "container" {
367366
return procType, nil
368367
}
369368
log.Debug("Procfile not present. Getting it from the buildpack")

pkg/gitreceive/build_test.go

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,11 @@ func TestGetProcFileFromRepoSuccess(t *testing.T) {
122122
}
123123
}()
124124
getter := &storage.FakeObjectGetter{}
125-
procType, err := getProcFile(getter, tmpDir, objKey, buildTypeSlugbuilder)
125+
config := api.Config{}
126+
config.Values = map[string]interface{}{
127+
"DRYCC_STACK": "heroku-18",
128+
}
129+
procType, err := getProcFile(getter, tmpDir, objKey, getStack(tmpDir, config))
126130
actualData := api.ProcessType{}
127131
yaml.Unmarshal(data, &actualData)
128132
assert.NoErr(t, err)
@@ -144,7 +148,11 @@ func TestGetProcFileFromRepoFailure(t *testing.T) {
144148
}
145149
}()
146150
getter := &storage.FakeObjectGetter{}
147-
_, err = getProcFile(getter, tmpDir, objKey, buildTypeSlugbuilder)
151+
config := api.Config{}
152+
config.Values = map[string]interface{}{
153+
"DRYCC_STACK": "heroku-18",
154+
}
155+
_, err = getProcFile(getter, tmpDir, objKey, getStack(tmpDir, config))
148156

149157
assert.True(t, err != nil, "no error received when there should have been")
150158
}
@@ -156,8 +164,13 @@ func TestGetProcFileFromServerSuccess(t *testing.T) {
156164
return data, nil
157165
},
158166
}
167+
tmpDir := os.TempDir()
168+
config := api.Config{}
169+
config.Values = map[string]interface{}{
170+
"DRYCC_STACK": "heroku-18",
171+
}
159172

160-
procType, err := getProcFile(getter, "", objKey, buildTypeSlugbuilder)
173+
procType, err := getProcFile(getter, "", objKey, getStack(tmpDir, config))
161174
actualData := api.ProcessType{}
162175
yaml.Unmarshal(data, &actualData)
163176
assert.NoErr(t, err)
@@ -171,8 +184,12 @@ func TestGetProcFileFromServerFailure(t *testing.T) {
171184
return []byte("web: example-go"), expectedErr
172185
},
173186
}
174-
175-
_, err := getProcFile(getter, "", objKey, buildTypeSlugbuilder)
187+
tmpDir := os.TempDir()
188+
config := api.Config{}
189+
config.Values = map[string]interface{}{
190+
"DRYCC_STACK": "heroku-18",
191+
}
192+
_, err := getProcFile(getter, "", objKey, getStack(tmpDir, config))
176193
assert.Err(t, err, fmt.Errorf("error in reading %s (%s)", objKey, expectedErr))
177194
assert.True(t, err != nil, "no error received when there should have been")
178195
}

pkg/gitreceive/build_type.go

Lines changed: 65 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,85 @@
11
package gitreceive
22

33
import (
4+
"encoding/json"
45
"fmt"
56
"github.com/drycc/controller-sdk-go/api"
7+
"io/ioutil"
68
"os"
9+
"strings"
710
)
811

9-
type buildType string
12+
// defaultStacks is default stacks json, order represents priority
13+
var defaultStacks = `[
14+
{
15+
"name": "container",
16+
"image": "drycc/container:canary"
17+
},
18+
{
19+
"name": "heroku-18",
20+
"image": "drycc/slugrunner:canary.heroku-18"
21+
},
22+
{
23+
"name": "heroku-16",
24+
"image": "drycc/slugrunner:canary.heroku-16"
25+
}
1026
11-
func (b buildType) String() string {
12-
return string(b)
13-
}
27+
]`
1428

15-
const (
16-
buildTypeSlugbuilder buildType = "slugbuilder"
17-
buildTypeDockerbuilder buildType = "dockerbuilder"
18-
)
29+
// Stacks for drycc
30+
var Stacks []map[string]string
1931

20-
func getBuildType(dirName string, config api.Config) buildType {
32+
// initStack load stack by config
33+
func initStack() error {
34+
data, err := ioutil.ReadFile("/etc/slugbuilder/images.json")
35+
if err == nil {
36+
var stacksSlugbuilder []map[string]string
37+
err = json.Unmarshal(data, &stacksSlugbuilder)
38+
if err == nil {
39+
data, err = ioutil.ReadFile("/etc/dockerbuilder/images.json")
40+
if err == nil {
41+
var stacksDockerbuilder []map[string]string
42+
err = json.Unmarshal(data, &stacksDockerbuilder)
43+
if err == nil {
44+
// Stacks order represents priority
45+
Stacks = stacksDockerbuilder
46+
Stacks = append(Stacks, stacksSlugbuilder...)
47+
}
48+
return nil
49+
}
50+
}
51+
}
52+
return json.Unmarshal([]byte(defaultStacks), &Stacks)
53+
}
54+
55+
func getStack(dirName string, config api.Config) map[string]string {
56+
if len(Stacks) == 0 {
57+
initStack()
58+
}
59+
if stackInterface, ok := config.Values["DRYCC_STACK"]; ok {
60+
if strStack, ok := stackInterface.(string); ok {
61+
for _, stack := range Stacks {
62+
if stack["name"] == strStack {
63+
return stack
64+
}
65+
}
66+
}
67+
}
2168

22-
hasDockerfile := false
2369
if _, err := os.Stat(fmt.Sprintf("%s/Dockerfile", dirName)); err == nil {
24-
hasDockerfile = true
70+
for _, stack := range Stacks {
71+
if strings.Contains(stack["name"], "container") {
72+
return stack
73+
}
74+
}
2575
}
2676

27-
hasProcfile := false
2877
if _, err := os.Stat(fmt.Sprintf("%s/Procfile", dirName)); err == nil {
29-
hasProcfile = true
30-
}
31-
if hasDockerfile && hasProcfile {
32-
if bTypeInterface, ok := config.Values["DRYCC_BUILDER"]; ok {
33-
if strType, ok := bTypeInterface.(string); ok {
34-
bType := buildType(strType)
35-
if bType == buildTypeSlugbuilder || bType == buildTypeDockerbuilder {
36-
return bType
37-
}
78+
for _, stack := range Stacks {
79+
if strings.Contains(stack["name"], "heroku") {
80+
return stack
3881
}
3982
}
40-
} else if hasProcfile {
41-
return buildTypeSlugbuilder
4283
}
43-
return buildTypeDockerbuilder
84+
return Stacks[0]
4485
}

pkg/gitreceive/build_type_test.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@ import (
66
"testing"
77
)
88

9-
func TestGetBuildType(t *testing.T) {
9+
func TestGetStack(t *testing.T) {
1010
tmpDir := os.TempDir()
1111
config := api.Config{}
12-
bType := getBuildType(tmpDir, config)
13-
if bType != buildTypeDockerbuilder {
14-
t.Fatalf("expected procfile build, got %s", bType)
12+
stack := getStack(tmpDir, config)
13+
if stack["name"] != "container" {
14+
t.Fatalf("expected procfile build, got %s", stack)
1515
}
1616
if _, err := os.Create(tmpDir + "/Dockerfile"); err != nil {
1717
t.Fatalf("error creating %s/Dockerfile (%s)", tmpDir, err)
1818
}
1919

20-
bType = getBuildType(tmpDir, config)
21-
if bType != buildTypeDockerbuilder {
22-
t.Fatalf("expected dockerfile build, got %s", bType)
20+
stack = getStack(tmpDir, config)
21+
if stack["name"] != "container" {
22+
t.Fatalf("expected dockerfile build, got %s", stack)
2323
}
2424

2525
if _, err := os.Create(tmpDir + "/Procfile"); err != nil {
@@ -35,18 +35,18 @@ func TestGetBuildType(t *testing.T) {
3535
}
3636
}()
3737
config.Values = map[string]interface{}{
38-
"DRYCC_BUILDER": "slugbuilder",
38+
"DRYCC_STACK": "heroku-18",
3939
}
40-
bType = getBuildType(tmpDir, config)
41-
if bType != buildTypeSlugbuilder {
42-
t.Fatalf("expected procfile build, got %s", bType)
40+
stack = getStack(tmpDir, config)
41+
if stack["name"] != "heroku-18" {
42+
t.Fatalf("expected procfile build, got %s", stack)
4343
}
4444

4545
config.Values = map[string]interface{}{
46-
"DRYCC_BUILDER": "dockerbuilder",
46+
"DRYCC_STACK": "container",
4747
}
48-
bType = getBuildType(tmpDir, config)
49-
if bType != buildTypeDockerbuilder {
50-
t.Fatalf("expected Dockerfile build, got %s", bType)
48+
stack = getStack(tmpDir, config)
49+
if stack["name"] != "container" {
50+
t.Fatalf("expected Dockerfile build, got %s", stack)
5151
}
5252
}

pkg/gitreceive/config.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,8 @@ type Config struct {
3535
ObjectStorageTickDurationMSec int `envconfig:"OBJECT_STORAGE_TICK_DURATION" default:"500"`
3636
ObjectStorageWaitDurationMSec int `envconfig:"OBJECT_STORAGE_WAIT_DURATION" default:"300000"` // 5 minutes
3737
SessionIdleIntervalMsec int `envconfig:"SESSION_IDLE_INTERVAL" default:"10000"` // 10 seconds
38-
SlugBuilderImage string `envconfig:"SLUGBUILDER_IMAGE_NAME" required:"true"`
39-
DockerBuilderImage string `envconfig:"DOCKERBUILDER_IMAGE_NAME" required:"true"`
40-
SlugBuilderImagePullPolicy string `envconfig:"SLUG_BUILDER_IMAGE_PULL_POLICY" default:"Always"`
41-
DockerBuilderImagePullPolicy string `envconfig:"DOCKER_BUILDER_IMAGE_PULL_POLICY" default:"Always"`
38+
SlugBuilderImagePullPolicy string `envconfig:"SLUGBUILDER_IMAGE_PULL_POLICY" default:"Always"`
39+
DockerBuilderImagePullPolicy string `envconfig:"DOCKERBUILDER_IMAGE_PULL_POLICY" default:"Always"`
4240
StorageType string `envconfig:"BUILDER_STORAGE" default:"minio"`
4341
BuilderPodNodeSelector string `envconfig:"BUILDER_POD_NODE_SELECTOR" default:""`
4442
}

pkg/sshd/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ type Config struct {
1414
HealthSrvTestStorageRegion string `envconfig:"STORAGE_REGION" default:"us-east-1"`
1515
CleanerPollSleepDurationSec int `envconfig:"CLEANER_POLL_SLEEP_DURATION_SEC" default:"5"`
1616
StorageType string `envconfig:"BUILDER_STORAGE" default:"minio"`
17-
SlugBuilderImagePullPolicy string `envconfig:"SLUG_BUILDER_IMAGE_PULL_POLICY" default:"Always"`
18-
DockerBuilderImagePullPolicy string `envconfig:"DOCKER_BUILDER_IMAGE_PULL_POLICY" default:"Always"`
17+
SlugBuilderImagePullPolicy string `envconfig:"SLUGBUILDER_IMAGE_PULL_POLICY" default:"Always"`
18+
DockerBuilderImagePullPolicy string `envconfig:"DOCKERBUILDER_IMAGE_PULL_POLICY" default:"Always"`
1919
LockTimeout int `envconfig:"GIT_LOCK_TIMEOUT" default:"10"`
2020
}
2121

0 commit comments

Comments
 (0)