@@ -18,6 +18,7 @@ import (
1818 "github.com/deis/pkg/log"
1919 "gopkg.in/yaml.v2"
2020
21+ storagedriver "github.com/deis/builder/pkg/storage/driver"
2122 "k8s.io/kubernetes/pkg/api"
2223 client "k8s.io/kubernetes/pkg/client/unversioned"
2324)
@@ -41,7 +42,7 @@ func run(cmd *exec.Cmd) error {
4142 return cmd .Run ()
4243}
4344
44- func build (conf * Config , s3Client * storage. Client , kubeClient * client.Client , fs sys.FS , env sys.Env , builderKey , rawGitSha string ) error {
45+ func build (conf * Config , storageDriver storagedriver. StorageDriver , kubeClient * client.Client , fs sys.FS , env sys.Env , builderKey , rawGitSha string ) error {
4546 repo := conf .Repository
4647 gitSha , err := git .NewSha (rawGitSha )
4748 if err != nil {
@@ -63,7 +64,7 @@ func build(conf *Config, s3Client *storage.Client, kubeClient *client.Client, fs
6364 return fmt .Errorf ("unable to create tmpdir %s (%s)" , buildDir , err )
6465 }
6566
66- slugBuilderInfo := NewSlugBuilderInfo (s3Client . Endpoint , conf . Bucket , appName , slugName , gitSha )
67+ slugBuilderInfo := storage . NewSlugBuilderInfo (slugName )
6768
6869 // Get the application config from the controller, so we can check for a custom buildpack URL
6970 appConf , err := getAppConfig (conf , builderKey , conf .Username , appName )
@@ -100,18 +101,15 @@ func build(conf *Config, s3Client *storage.Client, kubeClient *client.Client, fs
100101 bType := getBuildTypeForDir (tmpDir )
101102 usingDockerfile := bType == buildTypeDockerfile
102103
103- if err := storage .CreateBucket (s3Client , conf .Bucket ); err != nil {
104- log .Warn ("create bucket error: %+v" , err )
105- }
106-
107- appTgzReader , err := os .Open (absAppTgz )
104+ appTgzdata , err := ioutil .ReadFile (absAppTgz )
108105 if err != nil {
109- return fmt .Errorf ("opening %s for read (%s)" , appTgz , err )
106+ return fmt .Errorf ("error while reading file %s: (%s)" , appTgz , err )
110107 }
111108
112- log .Debug ("Uploading tar to %s/%s/%s" , s3Client .Endpoint .FullURL (), conf .Bucket , slugBuilderInfo .TarKey ())
113- if err := storage .UploadObject (s3Client , conf .Bucket , slugBuilderInfo .TarKey (), appTgzReader ); err != nil {
114- return fmt .Errorf ("uploading %s to %s/%s (%v)" , absAppTgz , conf .Bucket , slugBuilderInfo .TarKey (), err )
109+ //log.Debug("Uploading tar to %s/%s/%s", s3Client.Endpoint.FullURL(), conf.Bucket, slugBuilderInfo.TarKey())
110+
111+ if err := storageDriver .PutContent (slugBuilderInfo .TarKey (), appTgzdata ); err != nil {
112+ return fmt .Errorf ("uploading %s to %s (%v)" , absAppTgz , slugBuilderInfo .TarKey (), err )
115113 }
116114
117115 creds := storage .CredsOK (fs )
@@ -126,7 +124,7 @@ func build(conf *Config, s3Client *storage.Client, kubeClient *client.Client, fs
126124 buildPodName ,
127125 conf .PodNamespace ,
128126 appConf .Values ,
129- slugBuilderInfo .TarURL (),
127+ slugBuilderInfo .TarKey (),
130128 slugName ,
131129 conf .StorageRegion ,
132130 conf .DockerBuilderImage ,
@@ -139,10 +137,11 @@ func build(conf *Config, s3Client *storage.Client, kubeClient *client.Client, fs
139137 buildPodName ,
140138 conf .PodNamespace ,
141139 appConf .Values ,
142- slugBuilderInfo .TarURL (),
143- slugBuilderInfo .PushURL (),
140+ slugBuilderInfo .TarKey (),
141+ slugBuilderInfo .PushKey (),
144142 buildPackURL ,
145143 conf .SlugBuilderImage ,
144+ conf .StorageType ,
146145 )
147146 }
148147
@@ -211,17 +210,15 @@ func build(conf *Config, s3Client *storage.Client, kubeClient *client.Client, fs
211210 log .Debug ("Done" )
212211
213212 log .Debug (
214- "Polling the S3 server every %s for %s for the resultant slug at %s/%s " ,
213+ "Polling the S3 server every %s for %s for the resultant slug at %s" ,
215214 conf .ObjectStorageTickDuration (),
216215 conf .ObjectStorageWaitDuration (),
217- conf .Bucket ,
218216 slugBuilderInfo .AbsoluteSlugObjectKey (),
219217 )
220218 // poll the s3 server to ensure the slug exists
221219 if ! usingDockerfile {
222220 if err := storage .WaitForObject (
223- s3Client ,
224- conf .Bucket ,
221+ storageDriver ,
225222 slugBuilderInfo .AbsoluteSlugObjectKey (),
226223 conf .ObjectStorageTickDuration (),
227224 conf .ObjectStorageWaitDuration (),
@@ -232,8 +229,7 @@ func build(conf *Config, s3Client *storage.Client, kubeClient *client.Client, fs
232229
233230 procType := pkg.ProcessType {}
234231 if bType == buildTypeProcfile {
235- getter := & storage.RealObjectGetter {Client : s3Client .Client }
236- if procType , err = getProcFile (getter , tmpDir , conf .Bucket , slugBuilderInfo .AbsoluteProcfileKey ()); err != nil {
232+ if procType , err = getProcFile (storageDriver , tmpDir , slugBuilderInfo .AbsoluteProcfileKey ()); err != nil {
237233 return err
238234 }
239235 }
@@ -276,7 +272,7 @@ func prettyPrintJSON(data interface{}) (string, error) {
276272 return string (formatted .Bytes ()), nil
277273}
278274
279- func getProcFile (getter storage. ObjectGetter , dirName , bucketName , procfileKey string ) (pkg.ProcessType , error ) {
275+ func getProcFile (storageDriver storagedriver. StorageDriver , dirName , procfileKey string ) (pkg.ProcessType , error ) {
280276 procType := pkg.ProcessType {}
281277 if _ , err := os .Stat (fmt .Sprintf ("%s/Procfile" , dirName )); err == nil {
282278 rawProcFile , err := ioutil .ReadFile (fmt .Sprintf ("%s/Procfile" , dirName ))
@@ -289,12 +285,12 @@ func getProcFile(getter storage.ObjectGetter, dirName, bucketName, procfileKey s
289285 return procType , nil
290286 }
291287 log .Debug ("Procfile not present. Getting it from the buildpack" )
292- rawProcFile , err := storage . DownloadObject ( getter , bucketName , procfileKey )
288+ rawProcFile , err := storageDriver . GetContent ( procfileKey )
293289 if err != nil {
294- return nil , fmt .Errorf ("error in reading %s/%s (%s)" , bucketName , procfileKey , err )
290+ return nil , fmt .Errorf ("error in reading %s (%s)" , procfileKey , err )
295291 }
296292 if err := yaml .Unmarshal (rawProcFile , & procType ); err != nil {
297- return nil , fmt .Errorf ("procfile %s/%s is malformed (%s)" , bucketName , procfileKey , err )
293+ return nil , fmt .Errorf ("procfile %s is malformed (%s)" , procfileKey , err )
298294 }
299295 return procType , nil
300296}
0 commit comments