在打包器中使用配置程序安装nvm时安装失败

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

我在配置程序中按照以下步骤在新的azure vm上安装nvm,但我无法安装。源不加载sh脚本。

{
  "variables": {
    "client_id": "{{env `ARM_CLIENT_ID`}}",
    "client_secret": "{{env `ARM_CLIENT_SECRET`}}",
    "resource_group": "{{env `ARM_RESOURCE_GROUP`}}",
    "storage_account": "{{env `ARM_STORAGE_ACCOUNT`}}",
    "subscription_id": "{{env `ARM_SUBSCRIPTION_ID`}}",
    "ssh_user": "palm",
    "ssh_pass": null
  },
  "builders": [{
    "type": "azure-arm",

    "client_id": "{{user `client_id`}}",
    "client_secret": "{{user `client_secret`}}",
    "resource_group_name": "{{user `resource_group`}}",
    "storage_account": "{{user `storage_account`}}",
    "subscription_id": "{{user `subscription_id`}}",

    "capture_container_name": "images",
    "capture_name_prefix": "packer",

    "os_type": "Linux",
    "image_publisher": "Canonical",
    "image_offer": "UbuntuServer",
    "image_sku": "16.04-LTS",

    "azure_tags": {
        "ticket": "palm"
    },

    "location": "East US",
    "vm_size": "Standard_DS2_v2"
  }],
  "provisioners": [{
    "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} sudo -E sh '{{ .Path }}'",
    "inline": [
        "curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash",
        "source ~/.bashrc",
        "nvm install v8.9.4",
        "nvm alias default v8.9.4",

        "/usr/sbin/waagent -force -deprovision+user && export HISTSIZE=0 && sync"
    ],
    "inline_shebang": "/bin/sh -x",
    "type": "shell"
  }]

我运行构建脚本时收到以下错误。不知道为什么它说没有找到nvm命令。

./packer build -var-file=variable.json ubuntu-16.04-nodejs.json 
azure-arm output will be in this color.

==> azure-arm: Running builder ...
    azure-arm: Creating Azure Resource Manager (ARM) client ...
==> azure-arm: Creating resource group ...
==> azure-arm:  -> ResourceGroupName : 'packer-Resource-Group-j5kfs33y6n'
==> azure-arm:  -> Location          : 'East US'
==> azure-arm:  -> Tags              :
==> azure-arm:  ->> ticket : palm-972
==> azure-arm: Validating deployment template ...
==> azure-arm:  -> ResourceGroupName : 'packer-Resource-Group-j5kfs33y6n'
==> azure-arm:  -> DeploymentName    : 'pkrdpj5kfs33y6n'
==> azure-arm: Deploying deployment template ...
==> azure-arm:  -> ResourceGroupName : 'packer-Resource-Group-j5kfs33y6n'
==> azure-arm:  -> DeploymentName    : 'pkrdpj5kfs33y6n'
==> azure-arm: Getting the VM's IP address ...
==> azure-arm:  -> ResourceGroupName   : 'packer-Resource-Group-j5kfs33y6n'
==> azure-arm:  -> PublicIPAddressName : 'packerPublicIP'
==> azure-arm:  -> NicName             : 'packerNic'
==> azure-arm:  -> Network Connection  : 'PublicEndpoint'
==> azure-arm:  -> IP Address          : '40.71.227.46'
==> azure-arm: Waiting for SSH to become available...
==> azure-arm: Connected to SSH!
==> azure-arm: Provisioning with shell script: /tmp/packer-shell063897685
    azure-arm:   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
    azure-arm:                                  Dload  Upload   Total   Spent    Left  Speed
    azure-arm: 100 12540  100 12540    0     0  40290      0 --:--:-- --:--:-- --:--:-- 40321
    azure-arm: => Downloading nvm from git to '/home/packer/.nvm'
    azure-arm: Cloning into '/home/packer/.nvm'...
    azure-arm: Note: checking out '7ad6d98cedde01809e32d56ab8ced064f6f28175'.
    azure-arm:
    azure-arm: You are in 'detached HEAD' state. You can look around, make experimental
    azure-arm: changes and commit them, and you can discard any commits you make in this
    azure-arm: state without impacting any branches by performing another checkout.
    azure-arm:
    azure-arm: If you want to create a new branch to retain commits you create, you may
    azure-arm: do so (now or later) by using -b with the checkout command again. Example:
    azure-arm:
    azure-arm:   git checkout -b <new-branch-name>
    azure-arm:
    azure-arm: => => Compressing and cleaning up git repository
    azure-arm:
    azure-arm: => Appending nvm source string to /home/packer/.bashrc
    azure-arm: => Appending bash_completion source string to /home/packer/.bashrc
    azure-arm: => Close and reopen your terminal to start using nvm or run the following to use it now:
    azure-arm: /tmp/script_8684.sh: 3: /tmp/script_8684.sh: source: not found
    azure-arm:
    azure-arm: /tmp/script_8684.sh: 4: /tmp/script_8684.sh: nvm: not found
    azure-arm: export NVM_DIR="$HOME/.nvm"
    azure-arm: [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
    azure-arm: /tmp/script_8684.sh: 5: /tmp/script_8684.sh: nvm: not found
    azure-arm: [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
    azure-arm: WARNING! The waagent service will be stopped.
    azure-arm: WARNING! Cached DHCP leases will be deleted.
    azure-arm: WARNING! root password will be disabled. You will not be able to login as root.
    azure-arm: WARNING! /etc/resolvconf/resolv.conf.d/tail and /etc/resolvconf/resolv.conf.d/original will be deleted.
    azure-arm: WARNING! packer account and entire home directory will be deleted.
==> azure-arm: Querying the machine's properties ...
==> azure-arm:  -> ResourceGroupName : 'packer-Resource-Group-j5kfs33y6n'
==> azure-arm:  -> ComputeName       : 'pkrvmj5kfs33y6n'
==> azure-arm:  -> OS Disk           : 'https://ubuntujava8.blob.core.windows.net/images/pkrosj5kfs33y6n.vhd'
==> azure-arm: Powering off machine ...
==> azure-arm:  -> ResourceGroupName : 'packer-Resource-Group-j5kfs33y6n'
==> azure-arm:  -> ComputeName       : 'pkrvmj5kfs33y6n'

如何使用packer动态运行nvm?有没有其他方法使用配置程序安装nvm?

node.js nvm packer
1个回答
0
投票

您错过了第一个错误

tmp/script_8684.sh: 3: /tmp/script_8684.sh: source: not found

source不是有效的sh内置,你应该使用.代替。即

. ~/.bashrc
© www.soinside.com 2019 - 2024. All rights reserved.