Skip to content

Commit e5a7f03

Browse files
arschlesAaron Schlesinger
authored andcommitted
fix(build.go): progress on porting build to shell
1 parent aa26fb3 commit e5a7f03

2 files changed

Lines changed: 48 additions & 2 deletions

File tree

pkg/gitreceive/build.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
package gitreceive
22

3+
import (
4+
"fmt"
5+
"path/filepath"
6+
"strings"
7+
)
8+
9+
const shortShaIdx = 8
10+
11+
type errGitShaTooShort struct {
12+
sha string
13+
}
14+
15+
func (e errGitShaTooShort) Error() string {
16+
return fmt.Sprintf("git sha %s was too short", e.sha)
17+
}
18+
319
func build(conf *Config, newRev string) error {
420
// #!/usr/bin/env bash
521
// #
@@ -43,18 +59,34 @@ func build(conf *Config, newRev string) error {
4359
// exit 1
4460
// fi
4561
//
62+
4663
// USER=$1
4764
// REPO=$2
4865
// GIT_SHA=$3
4966
// SHORT_SHA=${GIT_SHA:0:8}
5067
// APP_NAME="${REPO%.*}"
68+
user := conf.Username
69+
repo := conf.Repository
70+
gitSha := conf.SHA
71+
if len(gitSha) <= shortShaIdx {
72+
return errGitShaTooShort{sha: gitSha}
73+
}
74+
shortSha := conf.SHA[0:8]
75+
appName := conf.App
5176
//
5277
// cd $(dirname $0) # ensure we are in the root dir
5378
//
5479
// ROOT_DIR=$(pwd)
5580
// REPO_DIR="${ROOT_DIR}/${REPO}"
5681
// BUILD_DIR="${REPO_DIR}/build"
5782
// CACHE_DIR="${REPO_DIR}/cache"
83+
rootDir, err := os.Getwd()
84+
if err != nil {
85+
return nil
86+
}
87+
repoDir := filepath.Join(rootDir, repo)
88+
buildDir := filepath.Join(repoDir, "build")
89+
cacheDir := filepath.Join(repoDir, "cache")
5890
//
5991
// # define image names
6092
// SLUG_NAME="$APP_NAME:git-$SHORT_SHA"
@@ -64,6 +96,15 @@ func build(conf *Config, newRev string) error {
6496
// mkdir -p $BUILD_DIR $CACHE_DIR
6597
// # create temporary directory inside the build dir for this push
6698
// TMP_DIR=$(mktemp -d -p $BUILD_DIR)
99+
slugName := fmt.Sprintf("%s:git-%s", appName, shortSha)
100+
metaName := strings.Replace(slugName, ":", "-")
101+
tmpImage := fmt.Sprintf("%s:%s/%s", conf.RegistryHost, conf.RegistryPort, conf.ImageName)
102+
if err := os.MkdirAll(buildDir, os.ModeDir); err != nil {
103+
return errMkdir{dir: buildDir, err: err}
104+
}
105+
106+
//TODO: make tmp_dir
107+
67108
//
68109
// cd $REPO_DIR
69110
// # use Procfile if provided, otherwise try default process types from ./release

pkg/gitreceive/config.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package gitreceive
22

33
type Config struct {
4-
WorkflowHost string `envconfig:"deis_workflow_service_host"`
5-
WorkflowPort string `envconfig:"deis_workflow_service_port"`
4+
// k8s service discovery env vars
5+
WorkflowHost string `envconfig:"deis_workflow_service_host"`
6+
WorkflowPort string `envconfig:"deis_workflow_service_port"`
7+
RegistryHost string `envconfig:"deis_registry_service_host"`
8+
RegistryPort string `envconfig:"deis_registry_service_port"`
9+
610
GitHome string `envconfig:"git_home"`
711
SSHConnection string `envconfig:"ssh_connection"`
812
SSHOriginalCommand string `envconfig:"ssh_original_command"`
@@ -11,4 +15,5 @@ type Config struct {
1115
Username string `envconfig:"username"`
1216
App string `envconfing:"app"`
1317
Fingerprint string `envconfing:"fingerprint"`
18+
ImageName string `envconfig:"image_name"`
1419
}

0 commit comments

Comments
 (0)