act icon indicating copy to clipboard operation
act copied to clipboard

[Feature Request]: Bootstrap launcher of Windows container using Windows Sandbox

Open Dragon1573 opened this issue 7 months ago • 5 comments

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

Dragon1573 avatar Jun 01 '25 03:06 Dragon1573

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.

Image

Dragon1573 avatar Jun 01 '25 04:06 Dragon1573

It requires Windows Pro or Enterprise

panekj avatar Jun 05 '25 10:06 panekj

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?

Dragon1573 avatar Jun 05 '25 10:06 Dragon1573

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.

ChristopherHX avatar Jun 05 '25 21:06 ChristopherHX

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:

  1. Check the latest winget.exe version in GitHub Releases.
  2. Check if caches (installer of winget.exe, including required dependencies) are latest.
  3. Download the installer (and also its required dependencies) if outdated.
  4. Prepare *.wsb Sandbox configuration file and *.ps1 initialize script (contents are pre-defined in SandboxTest.ps1).
  5. Launch a brand new customized Sandbox instance using *.wsb file.
  6. Silently install the winget.exe using the *.ps1 script.
  7. Run "post initialize scripts" I provide with -Script parameter.
    1. Install the latest Nodejs LTS, for running GitHub Actions.
    2. Install the latest Git, for cloning Actions repository.
    3. Install the latest Act.
    4. Refresh environment variables, so node.exe git.exe and act.exe are available in $env:PATH.
    5. Configure Git CLI to use a specific proxy, for speeding up git clone process.
    6. Keep PowerShell session open, wait for further interactions.
  8. In the session, invoke act.exe manually as on a Windows host instance with `-P windows-latest=-self-hosted".

I can't sure if maintainers can provide such a "wrapper script". ❤

Dragon1573 avatar Jun 06 '25 10:06 Dragon1573