5
5
from glob import glob
6
6
7
7
from .state import ApplicationState
8
+ from .ecr_helper import ECRHelper
8
9
9
10
from app_pack_generator import GitManager , DockerUtil , ApplicationNotebook
10
11
from app_pack_generator import ProcessCWL , DataStagingCWL , Descriptor
@@ -18,7 +19,8 @@ class ApplicationGenerationError(Exception):
18
19
19
20
class UnityApplicationGenerator (object ):
20
21
21
- def __init__ (self , state_directory , source_repository = None , destination_directory = None , checkout = None , use_owner = True ):
22
+ def __init__ (self , state_directory , source_repository = None , destination_directory = None , checkout = None ,
23
+ use_namespace = None , use_repository = None , use_tag = None ):
22
24
23
25
if not ApplicationState .exists (state_directory ):
24
26
self .repo_info = self ._localize_source (source_repository , destination_directory , checkout )
@@ -27,34 +29,54 @@ def __init__(self, state_directory, source_repository=None, destination_director
27
29
self .app_state = ApplicationState (state_directory )
28
30
self .repo_info = self ._localize_source (self .app_state .source_repository , self .app_state .app_base_path , checkout )
29
31
30
- self .docker_util = DockerUtil (self .repo_info , do_prune = False , use_owner = use_owner )
32
+ # Use value from command line to override values saved into app state
33
+ image_namespace = use_namespace if use_namespace is not None else self .app_state .docker_image_namespace
34
+ image_repository = use_repository if use_repository is not None else self .app_state .docker_image_repository
35
+ image_tag = use_tag if use_tag is not None else self .app_state .docker_image_tag
36
+
37
+ self .docker_util = DockerUtil (self .repo_info , do_prune = False ,
38
+ use_namespace = image_namespace ,
39
+ use_repository = image_repository ,
40
+ use_tag = image_tag )
31
41
32
42
def _localize_source (self , source , dest , checkout ):
33
43
34
44
# Check out original repository
35
45
git_mgr = GitManager (source , dest )
36
46
37
47
if checkout is not None :
38
- logger .debug (f"Checking out { checkout } in { repo_dir } " )
48
+ logger .info (f"Checking out { checkout } in { repo_dir } " )
39
49
git_mgr .checkout (checkout )
40
50
41
51
return git_mgr
42
52
43
53
def create_docker_image (self ):
54
+
55
+ # These come either from the commandline or are generated by Docker util
56
+ self .app_state .docker_image_namespace = self .docker_util .image_namespace
57
+ self .app_state .docker_image_repository = self .docker_util .image_repository
58
+ self .app_state .docker_image_tag = self .docker_util .image_tag
44
59
45
60
# Create Docker image
46
- self .app_state .docker_image_tag = self .docker_util .repo2docker ()
47
-
48
- def push_to_docker_registry (self , docker_registry , image_tag = None ):
61
+ self .app_state .docker_image_reference = self .docker_util .build_image ()
49
62
50
- if image_tag is not None :
51
- self .app_state .docker_image_tag = image_tag
52
-
53
- if self .app_state .docker_image_tag is None :
54
- raise ApplicationGenerationError ("Cannot push Docker image to registry without a valid tag. Run the Docker build command or supply an image tag as an argument." )
63
+ def push_to_docker_registry (self , docker_registry ):
55
64
56
65
# Push to remote repository
57
- self .app_state .docker_url = self .docker_util .push_image (docker_registry , self .app_state .docker_image_tag )
66
+ self .app_state .docker_url = self .docker_util .push_image (docker_registry , self .app_state .docker_image_reference )
67
+
68
+ def push_to_aws_ecr (self ):
69
+
70
+ ecr_helper = ECRHelper (self .docker_util )
71
+
72
+ # Create an ECR registry if it doesn't already exist
73
+ ecr_helper .create_repository ()
74
+
75
+ # Log in to ECR via Docker
76
+ registry_url = ecr_helper .docker_login ()
77
+
78
+ # Push docker image into ECR
79
+ self .push_to_docker_registry (registry_url )
58
80
59
81
def _generate_dockstore_cwl (self , cwl_output_path , target_cwl_filename ):
60
82
@@ -77,12 +99,12 @@ def _generate_dockstore_cwl(self, cwl_output_path, target_cwl_filename):
77
99
78
100
def create_cwl (self , cwl_output_path = None , docker_url = None , monolithic = False ):
79
101
80
- # Fall through using docker_image_tag if docker_url does not exist because no push has occurred
102
+ # Fall through using docker_image_reference if docker_url does not exist because no push has occurred
81
103
# Or if docker_url is supplied as an argument use that
82
104
if docker_url is None and self .app_state .docker_url is not None :
83
105
docker_url = self .app_state .docker_url
84
- elif docker_url is None and self .app_state .docker_image_tag is not None :
85
- docker_url = self .app_state .docker_image_tag
106
+ elif docker_url is None and self .app_state .docker_image_reference is not None :
107
+ docker_url = self .app_state .docker_image_reference
86
108
elif docker_url is None :
87
109
raise ApplicationGenerationError ("Cannot create CWL files when Docker image tag or URL has not yet been registered through building and/or pushing Docker image" )
88
110
0 commit comments