def ConfigureArchInstall(args, mount_path, parent_path, disk_uuid, aur_packages):
  relative_builder_path = utils.CopyBuilder(mount_path)
  packages_dir = utils.CreateTempDirectory(mount_path)
  utils.Run(['git', 'clone', COMPUTE_IMAGE_PACKAGES_GIT_URL, packages_dir])
  utils.CreateDirectory(os.path.join(mount_path, ''))
  aur_packages_dir = os.path.join(packages_dir, 'aur')
  for aur_package in aur_packages:
    utils.CopyFiles(aur_package, aur_packages_dir + '/')
  packages_dir = os.path.relpath(packages_dir, mount_path)
  params = {
    'packages_dir': '/%s' % packages_dir,
    'device': parent_path,
    'disk_uuid': disk_uuid,
    'accounts': args.accounts,
    'debugmode': args.debug,
    'quiet': args.quiet,
    'verbose': args.verbose,
    'packages': args.packages,
    'size_gb': args.size_gb
  }
  config_arch_py = os.path.join(
      '/', relative_builder_path, 'arch-image.py')
  utils.RunChroot(mount_path,
                  '%s "%s"' % (config_arch_py, utils.EncodeArgs(params)),
                  use_custom_path=False)
  utils.DeleteDirectory(os.path.join(mount_path, relative_builder_path))
def CreateArchImage(args, aur_packages):
  logging.info('Creating Arch Image')
  logging.info('========================')
  image_path = os.path.join(os.getcwd(), IMAGE_FILE)
  CreateBlankImage(image_path, size_gb=int(args.size_gb), fs_type=args.fs_type)
  mount_path = utils.CreateTempDirectory(base_dir='/')
  image_mapping = utils.ImageMapper(image_path, mount_path)
  try:
    image_mapping.InstallLoopback()
    image_mapping.Map()
    primary_mapping = image_mapping.GetFirstMapping()
    image_mapping_path = primary_mapping['path']
    FormatImage(image_mapping_path)
    try:
      image_mapping.Mount()
      utils.CreateDirectory('/run/shm')
      utils.CreateDirectory(os.path.join(mount_path, 'run', 'shm'))
      InstallArchLinux(mount_path)
      disk_uuid = SetupFileSystem(mount_path, image_mapping_path, args.fs_type)
      ConfigureArchInstall(
          args, mount_path, primary_mapping['parent'], disk_uuid, aur_packages)
      utils.DeleteDirectory(os.path.join(mount_path, 'run', 'shm'))
      PurgeDisk(mount_path)
    finally:
      image_mapping.Unmount()
    ShrinkDisk(image_mapping_path)
  finally:
    image_mapping.Unmap()
  utils.Run(['parted', image_path, 'set', '1', 'boot', 'on'])
  utils.Sync()
  logging.info('========================')
  return image_path
def main():
    args = ParseArgs()
    utils.SetupLogging(quiet=args.quiet, verbose=args.verbose)
    logging.info('Arch Linux Image Builder')
    logging.info('========================')

    nobody_tmp_dir = utils.CreateTempDirectory()
    utils.ChangeDirectoryOwner('nobody', nobody_tmp_dir)

    aur_packages = InstallPackagesOnHostMachine()
    aur_packages.append(
        utils.AurBuild('google-cloud-sdk',
                       {'CLOUDSDK_CONFIG': nobody_tmp_dir})[0])
    aur_packages.append(utils.AurBuild('gce-compute-image-packages')[0])
    aur_packages.append(utils.AurBuild('google-compute-engine-oslogin-git')[0])
    aur_packages.append(utils.AurBuild('python2-google-compute-engine-git')[0])
    image_path = CreateArchImage(args, aur_packages)
    image_name, image_filename, image_description = GetImageNameAndDescription(
        args.outfile)
    image_file = SaveImage(image_path, image_filename)
    if args.upload and image_file:
        UploadImage(image_file, args.upload, make_public=args.public)
        if args.register:
            AddImageToComputeEngineProject(image_name, args.upload,
                                           image_description)
