Closed outzhu closed 1 year ago
I can't figured out Packer env variables. So I did this to fix GOPATH. Building to see if it works.
provisioner "shell" {
inline = ["echo GOPATH=$HOME/go > ~/.bashrc","echo PATH=$PATH:$GOPATH/bin > ~/.bashrc","source ~/.bashrc"]
}
That's a good approach! Then it'll be persistent for both Docker and Vagrant.
It didn't work. There's no ~/.bashrc. I guess Packer doesn't create files?
It didn't work. There's no ~/.bashrc. I guess Packer doesn't create files?
No, it doesn't. I'm guessing this is because we're on Alpine, which doesn't use bash as the default shell.
This might give you some clues: https://stackoverflow.com/q/39621880/8507637
But it worked in the vagrant box?
and I had to use source ~/.profile
to make it work in the box as well.
The Vagrant image isn't official (from Alpine)... It comes from a third pary (See: https://github.com/lavabit/robox/tree/master/scripts/alpine314). The docker image is an official image created by the Alpine developers.
Check this out:
docker run -it alpine:latest /bin/sh
cat /etc/profile.d/README
This directory should contain shell scripts configuring system-wide
environment on users' shells.
Files with the .sh extension found in this directory are evaluated by
Bourne-compatible shells (like ash, bash or zsh) when started as a
login shell.
Maybe you can create a new file here, e.g., /etc/profile.d/go.sh
I put this in the dependencies.sh
and it doesn't show up in the Vagrant box, didn't work.
Keeping at it.
export GOPATH=$HOME/go >/etc/profile.d/go.sh
export PATH=$PATH:$GOPATH/bin > /etc/profile.d/go.sh
Docker doesn't seem to like $HOME for it's env GOPATH. I have to figure out how to fix that.
from git action log
pentesting-docker.docker.alpine: go: GOPATH entry is relative; must be absolute path: "$HOME/go".
Have we tried this? https://stackoverflow.com/a/59485924/8507637
this wouldn't work. Packer doesn't save variables, it would still be the same issue when in the box/container. Alpine isn't the issue.
I made a solution to call go packages. I will still look for alternatives but until then the solution is uploading a go.sh in /etc/profile.d/.
go seems to have issues with
go install
due to its undefined GOPATH not being included in $PATH, once fixed I will close https://github.com/infinite-omicron/pentesting-vm/issues/20.go is in the /usr/bin/
go env
outputsIt has GOPATH="/home/vagrant/go" but I can't
echo $GOPATH
.I can call with
go env GOPATH
but I don't know how to export GOBIN with $GOPATH/bin