Example #1
0
    def deploy(self, project_config: ProjectConfig, output: AbstractOutputWriter, dry_run=False):
        # check that it's not a Nitro-based instance
        if is_nitro_instance(self.instance_config.instance_type):
            raise ValueError('Currently Nitro-based instances are not supported.')

        # check availability zone and subnet configuration
        check_az_and_subnet(self._ec2, self.instance_config.region, self.instance_config.availability_zone,
                            self.instance_config.subnet_id)

        # get volumes
        volumes = self._get_volumes()

        # get deployment availability zone
        availability_zone = self._get_availability_zone(volumes)

        # check the maximum price for a spot instance
        check_max_price(self._ec2, self.instance_config.instance_type, self.instance_config.on_demand,
                        self.instance_config.max_price, availability_zone)

        # create or get existing bucket for the project
        bucket_name = self.bucket.get_or_create_bucket(output, project_config.tags, dry_run)

        # sync the project with the bucket
        output.write('Syncing the project with S3 bucket...')
        sync_project_with_s3(project_config.project_dir, bucket_name, self.instance_config.region,
                             project_config.sync_filters, dry_run)

        # create or update instance profile
        if not dry_run:
            instance_profile_stack = InstanceProfileStackResource(
                self._project_name, self.instance_config.name, self.instance_config.region)
            instance_profile_arn = instance_profile_stack.create_or_update_stack(
                self.instance_config.managed_policy_arns, output=output, tags=project_config.tags)
        else:
            instance_profile_arn = None

        output.write('Preparing CloudFormation template...')

        # prepare CloudFormation template
        container = ContainerDeployment(project_config.project_name, volumes, project_config.container)
        with output.prefix('  '):
            template = prepare_instance_template(self.instance_config, volumes, availability_zone, container,
                                                 output)

            # get parameters for the template
            parameters = self._get_template_parameters(instance_profile_arn, self.instance_config.name, bucket_name,
                                                       project_config.sync_filters, volumes, container, output,
                                                       dry_run=dry_run)

        # print information about the volumes
        output.write('\nVolumes:\n%s\n' % render_volumes_info_table(container.volume_mounts, volumes))

        # create stack
        if not dry_run:
            self.stack.create_or_update_stack(template, parameters, output, project_config.tags)
Example #2
0
    def sync(self, output: AbstractOutputWriter, dry_run=False):
        # create or get existing bucket for the project
        bucket_name = self.instance_deployment.bucket.get_or_create_bucket(
            output, dry_run)

        # sync the project with S3 bucket
        output.write('Syncing the project with S3 bucket...')
        sync_project_with_s3(self.project_config.project_dir,
                             bucket_name,
                             self.instance_config.region,
                             self.project_config.sync_filters,
                             dry_run=dry_run)

        if not dry_run:
            # sync S3 with the instance
            output.write('Syncing S3 bucket with the instance...')
            sync_instance_with_s3(self.project_config.sync_filters,
                                  self.get_ip_address(), self.ssh_port,
                                  self.ssh_user, self.ssh_key_path)