Ejemplo n.º 4
0
def main():
    args = utils.DecodeArgs(sys.argv[1])
    utils.SetupLogging(quiet=args['quiet'], verbose=args['verbose'])
    logging.info('Setup Bootstrapper Environment')
    utils.SetupArchLocale()
    InstallPackagesForStagingEnvironment()
    image_path = os.path.join(os.getcwd(), IMAGE_FILE)
    CreateImage(image_path, size_gb=int(args['size_gb']))
    mount_path = utils.CreateTempDirectory(base_dir='/')
    image_mapping = utils.ImageMapper(image_path, mount_path)
    try:
        image_mapping.Map()
        primary_mapping = image_mapping.GetFirstMapping()
        image_mapping_path = primary_mapping['path']
        FormatImage(image_mapping_path)
        try:
            image_mapping.Mount()
            utils.CreateDirectory('/run/shm')
            utils.CreateDirectory(os.path.join(mount_path, 'run', 'shm'))
            InstallArchLinux(mount_path)
            disk_uuid = SetupFileSystem(mount_path, image_mapping_path)
            ConfigureArchInstall(args, mount_path, primary_mapping['parent'],
                                 disk_uuid)
            utils.DeleteDirectory(os.path.join(mount_path, 'run', 'shm'))
            PurgeDisk(mount_path)
        finally:
            image_mapping.Unmount()
        ShrinkDisk(image_mapping_path)
    finally:
        image_mapping.Unmap()
    utils.Run(['parted', image_path, 'set', '1', 'boot', 'on'])
    utils.Sync()
Ejemplo n.º 5
0
def ConfigureArchInstall(args, mount_path, parent_path, disk_uuid):
    relative_builder_path = utils.CopyBuilder(mount_path)
    utils.LogStep('Download compute-image-packages')
    packages_dir = utils.CreateTempDirectory(mount_path)
    utils.Run(['git', 'clone', COMPUTE_IMAGE_PACKAGES_GIT_URL, packages_dir])
    utils.CreateDirectory(os.path.join(mount_path, ''))
    packages_dir = os.path.relpath(packages_dir, mount_path)
    params = {
        'packages_dir': '/%s' % packages_dir,
        'device': parent_path,
        'disk_uuid': disk_uuid,
        'accounts': args['accounts'],
        'debugmode': args['debugmode'],
    }
    params.update(args)
    config_arch_py = os.path.join('/', relative_builder_path, 'arch-image.py')
    utils.RunChroot(mount_path,
                    '%s "%s"' % (config_arch_py, utils.EncodeArgs(params)),
                    use_custom_path=False)
    utils.DeleteDirectory(os.path.join(mount_path, relative_builder_path))
def main():
    args = ParseArgs()
    utils.SetupLogging(quiet=args.quiet, verbose=args.verbose)
    workspace_dir = None
    image_file = None
    try:
        workspace_dir = utils.CreateTempDirectory()
        bootstrap_file = DownloadArchBootstrap(args.bootstrap)
        utils.Untar(bootstrap_file, workspace_dir)
        arch_root = PrepareBootstrap(workspace_dir, args.mirror,
                                     not args.nopacmankeys)
        relative_builder_path = utils.CopyBuilder(arch_root)
        ChrootIntoArchAndBuild(arch_root, relative_builder_path, args)
        image_name, image_filename, image_description = GetImageNameAndDescription(
            args.outfile)
        image_file = SaveImage(arch_root, image_filename)
        if args.upload and image_file:
            UploadImage(image_file, args.upload, make_public=args.public)
            if args.register:
                AddImageToComputeEngineProject(image_name, args.upload,
                                               image_description)
    finally:
        if not args.nocleanup and workspace_dir:
            utils.DeleteDirectory(workspace_dir)