packer icon indicating copy to clipboard operation
packer copied to clipboard

Add support for building vanilla boxes

Open gusztavvargadr opened this issue 3 years ago • 8 comments

Discussed in https://github.com/gusztavvargadr/packer/discussions/289

Originally posted by JoelMiller74 November 21, 2021 I need Vagrant box images for testing in our DevOps pipelines. I love how you have built these images and keep them up to date every month using automation. However, I run into issues with the fact that the base boxes with just Windows Server also includes chocolatey, OpenSSL, and Chef Client 17. I am testing with Chef Test-Kitchen and currently we require a lower version than newest (17). I wish we were on the newest version, but currently, we are stuck at version 14. When I use test-kitchen with the Windows Server images, I get issues because Chef Client 17 is already installed. I must uninstall it before running my recipes. I am just looking at finding a way to build using this repo without any additional software like chocolatey, OpenSSL, Chef-Client, etc... on the built box. Test-Kitchen will automatically install the chef client and any additional software I need. Is there a way to build Windows Server images without any of the Configuration Management tools installed? I am just looking for a vanilla installation.

gusztavvargadr avatar Nov 30 '21 17:11 gusztavvargadr

Just checking to see if you have any idea on timeline for this one yet. -Thanks!

JoelMiller74 avatar Jan 24 '22 03:01 JoelMiller74

@JoelMiller74 I can probably start with this sometime in Feburary. Thanks for the patience.

gusztavvargadr avatar Jan 29 '22 21:01 gusztavvargadr

Just additional info as I have a new use-case. We are working to migrate from using Chef to CINC (Cinc Is Not Chef). It is an opensource version of Chef. In this case, I spin up a vagrant machine with Test-Kitchen and the Windows client already has Chef 17 and it creates problems when trying to get the CINC client installed. -Thanks!

JoelMiller74 avatar Mar 24 '22 19:03 JoelMiller74

@JoelMiller74 thanks for the update and sorry for the delay around this. You can try as a workaround in the meantime having a custom provisioning step with Test Kitchen to uninstall Chef.

Sorry again, I will try to get this done as soon as possible.

gusztavvargadr avatar Mar 24 '22 22:03 gusztavvargadr

@JoelMiller74 I've worked around this by adding a lifecycle hook to uninstall Chef client on this box after it's created:

platforms:
- name: windows-2022
  driver:
    box: gusztavvargadr/windows-server-2022-standard
    customize:
      memory: 1536
  lifecycle:
    post_create:
    - remote: | # Until there is a vanilla box available: https://github.com/gusztavvargadr/packer/issues/296
        $app = Get-WmiObject -Class 'Win32_Product' -Filter "Name LIKE 'Chef Infra Client v%'"
        $app.Uninstall() | Out-Null
  transport:
    elevated: true

decoyjoe avatar Mar 24 '22 22:03 decoyjoe

Thanks to both of you. I am absolutely fine and you do not need to rush, especially with this workaround. I appreciate both of you for your help. I was completely unaware of the lifecycle hooks. I had never seen this option and it will help for many things. Thanks!

JoelMiller74 avatar Mar 25 '22 00:03 JoelMiller74

@JoelMiller74 you can also extend the default Kitchen behavior by extending the Vagrantfile it generates, and use the standard Vagrant provisioners:

  • https://kitchen.ci/docs/drivers/vagrant/#vagrantfiles
  • https://kitchen.ci/docs/drivers/vagrant/#provision

gusztavvargadr avatar Mar 25 '22 06:03 gusztavvargadr

I was wondering if this might still be implemented at some point. I am working around it using the options above but all of my cookbooks require this workaround. -Thanks!

JoelMiller74 avatar Sep 14 '22 21:09 JoelMiller74

@JoelMiller74 I'm super sorry for the delay, had to take a break from maintaining the project.

I am back now and besides setting up the regular release rythm, I will take a look at this with top priority.

Thank you again for the patience.

gusztavvargadr avatar Nov 02 '22 16:11 gusztavvargadr

@JoelMiller74 @decoyjoe FYI, I have now an initial version of two boxes added in https://github.com/gusztavvargadr/packer/pull/367:

  • https://app.vagrantup.com/gusztavvargadr/boxes/windows-server-2022-standard-nocm
  • https://app.vagrantup.com/gusztavvargadr/boxes/windows-10-22h2-enterprise-nocm

Can you please give it a try and let me know how it works for you? I can add this nocm setup for other boxes as well if needed.

gusztavvargadr avatar Nov 28 '22 07:11 gusztavvargadr

I verified that this works as intended. Did you change how the image is called (when building) to pass nocm? Thanks!

JoelMiller74 avatar Nov 28 '22 18:11 JoelMiller74

@JoelMiller74 thanks for the quick check, glad to hear it works. Thank you for the patience and sorry again for the delay.

For now I only added this to the above two boxes as an experiment, but if you need it for others, let me know, and I can easily add it to others or to all of them.

Just type dotnet cake --configuration nocm to filter for all the nocm builds, it will display all the variants. Under the hood it works by buildind things just as earlier, and as an additional final step removing Chef and the other components. Because of this chaining you will also need the --recursive true flag for building with a single command.

gusztavvargadr avatar Nov 28 '22 20:11 gusztavvargadr