@@ -11,7 +11,6 @@ import (
1111 "path/filepath"
1212 "strings"
1313
14- "github.com/aws/aws-sdk-go/service/s3"
1514 "github.com/deis/builder/pkg"
1615 "github.com/deis/builder/pkg/gitreceive/git"
1716 "github.com/deis/builder/pkg/gitreceive/storage"
@@ -21,7 +20,6 @@ import (
2120
2221 "k8s.io/kubernetes/pkg/api"
2322 client "k8s.io/kubernetes/pkg/client/unversioned"
24- "k8s.io/kubernetes/pkg/util/wait"
2523)
2624
2725// repoCmd returns exec.Command(first, others...) with its current working directory repoDir
@@ -42,7 +40,7 @@ func run(cmd *exec.Cmd) error {
4240 return cmd .Run ()
4341}
4442
45- func build (conf * Config , s3Client * s3. S3 , kubeClient * client.Client , fs sys.FS , env sys.Env , builderKey , rawGitSha string ) error {
43+ func build (conf * Config , s3Client * storage. Client , kubeClient * client.Client , fs sys.FS , env sys.Env , builderKey , rawGitSha string ) error {
4644 repo := conf .Repository
4745 gitSha , err := git .NewSha (rawGitSha )
4846 if err != nil {
@@ -121,7 +119,7 @@ func build(conf *Config, s3Client *s3.S3, kubeClient *client.Client, fs sys.FS,
121119 return fmt .Errorf ("opening %s for read (%s)" , appTgz , err )
122120 }
123121
124- log .Debug ("Uploading tar to %s/%s/%s" , s3Client .Endpoint , conf .Bucket , slugBuilderInfo .TarKey ())
122+ log .Debug ("Uploading tar to %s/%s/%s" , s3Client .Endpoint . FullURL () , conf .Bucket , slugBuilderInfo .TarKey ())
125123 if err := storage .UploadObject (s3Client , conf .Bucket , slugBuilderInfo .TarKey (), appTgzReader ); err != nil {
126124 return fmt .Errorf ("uploading %s to %s/%s (%v)" , absAppTgz , conf .Bucket , slugBuilderInfo .TarKey (), err )
127125 }
@@ -193,11 +191,20 @@ func build(conf *Config, s3Client *s3.S3, kubeClient *client.Client, fs sys.FS,
193191 }
194192 log .Debug ("size of streamed logs %v" , size )
195193
194+ log .Debug (
195+ "Waiting for the %s/%s pod to end. Checking every %s for %s" ,
196+ newPod .Namespace ,
197+ newPod .Name ,
198+ conf .BuilderPodTickDuration (),
199+ conf .BuilderPodWaitDuration (),
200+ )
196201 // check the state and exit code of the build pod.
197202 // if the code is not 0 return error
198203 if err := waitForPodEnd (kubeClient , newPod .Namespace , newPod .Name , conf .BuilderPodTickDuration (), conf .BuilderPodWaitDuration ()); err != nil {
199204 return fmt .Errorf ("error getting builder pod status (%s)" , err )
200205 }
206+ log .Debug ("Done" )
207+ log .Debug ("Checking for builder pod exit code" )
201208 buildPod , err := kubeClient .Pods (newPod .Namespace ).Get (newPod .Name )
202209 if err != nil {
203210 return fmt .Errorf ("error getting builder pod status (%s)" , err )
@@ -209,37 +216,30 @@ func build(conf *Config, s3Client *s3.S3, kubeClient *client.Client, fs sys.FS,
209216 return fmt .Errorf ("Build pod exited with code %d, stopping build." , state .ExitCode )
210217 }
211218 }
212-
219+ log .Debug ("Done" )
220+
221+ log .Debug (
222+ "Polling the S3 server every %s for %s for the resultant slug at %s/%s" ,
223+ conf .ObjectStorageTickDuration (),
224+ conf .ObjectStorageWaitDuration (),
225+ conf .Bucket ,
226+ slugBuilderInfo .AbsoluteSlugObjectKey (),
227+ )
213228 // poll the s3 server to ensure the slug exists
214- err = wait .PollImmediate (conf .ObjectStorageTickDuration (), conf .ObjectStorageWaitDuration (), func () (bool , error ) {
215- exists , err := storage .ObjectExists (s3Client , conf .Bucket , slugBuilderInfo .PushKey ())
216- if err != nil {
217- return false , fmt .Errorf ("Checking if object %s/%s exists (%s)" , conf .Bucket , slugBuilderInfo .PushKey (), err )
218- }
219- return exists , nil
220- })
221-
222- if err != nil {
223- return fmt .Errorf ("Timed out waiting for object in storage. Aborting build..." )
229+ if err := storage .WaitForObject (
230+ s3Client ,
231+ conf .Bucket ,
232+ slugBuilderInfo .AbsoluteSlugObjectKey (),
233+ conf .ObjectStorageTickDuration (),
234+ conf .ObjectStorageWaitDuration (),
235+ ); err != nil {
236+ return fmt .Errorf ("Timed out waiting for object in storage, aborting build (%s)" , err )
224237 }
225238 log .Info ("Build complete." )
226239 log .Info ("Launching app." )
227240 log .Info ("Launching..." )
228241
229- buildHook := & pkg.BuildHook {
230- Sha : gitSha .Short (),
231- ReceiveUser : conf .Username ,
232- ReceiveRepo : appName ,
233- Image : appName ,
234- Procfile : procType ,
235- }
236- if ! usingDockerfile {
237- buildHook .Dockerfile = ""
238- // need this to tell the controller what URL to give the slug runner
239- buildHook .Image = slugBuilderInfo .PushURL () + "/slug.tgz"
240- } else {
241- buildHook .Dockerfile = "true"
242- }
242+ buildHook := createBuildHook (slugBuilderInfo , gitSha , conf .Username , appName , procType , usingDockerfile )
243243 buildHookResp , err := publishRelease (conf , builderKey , buildHook )
244244 if err != nil {
245245 return fmt .Errorf ("publishing release (%s)" , err )
0 commit comments