Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Homebrew error when running the post-generation scripts in Ubuntu 20.04 #3478

Closed
olandese opened this issue May 28, 2021 · 9 comments
Closed
Assignees
Labels
Area: Image administration Area: Scripting and command line investigate Collect additional information, like space on disk, other tool incompatibilities etc. OS: Ubuntu

Comments

@olandese
Copy link
Contributor

olandese commented May 28, 2021

Hi,

I created my own Ubuntu 20.04 image using the original Packer file and scripts from this repo and it work great!

But running the post-generation script as documented in the create-image-and-azure-resources.md is giving an error:

/opt/post-generation/homebrew-permissions.sh: line 7: brew: command not found
/opt/post-generation/homebrew-permissions.sh: line 7: cd: HOME not set
fatal: not a git repository (or any of the parent directories): .git

Step to reproduce:

Option 1 - Manually execute the command:

Create a VM with the ubuntu image, login:

and then execute:

sudo -i
find /opt/post-generation -mindepth 1 -maxdepth 1 -type f -name '*.sh' -exec bash {} \;

Option 2 with custom script extension:

  • Create a VM with the ubuntu image
  • create a file like config.json with this content:
    { "commandToExecute": "find /opt/post-generation -mindepth 1 -maxdepth 1 -type f -name '*.sh' -exec bash {} \\;" }
  • run (change the values in the <<>> with your VM name and Resource Group):

az vm extension set --vm-name <<your-vm-name>> --name customScript --resource-group <<your-resource-group>> --version 2.0 --publisher Microsoft.Azure.Extensions --settings ./config.json

  • Then look in the /var/lib/waagent/custom-script/download/{{some-number}} and open the contents of the stderr file

Solution (maybe?)

it seems the brew command should first be loaded in the homebrew-permissions.sh file like:

eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)

@LeonidLapshin LeonidLapshin added Area: Image administration investigate Collect additional information, like space on disk, other tool incompatibilities etc. OS: Ubuntu labels May 31, 2021
@LeonidLapshin
Copy link
Contributor

Hey, @olandese !
Thank you for reporting about the problem, we will check this issue and return with new information soon :)

@Darleev
Copy link
Contributor

Darleev commented Jun 1, 2021

Hello @olandese,
Could you please ensure that homebrew.sh script is included in your packer template? All required steps to add homebrew to the PATH and other required steps are in place in the script and should be applied during the build.
I tried to build an image and deploy it after, but everything works fine.
We are looking forward to your reply.

@olandese
Copy link
Contributor Author

olandese commented Jun 1, 2021

Hi @Darleev ,Yes, I am using all the scripts of the packer template in the git repo, homebrew.sh is there, did you applied the steps as I described after the VM creation?

@Darleev
Copy link
Contributor

Darleev commented Jun 3, 2021

@olandese Could you please provide us PATH variable from the machine where the problem appears? I tried to build machines on my own, and execute post-generation scripts, but everything works fine.
Let's try to figure out a reason of such behavior on your side.

@olandese
Copy link
Contributor Author

olandese commented Jun 3, 2021

@Darleev I recreate the VM, this is the output of running $PATH for the admin (olandese) user configured for this VM when created:

olandese@vmssaab00000000:~$ echo $PATH
/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:$HOME/.local/bin:/opt/pipx_bin:/usr/share/rust/.cargo/bin:$HOME/.config/composer/vendor/bin:/usr/local/.gh
cup/bin:$HOME/.dotnet/tools:/snap/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/olandese/.dotnet/tools

But if I run the script with this admin user like:

find /opt/post-generation -mindepth 1 -maxdepth 1 -type f -name '*.sh' -exec bash {} \;

I get this:

