@@ -59,23 +59,6 @@ func run(cmd *exec.Cmd) error {
5959}
6060
6161func build (conf * Config , builderKey , gitSha string ) error {
62- // HTTP_PREFIX="http"
63- // REMOTE_STORAGE="0"
64- // # if minio is in the cluster, use it. otherwise use fetcher
65- // # TODO: figure out something for using S3 also
66- // if [[ -n "$DEIS_MINIO_SERVICE_HOST" && -n "$DEIS_MINIO_SERVICE_PORT" ]]; then
67- // S3EP=${DEIS_MINIO_SERVICE_HOST}:${DEIS_MINIO_SERVICE_PORT}
68- // REMOTE_STORAGE="1"
69- // elif [[ -n "$DEIS_OUTSIDE_STORAGE_HOST" && -n "$DEIS_OUTSIDE_STORAGE_PORT" ]]; then
70- // HTTP_PREFIX="https"
71- // S3EP=${DEIS_OUTSIDE_STORAGE_HOST}:${DEIS_OUTSIDE_STORAGE_PORT}
72- // REMOTE_STORAGE="1"
73- // elif [ -z "$S3EP" ]; then
74- // S3EP=${HOST}:3000
75- // fi
76- //
77- // TAR_URL=$HTTP_PREFIX://$S3EP/git/home/${SLUG_NAME}/tar
78- // PUSH_URL=$HTTP_PREFIX://$S3EP/git/home/${SLUG_NAME}/push
7962 storage , err := getStorageConfig ()
8063 if err != nil {
8164 return err
@@ -85,79 +68,16 @@ func build(conf *Config, builderKey, gitSha string) error {
8568 return err
8669 }
8770
88- // #!/usr/bin/env bash
89- // #
90- // # builder hook called on every git receive-pack
91- // # NOTE: this script must be run as root (for docker access)
92- // #
93- // set -eo pipefail
94- //
95- // ARGS=3
96- // HOST=`ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'`
97- // indent() {
98- // echo " $@"
99- // }
100- //
101- // puts-step() {
102- // echo "-----> $@"
103- // }
104- //
105- // puts-step-sameline() {
106- // echo -n "-----> $@"
107- // }
108- //
109- // puts-warn() {
110- // echo " ! $@"
111- // }
112- //
113- // usage() {
114- // echo "Usage: $0 <user> <repo> <sha>"
115- // }
116- //
117- // parse-string(){
118- // # helper to avoid the single quote escape
119- // # occurred in command substitution
120- // local args=() idx=0 IFS=' ' c
121- // for c; do printf -v args[idx++] '%s ' "$c"; done
122- // printf "%s\n" "${args[*]}"
123- // }
124- //
125- // if [ $# -ne $ARGS ]; then
126- // usage
127- // exit 1
128- // fi
129- //
130-
131- // USER=$1
132- // REPO=$2
133- // GIT_SHA=$3
134- // SHORT_SHA=${GIT_SHA:0:8}
135- // APP_NAME="${REPO%.*}"
13671 repo := conf .Repository
13772 if len (gitSha ) <= shortShaIdx {
13873 return errGitShaTooShort {sha : gitSha }
13974 }
14075 shortSha := gitSha [0 :8 ]
14176 appName := conf .App ()
142- //
143- // cd $(dirname $0) # ensure we are in the root dir
144- //
145- // ROOT_DIR=$(pwd)
146- // REPO_DIR="${ROOT_DIR}/${REPO}"
147- // BUILD_DIR="${REPO_DIR}/build"
148- // CACHE_DIR="${REPO_DIR}/cache"
77+
14978 repoDir := filepath .Join (conf .GitHome , repo )
15079 buildDir := filepath .Join (repoDir , "build" )
151- // cacheDir := filepath.Join(repoDir, "cache")
152- //
153- // # define image names
154- // SLUG_NAME="$APP_NAME:git-$SHORT_SHA"
155- // META_NAME=`echo ${SLUG_NAME}| tr ":" "-"`
156- // TMP_IMAGE="$DEIS_REGISTRY_SERVICE_HOST:$DEIS_REGISTRY_SERVICE_PORT/$IMAGE_NAME"
157- // # create app directories
158- // mkdir -p $BUILD_DIR $CACHE_DIR
159- // # create temporary directory inside the build dir for this push
160- // TMP_DIR=$(mktemp -d -p $BUILD_DIR)
80+
16181 slugName := fmt .Sprintf ("%s:git-%s" , appName , shortSha )
16282 imageName := strings .Replace (slugName , ":" , "-" , - 1 )
16383 if err := os .MkdirAll (buildDir , os .ModeDir ); err != nil {
@@ -168,32 +88,22 @@ func build(conf *Config, builderKey, gitSha string) error {
16888 tarURL := fmt .Sprintf ("%s://%s:%s/git/home/%s/tar" , storage .schema (), storage .host (), storage .port (), slugName )
16989 pushURL := fmt .Sprintf ("%s://%s:%s/git/hom/%s/push" , storage .schema (), storage .host (), storage .port (), slugName )
17090
171- //
172- // cd $REPO_DIR
173- // # use Procfile if provided, otherwise try default process types from ./release
174- // git archive --format=tar.gz ${GIT_SHA} > ${APP_NAME}.tar.gz
91+ // build a tarball from the new objects
17592 gitArchiveCmd := repoCmd (repoDir , "git" , "archive" , "--format=tar.gz" , fmt .Sprintf ("--output=%s.tar.gz" , appName ), gitSha )
17693 gitArchiveCmd .Stdout = os .Stdout
17794 gitArchiveCmd .Stderr = os .Stderr
17895 if err := run (gitArchiveCmd ); err != nil {
17996 return fmt .Errorf ("running %s (%s)" , strings .Join (gitArchiveCmd .Args , " " ), err )
18097 }
181- // tar -xzf ${APP_NAME}.tar.gz -C $TMP_DIR/
98+
99+ // untar the archive into the temp dir
182100 tarCmd := repoCmd (repoDir , "tar" , "-xzf" , fmt .Sprintf ("%s.tar.gz" , appName ), "-C" , fmt .Sprintf ("%s/" , tmpDir ))
183101 tarCmd .Stdout = os .Stdout
184102 tarCmd .Stderr = os .Stderr
185103 if err := run (tarCmd ); err != nil {
186104 return fmt .Errorf ("running %s (%s)" , strings .Join (tarCmd .Args , " " ), err )
187105 }
188106
189- // USING_DOCKERFILE=true
190- // if [ -f $TMP_DIR/Procfile ]; then
191- // PROCFILE=$(cat $TMP_DIR/Procfile | yaml2json-procfile)
192- // USING_DOCKERFILE=false
193- // else
194- // PROCFILE="{}"
195- // fi
196-
197107 usingDockerfile := true
198108 rawProcFile , err := ioutil .ReadFile (fmt .Sprintf ("%s/Procfile" , tmpDir ))
199109 if err == nil {
@@ -204,27 +114,6 @@ func build(conf *Config, builderKey, gitSha string) error {
204114 return fmt .Errorf ("procfile %s/ProcFile is malformed (%s)" , tmpDir , err )
205115 }
206116
207- // if [[ ! -f /var/run/secrets/object/store/access-key-id ]]; then
208- // if $USING_DOCKERFILE ; then
209- // l1=`grep -n "object-store" /etc/deis-dockerbuilder.yaml | head -n1 |cut -d ":" -f1`
210- // l2=$(($l1+3))
211- // sed "$l1,$l2 d" /etc/deis-dockerbuilder.yaml > /etc/${SLUG_NAME}.yaml.tmp
212- // l1=`grep -n "object-store" /etc/deis-dockerbuilder.yaml.tmp | head -n1 |cut -d ":" -f1`
213- // l2=$(($l1+3))
214- // sed "$l1,$l2 d" /etc/${SLUG_NAME}.yaml.tmp > /etc/${SLUG_NAME}.yaml
215- // sed -i -- "s#repo_name#$TMP_IMAGE#g" /etc/${SLUG_NAME}.yaml
216- // else
217- // head -n 21 /etc/deis-slugbuilder.yaml > /etc/${SLUG_NAME}.yaml
218- // fi
219- // else
220- // if $USING_DOCKERFILE ; then
221- // cp /etc/deis-dockerbuilder.yaml /etc/${SLUG_NAME}.yaml
222- // sed -i -- "s#repo_name#$TMP_IMAGE#g" /etc/${SLUG_NAME}.yaml
223- // else
224- // cp /etc/deis-slugbuilder.yaml /etc/${SLUG_NAME}.yaml
225- // fi
226- // fi
227-
228117 var srcManifest string
229118 if err == os .ErrNotExist {
230119 // both key and secret are missing, proceed with no credentials
@@ -250,9 +139,6 @@ func build(conf *Config, builderKey, gitSha string) error {
250139 return fmt .Errorf ("reading kubernetes manifest %s (%s)" , srcManifest , err )
251140 }
252141
253- // sed -i -- "s#repo_name#$META_NAME#g" /etc/${SLUG_NAME}.yaml
254- // sed -i -- "s#puturl#$PUSH_URL#g" /etc/${SLUG_NAME}.yaml
255- // sed -i -- "s#tar-url#$TAR_URL#g" /etc/${SLUG_NAME}.yaml
256142 finalManifestFileLocation := fmt .Sprintf ("/etc/%s" , slugName )
257143 var buildPodName string
258144 var finalManifest string
@@ -274,45 +160,27 @@ func build(conf *Config, builderKey, gitSha string) error {
274160 return fmt .Errorf ("writing final manifest %s (%s)" , finalManifestFileLocation , err )
275161 }
276162
277- //
278- // ACCESS_KEY=`cat /var/run/secrets/object/store/access-key-id`
279- // ACCESS_SECRET=`cat /var/run/secrets/object/store/access-secret-key`
280- // # copy the self signed cert into the CA directory for alpine.
281- // # note: we're not running minio with SSL at all right now, so no need for this.
282- // # future SSL rollouts for in-cluster storage may not need it either if we set up an intermediate CA
283- // # CERT_FILE="/var/run/secrets/object/ssl/access-cert"
284- // # cp $CERT_FILE /etc/ssl/certs/deis-minio-self-signed-cert.crt
285- // mkdir -p /var/minio-conf
286- // CONFIG_DIR=/var/minio-conf
287- // MC_PREFIX="mc -C $CONFIG_DIR --quiet"
288163 configDir := "/var/minio-conf"
289164 if err := os .MkdirAll (configDir , os .ModePerm ); err != nil {
290165 return fmt .Errorf ("creating minio config file (%s)" , err )
291166 }
292167
293- // $MC_PREFIX config host add "$HTTP_PREFIX://$S3EP" $ACCESS_KEY $ACCESS_SECRET &>/dev/null
294168 configCmd := mcCmd (configDir , "config" , "host" , "add" , fmt .Sprintf ("%s://%s:%s" , storage .schema (), storage .host (), storage .port ()), creds .key , creds .secret )
295169 if err := run (configCmd ); err != nil {
296170 return fmt .Errorf ("configuring the minio client (%s)" , err )
297171 }
298172
299- // $MC_PREFIX mb "$HTTP_PREFIX://${S3EP}/git" &>/dev/null
300173 makeBucketCmd := mcCmd (configDir , "mb" , fmt .Sprintf ("%s://%s:%s/git" , storage .schema (), storage .host (), storage .port ()))
301174 // Don't look for errors here. Buckets may already exist
302175 // https://github.com/deis/builder/issues/80 will eliminate this distaste
303176 run (makeBucketCmd )
304177
305- // $MC_PREFIX cp ${APP_NAME}.tar.gz $TAR_URL &>/dev/null
306178 cpCmd := mcCmd (configDir , "cp" , fmt .Sprintf ("%s.tar.gz" , appName ), tarURL )
307179 cpCmd .Dir = repoDir
308180 if err := run (cpCmd ); err != nil {
309181 return fmt .Errorf ("copying %s.tar.gz to %s (%s)" , appName , tarURL , err )
310182 }
311183
312- //
313- // puts-step "Starting build"
314- // kubectl --namespace=${POD_NAMESPACE} create -f /etc/${SLUG_NAME}.yaml >/dev/null
315-
316184 log .Info ("Starting build" )
317185 kCreateCmd := exec .Command (
318186 "kubectl" ,
@@ -329,13 +197,6 @@ func build(conf *Config, builderKey, gitSha string) error {
329197 return fmt .Errorf ("creating builder pod (%s)" , err )
330198 }
331199
332- //
333- // # wait for pod to be running and then pull its logs
334- // until [ "`kubectl --namespace=${POD_NAMESPACE} get pods -o yaml ${META_NAME} | grep "phase: " | awk {'print $2'}`" == "Running" ]; do
335- // sleep 0.1
336- // done
337- // kubectl --namespace=${POD_NAMESPACE} logs -f ${META_NAME} 2>/dev/null &
338-
339200 // poll kubectl every 100ms to determine when the build pod is running
340201 // TODO: use the k8s client and watch the event stream instead (https://github.com/deis/builder/issues/65)
341202 for {
@@ -366,23 +227,6 @@ func build(conf *Config, builderKey, gitSha string) error {
366227 return fmt .Errorf ("running %s to get builder logs (%s)" , strings .Join (kLogsCmd .Args , " " ), err )
367228 }
368229
369- //
370- // #check for image creation or slug existence in S3EP
371- //
372- // if [[ "$REMOTE_STORAGE" == "1" ]]; then
373- // LS_CMD="$MC_PREFIX ls $PUSH_URL"
374- // until $LS_CMD &> /dev/null; do
375- // echo -ne "."
376- // sleep 2
377- // done
378- // else
379- // while [ ! -f /apps/${SLUG_NAME}/slug.tgz ]
380- // do
381- // echo -ne "."
382- // sleep 2
383- // done
384- // fi
385-
386230 // poll the s3 server to ensure the slug exists
387231 lsCmd := mcCmd (configDir , "ls" , pushURL )
388232 for {
@@ -393,43 +237,14 @@ func build(conf *Config, builderKey, gitSha string) error {
393237 }
394238 }
395239
396- //
397- // # build completed
398- //
399- // puts-step "Build complete."
400- // puts-step "Launching app."
401- //
402-
403240 log .Info ("Build complete." )
404241 log .Info ("Launching app." )
405242
406- // URL="http://$DEIS_WORKFLOW_SERVICE_HOST:$DEIS_WORKFLOW_SERVICE_PORT/v2/hooks/config"
407- // RESPONSE=$(get-app-config -url="$URL" -key="{{ getv "/deis/controller/builderKey" }}" -user=$USER -app=$APP_NAME)
408- // CODE=$?
409- // if [ $CODE -ne 0 ]; then
410- // puts-warn $RESPONSE
411- // exit 1
412- // fi
413- //
414-
415243 // Ensure that the app config can be gotten from workflow. We don't do anything with this information
416244 if _ , err := getAppConfig (conf , builderKey , conf .Username , appName ); err != nil {
417245 return fmt .Errorf ("getting app config for %s (%s)" , appName , err )
418246 }
419247
420- // # use Procfile if provided, otherwise try default process types from ./release
421- //
422- // puts-step "Launching... "
423- // URL="http://$DEIS_WORKFLOW_SERVICE_HOST:$DEIS_WORKFLOW_SERVICE_PORT/v2/hooks/build"
424- // DATA="$(generate-buildhook "$SHORT_SHA" "$USER" "$APP_NAME" "$APP_NAME" "$PROCFILE" "$USING_DOCKERFILE")"
425- // PUBLISH_RELEASE=$(echo "$DATA" | publish-release-controller -url=$URL -key={{ getv "/deis/controller/builderKey" }})
426- // CODE=$?
427- // if [ $CODE -ne 0 ]; then
428- // puts-warn "ERROR: Failed to launch container"
429- // puts-warn $PUBLISH_RELEASE
430- // exit 1
431- // fi
432-
433248 log .Info ("Launching..." )
434249
435250 buildHook := & pkg.BuildHook {
@@ -444,16 +259,6 @@ func build(conf *Config, builderKey, gitSha string) error {
444259 if err != nil {
445260 return fmt .Errorf ("publishing release (%s)" , err )
446261 }
447- //
448- // RELEASE=$(echo $PUBLISH_RELEASE | extract-version)
449- // DOMAIN=$(echo $PUBLISH_RELEASE | extract-domain)
450- // indent "done, $APP_NAME:v$RELEASE deployed to Deis"
451- // echo
452- // indent "http://$DOMAIN"
453- // echo
454- // indent "To learn more, use \`deis help\` or visit http://deis.io"
455- // echo
456-
457262 release , ok := buildHookResp .Release ["version" ]
458263 if ! ok {
459264 return fmt .Errorf ("No release returned from Deis controller" )
@@ -467,15 +272,9 @@ func build(conf *Config, builderKey, gitSha string) error {
467272 log .Info (fmt .Sprintf ("http://%s" , domain ))
468273 log .Info ("To learn more, use 'deis help' or visit http://deis.io" )
469274
470- //
471- // # cleanup
472- // cd $REPO_DIR
473- // git gc &>/dev/null
474-
475275 gcCmd := repoCmd (repoDir , "git" , "gc" )
476276 if err := run (gcCmd ); err != nil {
477277 return fmt .Errorf ("cleaning up the repository with %s (%s)" , strings .Join (gcCmd .Args , " " ), err )
478- // TODO: is it ok not to exit even if the repo was not cleaned up
479278 }
480279
481280 return nil
0 commit comments