如何使用 Packer 在 Azure 中构建带有大文件的图像?

问题描述 投票:0回答:1

我想在 Windows 2019 上的 Azure 中使用大文件构建映像。该文件包含创建图像所需的工件。在我尝试将一个 200MB 的文件复制到主机之前,虚拟机运行一切顺利。预计需要 11 个小时。那时我发现了 WinRM 及其文件复制限制。

然后我发现了 http_directory 参数可以通过 http 将文件复制到主机,但是 azure-arm builder 不可用。

然后我看到我可以使用 SSH。问题是我无法从 ssh provisioner 开始并切换到 WinRM provisioner 来运行我的 ps1 配置脚本。我读到我可以从 ssh 开始,拍摄图像,然后使用 WinRM 启动它。不理想。

我遇到了这个软件:“https://github.com/winfsp/sshfs-win” - 但我不知道配置主机直接访问其配置的加壳主机的方法。

我遇到了 winrmcp,但它看起来很旧,如果我能弄清楚如何让它继续下去,它就不太可能工作。

我倾向于 blob 存储,但这似乎是一种逃避。

启动 Windows 2019 Server、将 200MB 文件复制到其中并运行 ps1 脚本的最佳方法是什么?

windows azure packer file-copying winrm
1个回答
0
投票

您可以尝试使用 Ansible provisioner 复制您的文件。它要快得多。当我复制一个 10MB 的文件时,文件供应器花费了大约 4 分钟,但 Ansible 供应器只用了 15 秒。

打包文件:

source "azure-arm" "example" {
  use_azure_cli_auth                = true
  os_type                           = "Windows"
  communicator                      = "winrm"
  image_offer                       = "WindowsServer"
  image_publisher                   = "MicrosoftWindowsServer"
  image_sku                         = "2016-Datacenter"
  managed_image_name                = "image"
  managed_image_resource_group_name = "rg"
  location                          = "westeurope"
  vm_size                           = "Standard_D2_v2"

  winrm_insecure = true
  winrm_timeout  = "5m"
  winrm_use_ssl  = true
  winrm_username = "packer"
}

build {
  sources = ["sources.azure-arm.example"]

  provisioner "ansible" {
    playbook_file = "./copy.yml"
    extra_arguments = [
      "-e", "ansible_winrm_server_cert_validation=ignore",
      "-e", "ansible_winrm_transport=ntlm"
    ]
    user      = "packer"
    use_proxy = false
  }
}

Ansible 剧本 - copy.yml:

---
- name: Copy file to Windows host
  hosts: all

  tasks:
    - name: Copy file
      win_copy:
        src: ./10MB.bin
        dest: C:\10MB.bin
© www.soinside.com 2019 - 2024. All rights reserved.