Skip to content

Commit 96e01b8

Browse files
author
Aaron Schlesinger
committed
ref(build.go): begin to translate mc commands to s3 client API calls
1 parent c7f9a62 commit 96e01b8

1 file changed

Lines changed: 16 additions & 27 deletions

File tree

pkg/gitreceive/build.go

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,6 @@ func repoCmd(repoDir, first string, others ...string) *exec.Cmd {
3636
return cmd
3737
}
3838

39-
// mcCmd returns a command to execute the 'mc' binary, so that it reads config from configDir.
40-
// the command outputs its stderr to os.Stderr
41-
func mcCmd(configDir string, args ...string) *exec.Cmd {
42-
cmd := exec.Command("mc", "-C", configDir, "--quiet")
43-
cmd.Args = append(cmd.Args, args...)
44-
cmd.Stderr = os.Stderr
45-
return cmd
46-
}
47-
4839
func kGetCmd(podNS, podName string) *exec.Cmd {
4940
return exec.Command("kubectl", fmt.Sprintf("--namespace=%s", podNS), "get", "pods", "-o", "yaml", podName)
5041
}
@@ -78,10 +69,12 @@ func build(conf *Config, s3Client *s3.Client, builderKey, gitSha string) error {
7869
}
7970
tmpDir := os.TempDir()
8071

81-
tarURL := fmt.Sprintf("%s://%s:%s/git/home/%s/tar", storage.schema(), storage.host(), storage.port(), slugName)
72+
tarObjKey := fmt.Sprintf("home/%s/tar", slugName)
73+
tarURL := fmt.Sprintf("%s://%s:%s/git/%s", storage.schema(), storage.host(), storage.port(), tarObjKey)
8274

8375
// this is where workflow tells slugrunner to download the slug from, so we have to tell slugbuilder to upload it to here
84-
pushURL := fmt.Sprintf("%s://%s:%s/git/home/%s/push", storage.schema(), storage.host(), storage.port(), fmt.Sprintf("%s:git-%s", appName, gitSha))
76+
pushObjKey := fmt.Sprintf("home/%s/push", fmt.Sprintf("%s:git-%s", appName, gitSha))
77+
pushURL := fmt.Sprintf("%s://%s:%s/%s", storage.schema(), storage.host(), storage.port(), pushObjKey)
8578

8679
// Get the application config from the controller, so we can check for a custom buildpack URL
8780
appConf, err := getAppConfig(conf, builderKey, conf.Username, appName)
@@ -105,6 +98,7 @@ func build(conf *Config, s3Client *s3.Client, builderKey, gitSha string) error {
10598
if err := run(gitArchiveCmd); err != nil {
10699
return fmt.Errorf("running %s (%s)", strings.Join(gitArchiveCmd.Args, " "), err)
107100
}
101+
absAppTgz := fmt.Sprintf("%s/%s", repoDir, appTgz)
108102

109103
// untar the archive into the temp dir
110104
tarCmd := repoCmd(repoDir, "tar", "-xzf", appTgz, "-C", fmt.Sprintf("%s/", tmpDir))
@@ -180,20 +174,17 @@ func build(conf *Config, s3Client *s3.Client, builderKey, gitSha string) error {
180174
return fmt.Errorf("creating minio config file (%s)", err)
181175
}
182176

183-
configCmd := mcCmd(configDir, "config", "host", "add", fmt.Sprintf("%s://%s:%s", storage.schema(), storage.host(), storage.port()), creds.key, creds.secret)
184-
if err := run(configCmd); err != nil {
185-
return fmt.Errorf("configuring the minio client (%s)", err)
177+
bucketName := "git"
178+
if _, err := s3Client.CreateBucket(&s3.CreateBucketInput{Bucket: aws.String(bucketName)}); bucketCreateErr != nil {
179+
log.Warn("create bucket error: %+v", err)
186180
}
187181

188-
makeBucketCmd := mcCmd(configDir, "mb", fmt.Sprintf("%s://%s:%s/git", storage.schema(), storage.host(), storage.port()))
189-
// Don't look for errors here. Buckets may already exist
190-
// https://github.com/deis/builder/issues/80 will eliminate this distaste
191-
run(makeBucketCmd)
192-
193-
cpCmd := mcCmd(configDir, "cp", appTgz, tarURL)
194-
cpCmd.Dir = repoDir
195-
if err := run(cpCmd); err != nil {
196-
return fmt.Errorf("copying %s to %s (%s)", appTgz, tarURL, err)
182+
appTgzReader, err := os.Open(absAppTgz)
183+
if err != nil {
184+
return fmt.Errorf("opening %s for read (%s)", appTgz, err)
185+
}
186+
if err := storage.Upload(s3Client, bucketName, tarObjKey); err != nil {
187+
return fmt.Errorf("uploading %s to %s/%s (%s)", absAppTgz, bucketName, tarObjKey, err)
197188
}
198189

199190
log.Info("Starting build... but first, coffee!")
@@ -244,11 +235,9 @@ func build(conf *Config, s3Client *s3.Client, builderKey, gitSha string) error {
244235
}
245236

246237
// poll the s3 server to ensure the slug exists
238+
// TODO: time out looking
247239
for {
248-
// for now, assume the error indicates that the slug wasn't there, nothing else
249-
// TODO: implement https://github.com/deis/builder/issues/80, which will clean this up siginficantly
250-
lsCmd := mcCmd(configDir, "ls", pushURL)
251-
if err := run(lsCmd); err == nil {
240+
if storage.ObjectExists(s3Client, bucketName, pushObjKey) {
252241
break
253242
}
254243
}

0 commit comments

Comments
 (0)