olandese@vmssaab00000000:~$ find /opt/post-generation -mindepth 1 -maxdepth 1 -type f -name '*.sh' -exec bash {} ;
sed: couldn't open temporary file /etc/sedro9rkv: Permission denied
/usr/bin/journalctl
Failed to connect to /run/systemd/journal/io.systemd.journal: Permission denied
Vacuuming done, freed 0B of archived journals from /run/log/journal.
Vacuuming done, freed 0B of archived journals from /var/log/journal.
Vacuuming done, freed 0B of archived journals from /var/log/journal/73e7eca230f3467d813facba63c98903.
find: ‘/var/log/private’: Permission denied
find: ‘/var/log/private’: Permission denied
find: ‘/var/log/private’: Permission denied
cp: cannot create regular file '/var/log/journal/73e7eca230f3467d813facba63c98903/user-1000.journal': Permission denied
cp: cannot create regular file '/var/log/journal/73e7eca230f3467d813facba63c98903/system.journal': Permission denied
cp: cannot create regular file '/var/log/wtmp': Permission denied
cp: cannot create regular file '/var/log/mysql/error.log': Permission denied
cp: cannot create regular file '/var/log/dmesg': Permission denied
cp: cannot create regular file '/var/log/unattended-upgrades/unattended-upgrades-shutdown.log': Permission denied
cp: cannot create regular file '/var/log/landscape/sysinfo.log': Permission denied
cp: cannot create regular file '/var/log/apt/term.log': Permission denied
cp: cannot create regular file '/var/log/apt/eipp.log.xz': Permission denied
cp: cannot create regular file '/var/log/apt/history.log': Permission denied
cp: cannot create regular file '/var/log/btmp': Permission denied
cp: cannot create regular file '/var/log/lastlog': Permission denied
cp: cannot create regular file '/var/log/waagent.log': Permission denied
cp: cannot create regular file '/var/log/alternatives.log': Permission denied
cp: cannot create regular file '/var/log/cloud-init.log': Permission denied
cp: cannot create regular file '/var/log/syslog': Permission denied
cp: cannot create regular file '/var/log/dpkg.log': Permission denied
cp: cannot create regular file '/var/log/fontconfig.log': Permission denied
cp: cannot create regular file '/var/log/apache2/access.log': Permission denied
cp: cannot create regular file '/var/log/apache2/other_vhosts_access.log': Permission denied
cp: cannot create regular file '/var/log/apache2/error.log': Permission denied
cp: cannot create regular file '/var/log/auth.log': Permission denied
cp: cannot create regular file '/var/log/kern.log': Permission denied
cp: cannot create regular file '/var/log/nginx/access.log': Permission denied
cp: cannot create regular file '/var/log/nginx/error.log': Permission denied
cp: cannot create regular file '/var/log/cloud-init-output.log': Permission denied
cp: cannot create regular file '/var/log/postgresql/postgresql-13-main.log': Permission denied
cp: cannot create regular file '/var/log/php7.4-fpm.log': Permission denied
cp: cannot create regular file '/var/log/php8.0-fpm.log': Permission denied
HEAD is now at 227445ece Merge pull request #11288 from Homebrew/update-manpage

If I then run sudo -i and then echo $PATH:

root@vmssaab00000000:~# echo $PATH
/usr/share/rust/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/root/.dotnet/tools:/opt/pipx_bin:/opt/pipx_bin

Then running again:
find /opt/post-generation -mindepth 1 -maxdepth 1 -type f -name '*.sh' -exec bash {} \;

I get:

root@vmssaab00000000:~# find /opt/post-generation -mindepth 1 -maxdepth 1 -type f -name '*.sh' -exec bash {} ;
/usr/bin/journalctl
Vacuuming done, freed 0B of archived journals from /var/log/journal.
Deleted archived journal /var/log/journal/73e7eca230f3467d813facba63c98903/system@00000000000000000000000000000000-00000000000029db-0005c3e1faa1a798.journal (8.0M).
Deleted archived journal /var/log/journal/73e7eca230f3467d813facba63c98903/user-1000@00000000000000000000000000000000-00000000000029df-0005c3e1ffe3987d.journal (8.0M).
Vacuuming done, freed 16.0M of archived journals from /var/log/journal/73e7eca230f3467d813facba63c98903.
Vacuuming done, freed 0B of archived journals from /run/log/journal.
/opt/post-generation/homebrew-permissions.sh: line 7: brew: command not found
fatal: not a git repository (or any of the parent directories): .git

My FIX

I fixed running the command:

sudo su -c "find /opt/post-generation -mindepth 1 -maxdepth 1 -type f -name '*.sh' -exec bash {} \;"

But I really would like to know how is possible you are not getting the same issues as me

@Darleev
Copy link
Contributor

Darleev commented Jun 7, 2021

@olandese yes, finally, I was able to reproduce the issue on our side, and it is required to adjust the documentation according to the fix provided by you. I think also need to mention that users should have sudo privileges to perform post-generation scripts.
I've created a pull request, feel free to review it and add important points which I possibly miss.
Initially, I tried to reproduce the issue using a script, where sudo permissions are included as a part of script execution.
Thank you for contributing to the repository.

@olandese
Copy link
Contributor Author

olandese commented Jun 8, 2021

Thank you very much @Darleev !
It would be nice if the full post provisioning process could be shared in this repo too. (At least how the ADO a/o Runner agents are added automatically to the created VMs)

@Darleev
Copy link
Contributor

Darleev commented Jun 8, 2021

@olandese we've merged the PR and now the information is available in our documentation.
Unfortunately, we are not able to provide a full provisioning workflow due to complexity and some internal configuration aspects, however in case of any question feel free to contact us, we'll do our best to answer your questions.
Regrading automatic agents configuration: I guess, it is possible to add some bash/cmd/powershell script(post-generation) and write installation logic there.

@Darleev
Copy link
Contributor

Darleev commented Jun 10, 2021

@olandese I'm going to close the issue.
In case of any questions, do not hesitate to contact us.

@Darleev Darleev closed this as completed Jun 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Image administration Area: Scripting and command line investigate Collect additional information, like space on disk, other tool incompatibilities etc. OS: Ubuntu
Projects
None yet
Development

No branches or pull requests

4 participants
@olandese @LeonidLapshin @Darleev and others