Esempio n. 1
0
    def add_vaues_for_bucket_placeholder(self):
        input_sh_file = os.path.join(self.dest_dir, self.docker_dir,
                                     "entrypoint.sh.tpl")
        output_sh_file = os.path.join(self.dest_dir, self.docker_dir,
                                      "entrypoint.sh")
        write_lines = []

        with open(input_sh_file, "r") as input_file:
            read_lines = input_file.readlines()
            for line in read_lines:
                s3_bukcet_base_path = os.path.join(
                    BucketStorage.get_input_attr('bucket'),
                    Settings.RESOURCE_NAME_PREFIX)
                write_lines.append(
                    line.replace('{{s3-bucket-base-path}}',
                                 s3_bukcet_base_path))

        with open(output_sh_file, "w") as output_file:
            output_file.writelines(write_lines)
    def post_terraform_apply(self):
        archive_type = "zip"
        s3_client = s3.get_s3_client(Settings.AWS_AUTH_CRED)

        zip_file_name = Settings.RESOURCE_NAME_PREFIX + "-terraform-installer-backup"
        zip_file_abs_path = os.path.join(Settings.BASE_APP_DIR, zip_file_name)
        dir_to_archive = Settings.DATA_DIR
        SysLog().write_debug_log("Started Archiving Terraform Directory")
        shutil.make_archive(zip_file_abs_path, archive_type, dir_to_archive)
        SysLog().write_debug_log("Completed Archiving")

        bucket_name = BucketStorage.get_input_attr('bucket')
        zip_file_name = zip_file_name + ".zip"
        zip_file_abs_path = zip_file_abs_path + ".zip"
        SysLog().write_debug_log("Started Uploading Archived Terraform(Zip File: %s) into S3 Bucket(Name: %s)" % (zip_file_abs_path, bucket_name))
        s3_client.upload_file(
            zip_file_abs_path,
            bucket_name,
            zip_file_name)

        os.remove(zip_file_abs_path)