@@ -23,19 +23,16 @@ class DeployerError(Exception):
2323 def __init__ (self , message ):
2424 self .message = message
2525 error (message )
26- raise SystemExit (1 )
2726
2827
2928def get_params ():
3029 parser = argparse .ArgumentParser (description = "Orlo Test Deployer" )
3130 parser .add_argument ('packages' , choices = None , const = None , nargs = '*' ,
32- help = "Packages to deploy, in format package_name=version, "
33- "e.g test-package=1.0.0" )
31+ help = "Packages to deploy, in format "
32+ "package_name=version, e.g test-package=1.0.0" )
3433 args , unknown = parser .parse_known_args ()
3534
3635 _packages = OrderedDict ()
37- if not args .packages :
38- raise DeployerError ("No packages to deploy, see help" )
3936
4037 for pkg in args .packages :
4138 package , version = pkg .split ('=' )
@@ -62,13 +59,14 @@ def deploy(package, meta=None):
6259 :param dict meta: Dictionary of metadata (unused in this dummy function)
6360 :return:
6461 """
62+ info ("Package start - {}:{}" .format (package .name , package .version ))
6563 orlo_client .package_start (package )
6664
67- # Do the deploy...
68-
65+ # Do stuff
6966 # Determining success status is up to you
7067 success = True
7168
69+ info ("Package stop - {}:{}" .format (package .name , package .version ))
7270 orlo_client .package_stop (package , success = success )
7371
7472 return success
@@ -79,33 +77,45 @@ def deploy(package, meta=None):
7977 orlo_url = os .environ ['ORLO_URL' ]
8078 else :
8179 # This deployer is only every supposed to accept releases from Orlo
82- # Other deployers could use this to detect whether they are being invoked by Orlo
80+ # Other deployers could use this to detect whether they are being
81+ # invoked by Orlo
8382 raise DeployerError ("Could not detect ORLO_URL from environment" )
8483
8584 if os .getenv ('ORLO_RELEASE' ):
86- orlo_release = os .environ ['ORLO_RELEASE' ]
85+ orlo_release_id = os .environ ['ORLO_RELEASE' ]
8786 else :
8887 raise DeployerError ("Could not detect ORLO_RELEASE in environment" )
8988
89+ logging .info (
90+ "Environment: \n " +
91+ json .dumps (os .environ , indent = 2 , default = lambda o : o .__dict__ ))
92+
93+ # Fetch packages and metadata. Packages is not used, it is just to
94+ # demonstrate they are passed as arguments
9095 packages , metadata = get_params ()
9196
97+ logging .info ("Stdin: \n " + str (metadata ))
98+
99+ # Create an instance of the Orlo client
92100 orlo_client = OrloClient (uri = orlo_url )
93- # The release is created in Orlo before being handed to the deployer
94- # So fetch it here
95- release = orlo_client .get_release (orlo_release )
96101
97- # TODO - using package info from arguments makes no sense when we could fetch from Orlo
98- orlo_packages = []
99- for p , v in packages .items ():
100- info ("Creating Package {}:{}" .format (p , v ))
101- pkg = orlo_client .create_package (release , p , v )
102- orlo_packages .append (pkg )
102+ # The release is created in Orlo before the deployer is invoked, so fetch
103+ # it here. If you prefer, you can to do the release creation within your
104+ # deployer and use Orlo only for receiving data
105+ release = orlo_client .get_release (orlo_release_id )
106+
107+ # While we fetch Packages using the Orlo client, they are passed on the
108+ # CLI as well, which is useful for non-python deployers
109+ info ("Fetching packages from Orlo" )
110+ if not release .packages :
111+ raise DeployerError ("No packages to deploy" )
103112
104113 info ("Starting Release" )
105- for pkg in orlo_packages :
114+ for pkg in release . packages :
106115 info ("Deploying {}" .format (pkg .name ))
107116 deploy (pkg , meta = metadata )
108- info ("Finishing Release" )
109117
118+ info ("Finishing Release" )
110119 orlo_client .release_stop (release )
120+
111121 info ("Done." )
0 commit comments