Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Report the time of every provisioner step at the end of the build #10072
Comments
|
Hi there @maxim-lobanov thanks for reaching out. As you mention there is no clear way of achieving this without having to parse the logs. Even with the machine-readable logs format flag you will still need to write some script that could parse the times and do the time calculation. Packer builders, provisioners, and post-processors run as separate process so it would be up to each plugin to collect and report back their execution times to Packer to be made available as some summary. I think it is doable but not sure the level of effort it would take. I'm going to mark this issue as thinking to discuss with the other maintainers. In the meantime, an alternative approach could be to have your scripts output their execution times to some file on the instance being provisioned then use the artifice post-processor to download the said file as the final build artifact or use the file provisioner to download the file as the last step of the build. This process wouldn't account for the actual builder time but with the collective totals I think you would be able to deduce the time for instance provisioning/base setup. |
|
@nywilken , I have looked at packer source code and now I have more context about complexity that you mentioned. I am thinking about simpler solution to help us and other customers with problem which I have defined. What if we improve existing provisioners to print run duration to logs. Personally, we interested in the following provisioners: For example, {
"type": "shell",
"execute_command": "chmod +x {{ .Path }}; {{ .Vars }} {{ .Path }}",
"scripts": [
"./provision/configuration/configure-hostname.sh",
"./provision/configuration/finalize-vm.sh"
]
}will print something like that to logs:
This change should be pretty simple and will be helpful for us and other customers. Also it will be pretty useful for visibility side in general. |
|
This would be much more achievable -- the call that actually runs the individual provisioners is here: https://github.com/hashicorp/packer/blob/master/packer/provisioner.go#L138; Wrapping that line in a timer like we do for the whole build in command/build.go should be pretty doable. https://github.com/hashicorp/packer/blob/master/command/build.go#L291-L294 |
|
@SwampDragons , I thought about implementation of this logic for individual provisioners like
Will produce the duration of the whole block and we won't get duration of every script separately. I have done PR in my fork just to show what I am talking about: maxim-lobanov#1 |
|
@SwampDragons , @nywilken ^^ |
|
Hi @maxim-lobanov sorry for the delayed response. This week is HashiConf so we probably wont be able to take a look this week, but will do so first chance we get. Thanks for providing a link to your fork. Excited to see the route you took. |
|
The approach in your fork looks good to me; go ahead and make a PR and I can give it a full review when you're ready. |
|
@SwampDragons I have prepared PR #10125 . Please let me know if you know better wording for logging |
|
Hello! If someone is looking for solution for this issue, I have implemented small PowerShell script to parse Packer diagnostic log and get the list of all provisioners with their duration. You can find the script in https://gist.github.com/maxim-lobanov/1df36f67c821ddbbce6bcbfd06017686 |


Description
It would be great if packer can provide steps summary at the end of the image build that contains the duration of every step. Something like that:
Or even sorted by duration.
It would be very helpful for investigating and finding bottlenecks (installation scripts that take too much time).
Context
We build a bunch of images (Windows, Ubuntu, MacOS) in https://github.com/actions/virtual-environments repo via packer.
We have found that Windows image generation takes more than 10 hours for us so we are looking at some simple way to profile build and find steps that take too much time. it would help us to look deeper at those scripts and may be rework installation approach.
Alternatives
Unfortunately, I don't know the alternatives. You can check build log manually, find the lines where every script is started and check starting time but it is very painful when you have 150+ scripts. Please let me know if you know simpler alternative
P.S. Please let me know if there is an existing proposal to cover it
The text was updated successfully, but these errors were encountered: