Skip to content

Commit 72ce5cb

Browse files
author
smothiki
committed
feat(dockerbuilder): add logic to build dockerfile builds
1 parent 2944714 commit 72ce5cb

4 files changed

Lines changed: 18 additions & 18 deletions

File tree

pkg/gitreceive/build.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,14 @@ func build(conf *Config, s3Client *s3.S3, kubeClient *client.Client, builderKey,
5454
buildDir := filepath.Join(repoDir, "build")
5555

5656
slugName := fmt.Sprintf("%s:git-%s", appName, gitSha.Short())
57-
imageName := strings.Replace(slugName, ":", "-", -1)
5857
if err := os.MkdirAll(buildDir, os.ModeDir); err != nil {
5958
return fmt.Errorf("making the build directory %s (%s)", buildDir, err)
6059
}
61-
tmpDir := os.TempDir()
60+
61+
tmpDir, err := ioutil.TempDir(buildDir, "tmp")
62+
if err != nil {
63+
return fmt.Errorf("unable to create tmpdir %s (%s)", buildDir, err)
64+
}
6265

6366
slugBuilderInfo := storage.NewSlugBuilderInfo(s3Client.Endpoint, appName, slugName, gitSha)
6467

@@ -78,7 +81,7 @@ func build(conf *Config, s3Client *s3.S3, kubeClient *client.Client, builderKey,
7881

7982
// build a tarball from the new objects
8083
appTgz := fmt.Sprintf("%s.tar.gz", appName)
81-
gitArchiveCmd := repoCmd(repoDir, "git", "archive", "--format=tar.gz", fmt.Sprintf("--output=%s", appTgz), gitSha.Full())
84+
gitArchiveCmd := repoCmd(repoDir, "git", "archive", "--format=tar.gz", fmt.Sprintf("--output=%s", appTgz), gitSha.Short())
8285
gitArchiveCmd.Stdout = os.Stdout
8386
gitArchiveCmd.Stderr = os.Stderr
8487
if err := run(gitArchiveCmd); err != nil {
@@ -97,7 +100,7 @@ func build(conf *Config, s3Client *s3.S3, kubeClient *client.Client, builderKey,
97100
bType := getBuildTypeForDir(tmpDir)
98101
usingDockerfile := bType == buildTypeDockerfile
99102

100-
var procType pkg.ProcessType
103+
procType := pkg.ProcessType{}
101104
if bType == buildTypeProcfile {
102105
rawProcFile, err := ioutil.ReadFile(fmt.Sprintf("%s/Procfile", tmpDir))
103106
if err != nil {
@@ -136,7 +139,7 @@ func build(conf *Config, s3Client *s3.S3, kubeClient *client.Client, builderKey,
136139
conf.PodNamespace,
137140
appConf.Values,
138141
slugBuilderInfo.TarURL(),
139-
imageName,
142+
slugName,
140143
)
141144
} else {
142145
buildPodName = slugBuilderPodName(appName, gitSha.Short())
@@ -201,13 +204,12 @@ func build(conf *Config, s3Client *s3.S3, kubeClient *client.Client, builderKey,
201204
if err != nil {
202205
return fmt.Errorf("Timed out waiting for object in storage. Aborting build...")
203206
}
204-
205207
log.Info("Build complete.")
206208
log.Info("Launching app.")
207209
log.Info("Launching...")
208210

209211
buildHook := &pkg.BuildHook{
210-
Sha: gitSha.Full(),
212+
Sha: gitSha.Short(),
211213
ReceiveUser: conf.Username,
212214
ReceiveRepo: appName,
213215
Image: appName,
@@ -217,7 +219,6 @@ func build(conf *Config, s3Client *s3.S3, kubeClient *client.Client, builderKey,
217219
buildHook.Dockerfile = ""
218220
} else {
219221
buildHook.Dockerfile = "true"
220-
buildHook.Image = imageName
221222
}
222223
buildHookResp, err := publishRelease(conf, builderKey, buildHook)
223224
if err != nil {

pkg/gitreceive/k8s_util.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ import (
1212
)
1313

1414
const (
15-
slugBuilderName = "deis-slugbuilder"
16-
slugBuilderImage = "quay.io/deisci/slugbuilder:v2-beta"
17-
dockerBuilderName = "deis-dockerbuilder"
18-
dockerBuilderImage = "quay.io/deisci/dockerbuilder:v2-beta"
15+
slugBuilderName = "deis-slugbuilder"
16+
slugBuilderImage = "quay.io/deisci/slugbuilder:v2-beta"
17+
dockerBuilderName = "deis-dockerbuilder"
18+
// change the value back to quay.io/deisci/dockerbuilder:v2-beta
19+
dockerBuilderImage = "smothiki/dockerbuilder:v1.8"
1920

2021
tarURLKey = "TAR_URL"
2122
putURLKey = "put_url"
@@ -44,10 +45,8 @@ func dockerBuilderPod(debug, withAuth bool, name, namespace string, env map[stri
4445
addEnvToPod(pod, "ACCESS_KEY_FILE", "/var/run/secrets/object/store/access_key")
4546
addEnvToPod(pod, "ACCESS_SECRET_FILE", "/var/run/secrets/object/store/access_secret")
4647

47-
if !withAuth {
48-
addEnvToPod(pod, tarURLKey, tarURL)
49-
addEnvToPod(pod, "IMG_NAME", imageName)
50-
}
48+
addEnvToPod(pod, tarURLKey, tarURL)
49+
addEnvToPod(pod, "IMG_NAME", imageName)
5150

5251
pod.Spec.Containers[0].VolumeMounts = append(pod.Spec.Containers[0].VolumeMounts, api.VolumeMount{
5352
Name: dockerSocketName,

pkg/gitreceive/storage/slug_builder_info.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type SlugBuilderInfo struct {
1818
func NewSlugBuilderInfo(s3Endpoint, appName, slugName string, gitSha *git.SHA) *SlugBuilderInfo {
1919
tarKey := fmt.Sprintf("home/%s/tar", slugName)
2020
// this is where workflow tells slugrunner to download the slug from, so we have to tell slugbuilder to upload it to here
21-
pushKey := fmt.Sprintf("home/%s:git-%s/push", appName, gitSha.Full())
21+
pushKey := fmt.Sprintf("home/%s:git-%s/push", appName, gitSha.Short())
2222

2323
return &SlugBuilderInfo{
2424
pushKey: pushKey,

pkg/gitreceive/storage/slug_builder_info_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func TestPushKey(t *testing.T) {
3636
t.Fatalf("error building git sha (%s)", err)
3737
}
3838
sbi := NewSlugBuilderInfo(s3Endpoint, appName, slugName, sha)
39-
expectedPushKey := "home/" + appName + ":git-" + sha.Full() + "/push"
39+
expectedPushKey := "home/" + appName + ":git-" + sha.Short() + "/push"
4040
if sbi.PushKey() != expectedPushKey {
4141
t.Errorf("push key %s didn't match expected %s", sbi.PushKey(), expectedPushKey)
4242
}

0 commit comments

Comments
 (0)