def _PossiblyBuildAndPush(self, new_version, service, image, code_bucket_ref): """Builds and Pushes the Docker image if necessary for this service. Args: new_version: version_util.Version describing where to deploy the service service: yaml_parsing.ServiceYamlInfo, service configuration to be deployed image: str or None, the URL for the Docker image to be deployed (if image already exists). code_bucket_ref: cloud_storage.BucketReference where the service's files have been uploaded Returns: str, The name of the pushed or given container image or None if the service does not require an image. """ if service.RequiresImage(): if service.env == util.Environment.FLEXIBLE: log.warning( 'Deployment of App Engine Flexible Environment apps is ' 'currently in Beta') if not image: image = deploy_command_util.BuildAndPushDockerImage( new_version.project, service, new_version.id, code_bucket_ref) else: image = None return image
def _PossiblyBuildAndPush(self, new_version, service, source_dir, image, code_bucket_ref, gcr_domain): """Builds and Pushes the Docker image if necessary for this service. Args: new_version: version_util.Version describing where to deploy the service service: yaml_parsing.ServiceYamlInfo, service configuration to be deployed source_dir: str, path to the service's source directory image: str or None, the URL for the Docker image to be deployed (if image already exists). code_bucket_ref: cloud_storage.BucketReference where the service's files have been uploaded gcr_domain: str, Cloud Registry domain, determines the physical location of the image. E.g. `us.gcr.io`. Returns: str, The name of the pushed or given container image or None if the service does not require an image. """ if service.RequiresImage(): if not image: image = deploy_command_util.BuildAndPushDockerImage( new_version.project, service, source_dir, new_version.id, code_bucket_ref, gcr_domain, self.deploy_options.runtime_builder_strategy) elif service.parsed.skip_files.regex: log.warning( 'Deployment of service [{0}] will ignore the skip_files ' 'field in the configuration file, because the image has ' 'already been built.'.format(new_version.service)) else: image = None return image
def _PossiblyBuildAndPush(self, new_version, service, source_dir, image, code_bucket_ref): """Builds and Pushes the Docker image if necessary for this service. Args: new_version: version_util.Version describing where to deploy the service service: yaml_parsing.ServiceYamlInfo, service configuration to be deployed source_dir: str, path to the service's source directory image: str or None, the URL for the Docker image to be deployed (if image already exists). code_bucket_ref: cloud_storage.BucketReference where the service's files have been uploaded Returns: str, The name of the pushed or given container image or None if the service does not require an image. """ if service.RequiresImage(): if service.env in [util.Environment.FLEX, util.Environment.MANAGED_VMS]: log.warning('Deployment of App Engine Flexible Environment apps is ' 'currently in Beta') if not image: image = deploy_command_util.BuildAndPushDockerImage( new_version.project, service, source_dir, new_version.id, code_bucket_ref, self.deploy_options.use_runtime_builders) elif service.parsed.skip_files.regex: log.warning('Deployment of service [{0}] will ignore the skip_files ' 'field in the configuration file, because the image has ' 'already been built.'.format(new_version.service)) else: image = None return image
def _PossiblyBuildAndPush( self, new_version, service, upload_dir, source_files, image, code_bucket_ref, gcr_domain, flex_image_build_option): """Builds and Pushes the Docker image if necessary for this service. Args: new_version: version_util.Version describing where to deploy the service service: yaml_parsing.ServiceYamlInfo, service configuration to be deployed upload_dir: str, path to the service's upload directory source_files: [str], relative paths to upload. image: str or None, the URL for the Docker image to be deployed (if image already exists). code_bucket_ref: cloud_storage.BucketReference where the service's files have been uploaded gcr_domain: str, Cloud Registry domain, determines the physical location of the image. E.g. `us.gcr.io`. flex_image_build_option: FlexImageBuildOptions, whether a flex deployment should upload files so that the server can build the image or build the image on client. Returns: BuildArtifact, a wrapper which contains either the build ID for an in-progress build, or the name of the container image for a serial build. Possibly None if the service does not require an image. Raises: RequiredFileMissingError: if a required file is not uploaded. """ build = None if image: if service.RequiresImage() and service.parsed.skip_files.regex: log.warning('Deployment of service [{0}] will ignore the skip_files ' 'field in the configuration file, because the image has ' 'already been built.'.format(new_version.service)) return app_cloud_build.BuildArtifact.MakeImageArtifact(image) elif service.RequiresImage(): if not _AppYamlInSourceFiles(source_files, service.GetAppYamlBasename()): raise RequiredFileMissingError(service.GetAppYamlBasename()) if flex_image_build_option == FlexImageBuildOptions.ON_SERVER: cloud_build_options = { 'appYamlPath': service.GetAppYamlBasename(), } timeout = properties.VALUES.app.cloud_build_timeout.Get() if timeout: build_timeout = int( times.ParseDuration(timeout, default_suffix='s').total_seconds) cloud_build_options['cloudBuildTimeout'] = six.text_type( build_timeout) + 's' build = app_cloud_build.BuildArtifact.MakeBuildOptionsArtifact( cloud_build_options) else: build = deploy_command_util.BuildAndPushDockerImage( new_version.project, service, upload_dir, source_files, new_version.id, code_bucket_ref, gcr_domain, self.deploy_options.runtime_builder_strategy, self.deploy_options.parallel_build) return build
def _PossiblyBuildAndPush(self, new_version, service, source_dir, image, code_bucket_ref, gcr_domain, flex_image_build_option): """Builds and Pushes the Docker image if necessary for this service. Args: new_version: version_util.Version describing where to deploy the service service: yaml_parsing.ServiceYamlInfo, service configuration to be deployed source_dir: str, path to the service's source directory image: str or None, the URL for the Docker image to be deployed (if image already exists). code_bucket_ref: cloud_storage.BucketReference where the service's files have been uploaded gcr_domain: str, Cloud Registry domain, determines the physical location of the image. E.g. `us.gcr.io`. flex_image_build_option: FlexImageBuildOptions, whether a flex deployment should upload files so that the server can build the image or build the image on client. Returns: BuildArtifact, a wrapper which contains either the build ID for an in-progress build, or the name of the container image for a serial build. Possibly None if the service does not require an image. """ if flex_image_build_option == FlexImageBuildOptions.ON_SERVER: return None build = None if image: if service.RequiresImage() and service.parsed.skip_files.regex: log.warning( 'Deployment of service [{0}] will ignore the skip_files ' 'field in the configuration file, because the image has ' 'already been built.'.format(new_version.service)) return cloud_build.BuildArtifact.MakeImageArtifact(image) elif service.RequiresImage(): build = deploy_command_util.BuildAndPushDockerImage( new_version.project, service, source_dir, new_version.id, code_bucket_ref, gcr_domain, self.deploy_options.runtime_builder_strategy, self.deploy_options.parallel_build) return build
def Deploy(self, service, new_version, code_bucket_ref, image, all_services): """Deploy the given service. Performs all deployment steps for the given service (if applicable): * Enable endpoints (for beta deployments) * Build and push the Docker image (Flex only, if image_url not provided) * Upload files (non-hermetic deployments) * Create the new version * Promote the version to receieve all traffic (if --promote given (default)) * Stop the previous version (if new version promoted and --stop-previous-version given (default)) Args: service: yaml_parsing.ServiceYamlInfo, service configuration to be deployed new_version: version_util.Version describing where to deploy the service code_bucket_ref: cloud_storage.BucketReference where the service's files have been uploaded image: str or None, the URL for the Docker image to be deployed (if image already exists). all_services: dict of service ID to service_util.Service objects corresponding to all pre-existing services (used to determine how to promote this version to receive all traffic, if applicable). """ log.status.Print( 'Beginning deployment of service [{service}]...'.format( service=new_version.service)) # If the app has enabled Endpoints API Management features, pass # control to the cloud_endpoints handler. # The cloud_endpoints handler calls the Service Management APIs and # creates an endpoints/service.json file on disk which will need to # be bundled into the app Docker image. if self.deploy_options.enable_endpoints: cloud_endpoints.ProcessEndpointsService(service, new_version.project) # Build and Push the Docker image if necessary for this service. if service.RequiresImage(): log.warning( 'Deployment of App Engine Flexible Environment apps is ' 'currently in Beta') if not image: image = deploy_command_util.BuildAndPushDockerImage( new_version.project, service, new_version.id, code_bucket_ref) else: image = None manifest = _UploadFiles(service, code_bucket_ref) # Actually create the new version of the service. message = 'Updating service [{service}]'.format( service=new_version.service) with console_io.ProgressTracker(message): self.api_client.DeployService(new_version.service, new_version.id, service, manifest, image) metrics.CustomTimedEvent(metric_names.DEPLOY_API) if self.deploy_options.promote: try: version_util.PromoteVersion( all_services, new_version, self.api_client, self.deploy_options.stop_previous_version) except calliope_exceptions.HttpException as err: raise VersionPromotionError(err) elif self.deploy_options.stop_previous_version: log.info( 'Not stopping previous version because new version was ' 'not promoted.')