Browse code

build system: configurable sources repo support

make PHOTON_PULLSOURCES_CONFIG=myrepo.conf will pull sources from
alternative repo (myrepo) instead of bintray.

--- myrepo.conf format ---
{
"baseurl":"http://myhost/path/to/sources/",
"user":"",
"apikey":""
}

Change-Id: I29e49d1613f803726c039f5b08c8eb30c33651be
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/2708
Reviewed-by: Vinay Kulkarni <kulkarniv@vmware.com>
Tested-by: gerrit-photon <photon-checkins@vmware.com>
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/2789
Reviewed-by: Priyesh Padmavilasom <ppadmavilasom@vmware.com>

Alexey Makhalov authored on 2017/05/19 06:22:19
Showing 7 changed files
... ...
@@ -96,7 +96,7 @@ packages-micro: check $(PHOTON_STAGE) $(PHOTON_PUBLISH_RPMS) $(PHOTON_SOURCES) g
96 96
                 -b $(PHOTON_CHROOT_PATH) \
97 97
                 -l $(PHOTON_LOGS_DIR) \
98 98
                 -p $(PHOTON_PUBLISH_RPMS_DIR) \
99
-                -c $(PHOTON_BINTRAY_CONFIG) \
99
+                -c $(PHOTON_PULLSOURCES_CONFIG) \
100 100
                 -d $(PHOTON_DIST_TAG) \
101 101
                 -n $(PHOTON_BUILD_NUMBER) \
102 102
                 -v $(PHOTON_RELEASE_VERSION) \
... ...
@@ -165,7 +165,7 @@ packages-minimal: check $(PHOTON_STAGE) $(PHOTON_PUBLISH_RPMS) $(PHOTON_SOURCES)
165 165
                 -b $(PHOTON_CHROOT_PATH) \
166 166
                 -l $(PHOTON_LOGS_DIR) \
167 167
                 -p $(PHOTON_PUBLISH_RPMS_DIR) \
168
-                -c $(PHOTON_BINTRAY_CONFIG) \
168
+                -c $(PHOTON_PULLSOURCES_CONFIG) \
169 169
                 -d $(PHOTON_DIST_TAG) \
170 170
                 -n $(PHOTON_BUILD_NUMBER) \
171 171
                 -v $(PHOTON_RELEASE_VERSION) \
... ...
@@ -246,7 +246,7 @@ packages: check $(PHOTON_STAGE) $(PHOTON_PUBLISH_XRPMS) $(PHOTON_PUBLISH_RPMS) $
246 246
                 -l $(PHOTON_LOGS_DIR) \
247 247
 		-e $(PHOTON_PUBLISH_XRPMS_DIR) \
248 248
                 -p $(PHOTON_PUBLISH_RPMS_DIR) \
249
-                -c $(PHOTON_BINTRAY_CONFIG) \
249
+                -c $(PHOTON_PULLSOURCES_CONFIG) \
250 250
                 -d $(PHOTON_DIST_TAG) \
251 251
                 -n $(PHOTON_BUILD_NUMBER) \
252 252
                 -v $(PHOTON_RELEASE_VERSION) \
