Skip to content

Commit 266c133

Browse files
arschlesAaron Schlesinger
authored andcommitted
fix(build.go,storage_creds.go,storage.go): fix build errors so far
1 parent 08a6c2d commit 266c133

3 files changed

Lines changed: 59 additions & 45 deletions

File tree

pkg/gitreceive/build.go

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
package gitreceive
22

33
import (
4+
"bytes"
45
"fmt"
6+
"io/ioutil"
7+
"os"
8+
"os/exec"
59
"path/filepath"
610
"strings"
11+
"time"
712

813
"code.google.com/p/go-uuid/uuid"
14+
"github.com/deis/builder/pkg"
15+
"github.com/deis/builder/pkg/log"
916
)
1017

1118
const (
@@ -49,9 +56,6 @@ func build(conf *Config, newRev string) error {
4956
os.Exit(1)
5057
}
5158

52-
tarURL := fmt.Sprintf("%s://%s:%s/git/home/%s/tar", storage.schema(), storage.host(), storage.port(), slugName)
53-
pushURL := fmt.Sprintf("%s://%s:%s/git/hom/%s/push", storage.schema(), storage.host(), storage.port(), slugName)
54-
5559
// #!/usr/bin/env bash
5660
// #
5761
// # builder hook called on every git receive-pack
@@ -132,13 +136,17 @@ func build(conf *Config, newRev string) error {
132136
// # create temporary directory inside the build dir for this push
133137
// TMP_DIR=$(mktemp -d -p $BUILD_DIR)
134138
slugName := fmt.Sprintf("%s:git-%s", appName, shortSha)
135-
metaName := strings.Replace(slugName, ":", "-")
139+
metaName := strings.Replace(slugName, ":", "-", -1)
136140
tmpImage := fmt.Sprintf("%s:%s/%s", conf.RegistryHost, conf.RegistryPort, conf.ImageName)
137141
if err := os.MkdirAll(buildDir, os.ModeDir); err != nil {
138-
return errMkdir{dir: buildDir, err: err}
142+
log.Err("making the build directory %s (%s)", buildDir, err)
143+
os.Exit(1)
139144
}
140145
tmpDir := os.TempDir()
141146

147+
tarURL := fmt.Sprintf("%s://%s:%s/git/home/%s/tar", storage.schema(), storage.host(), storage.port(), slugName)
148+
pushURL := fmt.Sprintf("%s://%s:%s/git/hom/%s/push", storage.schema(), storage.host(), storage.port(), slugName)
149+
142150
//
143151
// cd $REPO_DIR
144152
// # use Procfile if provided, otherwise try default process types from ./release
@@ -152,11 +160,11 @@ func build(conf *Config, newRev string) error {
152160
os.Exit(1)
153161
}
154162
// tar -xzf ${APP_NAME}.tar.gz -C $TMP_DIR/
155-
cmd := exec.Command("tar", "-xzf", fmt.Sprintf("%s.tar.gz", appName), "-C", fmt.Sprintf("%s/", tmpDir))
156-
cmd.Dir = repoDir
157-
cmd.Stdout = os.Stdout
158-
cmd.Stderr = os.Stderr
159-
if err := cmd.Run(); err != nil {
163+
tarCmd := exec.Command("tar", "-xzf", fmt.Sprintf("%s.tar.gz", appName), "-C", fmt.Sprintf("%s/", tmpDir))
164+
tarCmd.Dir = repoDir
165+
tarCmd.Stdout = os.Stdout
166+
tarCmd.Stderr = os.Stderr
167+
if err := tarCmd.Run(); err != nil {
160168
log.Err("running %s", strings.Join(cmd.Args, " "))
161169
os.Exit(1)
162170
}
@@ -174,7 +182,7 @@ func build(conf *Config, newRev string) error {
174182
if err != nil {
175183
usingDockerfile = false
176184
}
177-
procFile, err := pkg.YamlToJSON(rawProcfile)
185+
procFile, err := pkg.YamlToJSON(rawProcFile)
178186
if err != nil {
179187
log.Err("procfile %s/Procfile is not valid JSON [%s]", tmpDir, err)
180188
os.Exit(1)
@@ -236,14 +244,14 @@ func build(conf *Config, newRev string) error {
236244
var finalManifest string
237245
if usingDockerfile {
238246
buildPodName = fmt.Sprintf("%s-%s", tmpImage, uuid.New())
239-
finalManifest = strings.Replace(string(fileBytes), "repo_name", buildPodName)
240-
finalManifest = strings.Replace(finalManifest, "puturl", pushURL)
241-
finalManifest = strings.Replace(finalManifest, "tar-url", tarURL)
247+
finalManifest = strings.Replace(string(fileBytes), "repo_name", buildPodName, -1)
248+
finalManifest = strings.Replace(finalManifest, "puturl", pushURL, -1)
249+
finalManifest = strings.Replace(finalManifest, "tar-url", tarURL, -1)
242250
} else {
243251
buildPodName = fmt.Sprintf("%s-%s", slugName, uuid.New())
244-
finalManifest = strings.Replace(string(fileBytes), "repo_name", buildPodName)
245-
finalManifest = strings.Replace(finalManifest, "puturl", pushURL)
246-
finalManifest = strings.Replace(finalManifest, "tar-url", tarURL)
252+
finalManifest = strings.Replace(string(fileBytes), "repo_name", buildPodName, -1)
253+
finalManifest = strings.Replace(finalManifest, "puturl", pushURL, -1)
254+
finalManifest = strings.Replace(finalManifest, "tar-url", tarURL, -1)
247255
}
248256

249257
if err := ioutil.WriteFile(finalManifestFileName, []byte(finalManifest), os.ModePerm); err != nil {
@@ -253,11 +261,11 @@ func build(conf *Config, newRev string) error {
253261
//
254262
// git archive --format=tar.gz ${GIT_SHA} > ${APP_NAME}.tar.gz
255263

256-
cmd := exec.Command("git", "archive", "--format=tar.gz", fmt.Sprintf("%s > %s.tar.gz", gitSha, appName))
257-
cmd.Dir = repoDir
258-
cmd.Stdout = os.Stdout
259-
cmd.Stderr = os.Stderr
260-
if err := cmd.Run(); err != nil {
264+
gitArchiveCmd := exec.Command("git", "archive", "--format=tar.gz", fmt.Sprintf("%s > %s.tar.gz", gitSha, appName))
265+
gitArchiveCmd.Dir = repoDir
266+
gitArchiveCmd.Stdout = os.Stdout
267+
gitArchiveCmd.Stderr = os.Stderr
268+
if err := gitArchiveCmd.Run(); err != nil {
261269
log.Err("running %s", strings.Join(cmd.Args, " "))
262270
os.Exit(1)
263271
}
@@ -273,7 +281,7 @@ func build(conf *Config, newRev string) error {
273281
// mkdir -p /var/minio-conf
274282
// CONFIG_DIR=/var/minio-conf
275283
// MC_PREFIX="mc -C $CONFIG_DIR --quiet"
276-
configDir = "/var/minio-conf"
284+
configDir := "/var/minio-conf"
277285
if err := os.MkdirAll(configDir, os.ModePerm); err != nil {
278286
log.Err("creating minio config file (%s)", err)
279287
os.Exit(1)
@@ -289,8 +297,8 @@ func build(conf *Config, newRev string) error {
289297
"host",
290298
"add",
291299
fmt.Sprintf("%s://%s:%s", storage.schema(), storage.host(), storage.port()),
292-
storageCreds.key,
293-
storageCreds.secret,
300+
creds.key,
301+
creds.secret,
294302
)
295303
if err := configCmd.Run(); err != nil {
296304
log.Err("configuring the minio client (%s)", err)
@@ -317,7 +325,7 @@ func build(conf *Config, newRev string) error {
317325
)
318326
cpCmd.Dir = repoDir
319327
if err := cpCmd.Run(); err != nil {
320-
log.Err("copying %s.tar.gz to %s (%s)", apName, tarURL, err)
328+
log.Err("copying %s.tar.gz to %s (%s)", appName, tarURL, err)
321329
os.Exit(1)
322330
}
323331

@@ -351,15 +359,15 @@ func build(conf *Config, newRev string) error {
351359
getCmd := exec.Command(
352360
"kubectl",
353361
fmt.Sprintf("--namespace=%s", conf.PodNamespace),
354-
fmt.SPrintf("get"),
355-
fmt.SPrintf("pods"),
362+
fmt.Sprintf("get"),
363+
fmt.Sprintf("pods"),
356364
"-o",
357365
"yaml",
358366
buildPodName,
359367
)
360368
for {
361369
var out bytes.Buffer
362-
getCmd.Stdout = out
370+
getCmd.Stdout = &out
363371
if err := getCmd.Run(); err != nil {
364372
log.Err("running %s while determining if builder pod %s is running (%s)", buildPodName, err)
365373
os.Exit(1)
@@ -380,7 +388,7 @@ func build(conf *Config, newRev string) error {
380388
)
381389
logsCmd.Stdout = os.Stdout
382390
if err := logsCmd.Run(); err != nil {
383-
log.Err("running %s to get builder logs (%s)", strings.Join(logsCmd.Args), err)
391+
log.Err("running %s to get builder logs (%s)", strings.Join(logsCmd.Args, " "), err)
384392
os.Exit(1)
385393
}
386394

pkg/gitreceive/storage.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,30 +32,30 @@ func getStorageConfig() (storageConfig, error) {
3232
mHost := os.Getenv(minioHostEnvVar)
3333
mPort := os.Getenv(minioPortEnvVar)
3434
oHost := os.Getenv(outsideStorageHostEnvVar)
35-
oPost := os.Getenv(outsideStoragePortEnvVar)
36-
if mHost != "" && mPost != "" {
37-
return minioConfig{host: mHost, port: mPort}, nil
35+
oPort := os.Getenv(outsideStoragePortEnvVar)
36+
if mHost != "" && mPort != "" {
37+
return minioConfig{hst: mHost, prt: mPort}, nil
3838
} else if oHost != "" && oPort != "" {
39-
return outsideConfig{host: oHost, port: oPort}, nil
39+
return outsideConfig{hst: oHost, prt: oPort}, nil
4040
} else {
4141
return nil, errNoStorageConfig
4242
}
4343
}
4444

4545
type minioConfig struct {
46-
host string
47-
port string
46+
hst string
47+
prt string
4848
}
4949

5050
func (m minioConfig) schema() string { return "http" }
51-
func (m minioConfig) host() string { return m.host }
52-
func (m minioConfig) port() string { return m.port }
51+
func (m minioConfig) host() string { return m.hst }
52+
func (m minioConfig) port() string { return m.prt }
5353

5454
type outsideConfig struct {
55-
host string
56-
port string
55+
hst string
56+
prt string
5757
}
5858

5959
func (o outsideConfig) schema() string { return "https" }
60-
func (o outsideConfig) host() string { return o.host }
61-
func (o outsideConfig) port() string { return o.port }
60+
func (o outsideConfig) host() string { return o.hst }
61+
func (o outsideConfig) port() string { return o.prt }

pkg/gitreceive/storage_creds.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
package gitreceive
22

3+
import (
4+
"fmt"
5+
"io/ioutil"
6+
"os"
7+
)
8+
39
const (
410
accessKeyIDFile = "/var/run/secrets/object/store/access-key-id"
511
accessSecretKeyFile = "/var/run/secrets/object/store/access-secret-key"
612
)
713

814
var (
9-
errMissingKey = fmt.Sprintf("missing %s", accessKeyIDFile)
10-
errMissingSecret = fmt.Sprintf("missing %s", accessSecretKeyFile)
15+
errMissingKey = fmt.Errorf("missing %s", accessKeyIDFile)
16+
errMissingSecret = fmt.Errorf("missing %s", accessSecretKeyFile)
1117
)
1218

1319
type storageCreds struct {
@@ -30,7 +36,7 @@ func getStorageCreds() (*storageCreds, error) {
3036
if accessKeyErr == nil && accessSecretKeyErr != nil {
3137
return nil, errMissingSecret
3238
}
33-
return storageCreds{
39+
return &storageCreds{
3440
key: string(accessKeyIDBytes),
3541
secret: string(accessSecretKeyBytes),
3642
}, nil

0 commit comments

Comments
 (0)