[Feature Request]: Bootstrap launcher of Windows container using Windows Sandbox
Act version
act version 0.2.77
Feature description
Background
- Related #2726
Currently, act on Windows instance can be supported with adding switch -P windows-latest=-self-hosted. But this requires users to use their host OS instance for running GitHub Workflows, which might mess up their pre-configured development environments (such as actions/setup-python will overwrite users pre-installed Python instance and will not revert after workflows finished). In order to protect their own host instance, users have to prepare a Windows VM instance in advanced, install act in it and then launch workflow tests.
I'm one of the contributors in microsoft/winget-pkgs. In that repository, moderators provides a special PowerShell script Tools/SandboxTest.ps1, help contributors easily validate manifests in their Windows Sandbox instance.
Suggested implementation
I would recommend also provide a PowerShell bootstrap script (or anything else to realize this) with act.exe distributions.
microsoft/winget-pkgs is licensed under MIT, so I think we can start from there. Slightly modify the PowerShell scripts to silently install nektos.act package in Windows Sandbox instance and then launch act.exe -P windows-latest=-self-hosted automatically with users additional parameters attached to it. I think I can use it with
# actForWindows.ps1 -ActOptions "<pass any required parameters here required by act>"
actForWindows.ps1 -ActOptions "-q -j FooJob -r -v -w"
# Script will first run everything the same as SandboxTest.ps1 should be,
# Check available WinGet versions, launch a brand new Sandbox instance,
# install WinGet in it.
#
# Then it will automatically use WinGet to install act.exe, then refresh
# the environment variables (such as $env:PATH) to make act.exe usable.
#
# At last, following will be invoked as the GitHub Workflow truly launched:
# act.exe -P windows-latest=-self-hosted -q -j FooJob -r -v -w
Now I'm currently using a bootstrap like following:
SandboxTest.ps1 -Verbose -Script {
winget install --accept-source-agreements -s winget -e OpenJS.NodeJS.LTS
winget install --accept-source-agreements -s winget -e Git.Git
winget install --accept-source-agreements -s winget -e nektos.act
Update-EnvironmentVariables
git config --global http.proxy "http://localhost:7890"
git config --global https.proxy "http://localhost:7890"
}
Then I can run act -P windows-latest=-self-hosted in Sandbox's Windows PowerShell console.
It requires Windows Pro or Enterprise
It requires Windows Pro or Enterprise
Em ... Or is there any other virtual container environment for running windows-* images? Is that the only choice users prepare Windows containers in advanced on their own?
I've noticed that somebody instruct dockurr/windows. Can it work similar to provided Linux containers? Should I switch my Docker Desktop for Windows into Windows Container Mode?
Windows Container Mode
I guess this needs Windows Pro or Enterprise as well (which I own).
Regardless windows container are not implemented in act and cause cryptic errors, since I implemented this in 2021 exclusively for a similar cli tool for "Running Actions Locally" I did not spent any time about reimplementing this feature for act
Never tried dockur/windows, but doesn't this also break act assuming that the container env is linux?. . . this is hardcoded for the docker backend.
Further question
How are you supposed to customize the tools in the windows sandbox?
My current assumption is you can not do that at all, after sandbox restart all installed software is gone and the installed software does not match your local installation. e.g. redownload and reinstall from a fresh setup on every sandbox start.
Act must run inside the windows sandbox with your approach, the cli does not seem to allow other scenarious in a straight forward way compared to windows containers.
How are you supposed to customize the tools in the windows sandbox?
I would like to just keep act.exe as is, and provide a kind of "wrapper" to install required act.exe inside Windows Sandbox.
In previous comments, I use a modified-by-my-own bootstrap script based on SandboxTest.ps1. It simply do following steps:
- Check the latest
winget.exeversion in GitHub Releases. - Check if caches (installer of
winget.exe, including required dependencies) are latest. - Download the installer (and also its required dependencies) if outdated.
- Prepare
*.wsbSandbox configuration file and*.ps1initialize script (contents are pre-defined inSandboxTest.ps1). - Launch a brand new customized Sandbox instance using
*.wsbfile. - Silently install the
winget.exeusing the*.ps1script. - Run "post initialize scripts" I provide with
-Scriptparameter.- Install the latest Nodejs LTS, for running GitHub Actions.
- Install the latest Git, for cloning Actions repository.
- Install the latest Act.
- Refresh environment variables, so
node.exegit.exeandact.exeare available in$env:PATH. - Configure Git CLI to use a specific proxy, for speeding up
git cloneprocess. - Keep PowerShell session open, wait for further interactions.
- In the session, invoke
act.exemanually as on a Windows host instance with `-P windows-latest=-self-hosted".
I can't sure if maintainers can provide such a "wrapper script". ❤