canonical / packer-maas

Packer templates to create MAAS deployable images
Other
279 stars 169 forks source link

Building custom RHEL Based images will fail if make is not used #197

Closed GR360RY closed 7 months ago

GR360RY commented 8 months ago

Issue Description

As stated in the centos7/README.md file, the image can be build just with packer and without using make:

Alternatively you can manually run packer. Your current working directory must be in packer-maas/centos7, where this file is located. Once in packer-maas/centos7 you can generate an image with:

packer init
PACKER_LOG=1 packer build .

This will result in a failed build as anaconda cannot fetch the kickstart file:

[    8.612448] dracut-initqueue[710]: % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
[    8.616439] dracut-initqueue[710]: Dload  Upload   Total   Spent    Left  Speed
[    8.620850] dracut-initqueue[710]: 0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
[    8.626626] dracut-initqueue[710]: curl: (22) The requested URL returned error: 404 Not Found
[    8.630240] dracut-initqueue[710]: Warning: anaconda: failed to fetch kickstart from http://10.0.2.2:8536/centos7.ks

When starting a build process with make, the http/centos7.ks is generated by make, hence the build finishes successfully. Below is the code snippet from the Makefile:

http/centos7.ks: http/centos7.ks.in
    envsubst '$${KS_PROXY} $${KS_OS_REPOS} $${KS_UPDATES_REPOS} $${KS_EXTRA_REPOS}' < $< | tee $@

This happens with the rest of the RHEL based distros as far as I checked.

Proposal

Instead of using make to substitute strings in a http/centos7.ks.in and generate a new http/centos7.ks, use templatefile hcl function together with http_content

See more details in this blog post: Using Template Files with HashiCorp Packer

Pros

Please see example changes for centos7 in the fork: https://github.com/canonical/packer-maas/compare/main...GR360RY:packer-maas:packer_refactor_ks_generation?expand=1

I will be happy to provide a PR for all distributions if this is something you are willing to consider.

alexsander-souza commented 8 months ago

Hi, I think this solution is much cleaner than the existing one. We would certainly consider this move if you are willing to provide PRs.

If you do, please create a PR for each distro, let's avoid one massive PR as this is hard to review.

GR360RY commented 8 months ago

@alexsander-souza and @jurekh , the PR for CentOS 7 is ready. Please review and consider. I will continue with the reset of the distributions when this one is reviewed/commented on and merged.