Skip to content

feat: completing PowerShell script development can better support the Windows operating system. #479

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions codex-cli/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Dockerfile.windows
package-lock.json
24 changes: 24 additions & 0 deletions codex-cli/scripts/build_container.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env pwsh
# PowerShell 7.5
$ErrorActionPreference = 'Stop'
Set-StrictMode -Version Latest

# Get the script's directory and navigate to the parent directory.
$scriptDir = Split-Path $MyInvocation.MyCommand.Definition -Parent
Push-Location (Join-Path $scriptDir '..')
try {
& npm install
& npm run build
Remove-Item ./dist/openai-codex-*.tgz -Recurse -Force -ErrorAction Ignore
& npm pack --pack-destination ./dist
Move-Item ./dist/openai-codex-*.tgz ./dist/codex.tgz -Force

# Dockerfile Patch to Resolve Permission Issues on Windows
Copy-Item -Path ./Dockerfile -Destination ./Dockerfile.windows -Force
echo 'RUN git config --global --add safe.directory /app' >> ./Dockerfile.windows

& docker build -t codex -f './Dockerfile.windows' .
}
finally {
Pop-Location
}
51 changes: 51 additions & 0 deletions codex-cli/scripts/run_in_container.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env pwsh
# PowerShell 7.5
<#
Usage:
.\run_in_container.ps1 [-WorkDir <directory>] -- <PROMPT>
Example:
.\run_in_container.ps1 -WorkDir G:\Projects\demo1 -- "explain this codebase to me"
.\run_in_container.ps1
#>

param(
[string]$WorkDir = (Get-Location).ProviderPath,
[Parameter(ValueFromRemainingArguments)] [string[]]$Args
)

$WorkDir = (Get-Item $WorkDir).FullName
$containerName = 'codex_' + ($WorkDir -replace '[\\/]', '_' -replace '[^0-9A-Za-z_-]', '')

# Check whether OPENAI_API_KEY has been set in environment variables.
if (-not $env:OPENAI_API_KEY) {
Write-Error 'An OPENAI_API_KEY environment variable must be provided.'
exit 1
}

function Cleanup {
docker rm -f $containerName 2> $null
}

function Quote-BashArg {
param([string]$Value)
return "'$($Value -replace "'", "''\'''")'"
}

try {
Cleanup # Remove old container

docker run --name $containerName -d `
-e OPENAI_API_KEY `
--cap-add=NET_ADMIN --cap-add=NET_RAW `
-v "${WorkDir}:/app" `
codex sleep infinity | Out-Null

# docker exec $containerName bash -c 'sudo /usr/local/bin/init_firewall.sh'

$quoted = ($Args | ForEach-Object { Quote-BashArg $_ }) -join ' '

docker exec -it $containerName bash -c "cd '/app' && codex --full-auto $quoted"
}
finally {
Register-EngineEvent PowerShell.Exiting -Action { Cleanup } | Out-Null
}