... ...
@@ -265,8 +265,8 @@ updated-packages: check $(PHOTON_STAGE) $(PHOTON_PUBLISH_XRPMS) $(PHOTON_PUBLISH
265 265
                 -b $(PHOTON_CHROOT_PATH) \
266 266
                 -l $(PHOTON_LOGS_DIR) \
267 267
                 -p $(PHOTON_PUBLISH_RPMS_DIR) \
268
-				-e $(PHOTON_PUBLISH_XRPMS_DIR) \
269
-                -c $(PHOTON_BINTRAY_CONFIG) \
268
+                -e $(PHOTON_PUBLISH_XRPMS_DIR) \
269
+                -c $(PHOTON_PULLSOURCES_CONFIG) \
270 270
                 -d $(PHOTON_DIST_TAG) \
271 271
                 -n $(PHOTON_BUILD_NUMBER) \
272 272
                 -v $(PHOTON_RELEASE_VERSION) \
... ...
@@ -286,7 +286,7 @@ tool-chain-stage1: check $(PHOTON_STAGE) $(PHOTON_PUBLISH_RPMS) $(PHOTON_SOURCES
286 286
                 -l $(PHOTON_LOGS_DIR) \
287 287
                 -p $(PHOTON_PUBLISH_RPMS_DIR) \
288 288
                 -t ${THREADS} \
289
-                -c $(PHOTON_BINTRAY_CONFIG) \
289
+                -c $(PHOTON_PULLSOURCES_CONFIG) \
290 290
                 -d $(PHOTON_DIST_TAG) \
291 291
                 -n $(PHOTON_BUILD_NUMBER) \
292 292
                 -v $(PHOTON_RELEASE_VERSION) \
... ...
@@ -305,7 +305,7 @@ tool-chain-stage2: check $(PHOTON_STAGE) $(PHOTON_PUBLISH_RPMS) $(PHOTON_SOURCES
305 305
                 -l $(PHOTON_LOGS_DIR) \
306 306
                 -p $(PHOTON_PUBLISH_RPMS_DIR) \
307 307
                 -t ${THREADS} \
308
-                -c $(PHOTON_BINTRAY_CONFIG) \
308
+                -c $(PHOTON_PULLSOURCES_CONFIG) \
309 309
                 -d $(PHOTON_DIST_TAG) \
310 310
                 -n $(PHOTON_BUILD_NUMBER) \
311 311
                 -v $(PHOTON_RELEASE_VERSION) \
... ...
@@ -321,7 +321,6 @@ packages-cached:
321 321
      $(CP) -f $(PHOTON_CACHE_PATH)/RPMS/x86_64/* $(PHOTON_RPMS_DIR_X86_64)/
322 322
 
323 323
 sources:
324
-	@echo "Pulling sources from bintray...(nothing to do)"
325 324
 	@$(MKDIR) -p $(PHOTON_SRCS_DIR)
326 325
 
327 326
 sources-cached:
... ...
@@ -532,8 +531,8 @@ check-packer-ovf-plugin:
532 532
                               -a $(PHOTON_SRPMS_DIR) \
533 533
                               -x $(PHOTON_SRCS_DIR) \
534 534
                               -p $(PHOTON_PUBLISH_RPMS_DIR) \
535
-							  -e $(PHOTON_PUBLISH_XRPMS_DIR) \
536
-                              -c $(PHOTON_BINTRAY_CONFIG) \
535
+                              -e $(PHOTON_PUBLISH_XRPMS_DIR) \
536
+                              -c $(PHOTON_PULLSOURCES_CONFIG) \
537 537
                               -d $(PHOTON_DIST_TAG) \
538 538
                               -n $(PHOTON_BUILD_NUMBER) \
539 539
                               -v $(PHOTON_RELEASE_VERSION) \
... ...
@@ -40,7 +40,11 @@ PHOTON_INSTALLER=$(PHOTON_INSTALLER_DIR)/photonInstaller.py
40 40
 PHOTON_SPECDEPS_DIR=$(SRCROOT)/support/SpecDeps
41 41
 PHOTON_SPECDEPS=$(PHOTON_SPECDEPS_DIR)/SpecDeps.py
42 42
 PHOTON_PACKAGE_BUILDER=$(PHOTON_PKG_BUILDER_DIR)/builder.py
43
-PHOTON_BINTRAY_CONFIG?=$(PHOTON_PKG_BUILDER_DIR)/pullsources.conf
43
+ifdef PHOTON_PULLSOURCES_CONFIG
44
+PHOTON_PULLSOURCES_CONFIG=$(abspath $(PHOTON_PULLSOURCES_CONFIG))
45
+else
46
+PHOTON_PULLSOURCES_CONFIG?=$(PHOTON_PKG_BUILDER_DIR)/bintray.conf
47
+endif
44 48
 PHOTON_PULL_PUBLISH_RPMS=$(PHOTON_PULL_PUBLISH_RPMS_DIR)/pullpublishrpms.sh
45 49
 PHOTON_PULL_PUBLISH_X_RPMS=$(PHOTON_PULL_PUBLISH_RPMS_DIR)/pullpublishXrpms.sh
46 50
 PHOTON_CLOUD_IMAGE_BUILDER=$(PHOTON_CLOUD_IMAGE_BUILDER_DIR)/cloud-image-build.sh
... ...
@@ -111,7 +111,7 @@ class PackageUtils(object):
111 111
             # Fetch/verify sources if sha1 not None.
112 112
             sha1 = constants.specData.getSHA1(package, source)
113 113
             if sha1 is not None:
114
-                PullSources.get(source, sha1, constants.sourcePath, constants.pullsourcesConfig)
114
+                PullSources.get(source, sha1, constants.sourcePath, constants.pullsourcesConfig, self.logger)
115 115
 
116 116
             sourcePath = cmdUtils.findFile(source,constants.sourcePath)
117 117
             if sourcePath is None or len(sourcePath) == 0:
... ...
@@ -1,11 +1,11 @@
1 1
 #! /usr/bin/python2
2 2
 #
3
-#    Copyright (C) 2015 VMware, Inc. All rights reserved.
3
+#    Copyright (C) 2015-2017 VMware, Inc. All rights reserved.
4 4
 #    pullsources.py 
5
-#    Allows pulling packages'sources from a bintary  
6
-#    repository.
5
+#    Allows pulling packages'sources from a source repository.
7 6
 #
8 7
 #    Author(s): Mahmoud Bassiouny (mbassiouny@vmware.com)
8
+#               Alexey Makhalov (amakhalov@vmware.com)
9 9
 #
10 10
 
11 11
 import json
... ...
@@ -25,7 +25,7 @@ def getFileHash(filepath):
25 25
         f.close()
26 26
     return sha1.hexdigest()
27 27
 
28
-def get(source, sha1, sourcesPath, configs):
28
+def get(source, sha1, sourcesPath, configs, logger):
29 29
     cmdUtils = CommandUtils()
30 30
     sourcePath = cmdUtils.findFile(source, sourcesPath)
31 31
     if sourcePath is not None and len(sourcePath) > 0:
... ...
@@ -34,21 +34,24 @@ def get(source, sha1, sourcesPath, configs):
34 34
         if sha1 == getFileHash(sourcePath[0]):
35 35
             # Use file from sourcesPath
36 36
             return
37
+        else:
38
+            logger.info("sha1 of "+sourcePath[0]+" does not match. "+sha1+" vs "+getFileHash(sourcePath[0]))
37 39
     configFiles=configs.split(":")
38 40
     for config in configFiles:
39
-        p = pullSources(config)
41
+        p = pullSources(config, logger)
40 42
         package_path = os.path.join(sourcesPath, source)
41 43
         try: 
42 44
             p.downloadFileHelper(source, package_path, sha1)
43 45
             return
44 46
         except Exception as e:
45
-            print e
47
+            logger.error(e)
46 48
     raise Exception("Missing source: "+source)
47 49
 
48 50
 class pullSources:
49 51
 
50
-    def __init__(self, conf_file):
52
+    def __init__(self, conf_file, logger):
51 53
         self._config = {}
54
+        self.logger=logger
52 55
         self.loadConfig(conf_file)
53 56
 
54 57
         # generate the auth
... ...
@@ -63,14 +66,9 @@ class pullSources:
63 63
 
64 64
     def downloadFile(self, filename, file_path):
65 65
         #form url: https://dl.bintray.com/vmware/photon_sources/1.0/<filename>.
66
-        url = '%s/%s/%s/%s/%s' % \
67
-              (self._config['baseurl'],\
68
-               self._config['subject'],\
69
-               self._config['repo'],\
70
-               self._config['version'],\
71
-               filename)
66
+        url = '%s/%s' % (self._config['baseurl'], filename)
72 67
 
73
-        print '%s: Downloading %s...' % (str(datetime.datetime.today()), url)
68
+        self.logger.info("Downloading: "+url)
74 69
 
75 70
         with open(file_path, 'wb') as handle:
76 71
             response = requests.get(url, auth=self._auth, stream=True)
77 72
new file mode 100644
... ...
@@ -0,0 +1,5 @@
0
+{
1
+  "baseurl":"https://dl.bintray.com/vmware/photon_sources/1.0",
2
+  "user":"",
3
+  "apikey":""
4
+}
... ...
@@ -190,7 +190,7 @@ def buildSourcesList(yamlDir, logger, singleFile=True):
190 190
             sourceName=listSourceNames[0]
191 191
             sha1 = constants.specData.getSHA1(package, sourceName)
192 192
             if sha1 is not None:
193
-                PullSources.get(sourceName, sha1, yamlDir, constants.pullsourcesConfig)
193
+                PullSources.get(sourceName, sha1, yamlDir, constants.pullsourcesConfig, logger)
194 194
 
195 195
         if not singleFile:
196 196
             yamlFile = open(yamlDir+"/"+ossname+"-"+ossversion+".yaml", "w")
197 197
deleted file mode 100644
... ...
@@ -1,8 +0,0 @@
1
-{
2
-  "baseurl":"https://dl.bintray.com",
3
-  "subject":"vmware",
4
-  "repo":"photon_sources",
5
-  "version":"1.0",
6
-  "user":"", 
7
-  "apikey":""
8
-}