[英]Store env variables in Vagrant from Packer
I'm trying to export PATH=$PATH:$GOPATH/bin
for go in the Vagrant box that my Packer built so when I vagrant ssh
into the box I can call whatever binary I have in there.
environment_vars = ["GOPATH=$HOME/go"]
讓go
安裝包,但它不會留在盒子里。 我已經在scripts/dependencies.sh
中嘗試export GOPATH=$HOME/go
和export PATH=$PATH:$GOPATH/bin
,但這沒有用。
有人知道如何將環境變量從 Packer 版本存儲到 Vagrant 盒子嗎?
build {
name = "test-vagrant"
description = "Testing VM"
sources = [
"source.vagrant.alpine"
]
provisioner "shell" {
environment_vars = ["GOPATH=$HOME/go"]
scripts = [
"scripts/dependencies.sh",
////
]
execute_command = "echo 'vagrant' | sudo -S -E sh -c '{{ .Vars }} {{ .Path }}'"
}
}
#!/bin/sh
set -eu
apk update && \
apk add \
////
go \
unzip
go install github.com/OJ/gobuster/v3@latest
好吧,我想不出通過 Packer 的 shell 導出變量,但我確實有一個解決方案。
https://www.packer.io/docs/provisioners/file
provisioner "file" {
source = "upload/go.sh"
destination = "/tmp/go.sh"
}
provisioner "shell" {
inline = [
"sudo mv /tmp/go.sh /etc/profile.d/"]
}
附帶說明,這最初不起作用(並且 Packer 沒有拋出任何信息/錯誤)這是因為.vagrant.d/boxes
中的“文件夾” packer_alpine
我刪除了它,它修復了上傳和其他一些問題有。
所以我找到了另一個解決辦法,哈哈。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.