-
Notifications
You must be signed in to change notification settings - Fork 35
Add windows docker build script #125
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
Merged
stefano-garzarella
merged 5 commits into
rust-vmm:main
from
youngbash88:add-windows-docker-build
Apr 4, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
set -ex | ||
|
||
ARCH=$(uname -m) | ||
RUST_TOOLCHAIN="1.85.0" | ||
|
||
apt-get update | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
IMAGE_NAME=rustvmm/dev | ||
REGISTRY=index.docker.io | ||
GIT_COMMIT=$(git rev-parse HEAD) | ||
GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD) | ||
RUST_TOOLCHAIN="1.85.0" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
param( | ||
[Parameter(Mandatory=$false)] | ||
[string]$Command | ||
) | ||
$ErrorActionPreference = "Stop" | ||
Get-Content docker.env | Where-Object { $_ -match '^([^#][^=]+)=(.+)$' } | ForEach-Object { | ||
if ($matches[2] -match '\$\((.*)\)') { | ||
$cmdOutput = Invoke-Expression $matches[1] | ||
Set-Variable -Name $matches[1].Trim() -Value $cmdOutput -Scope Script | ||
} else { | ||
Set-Variable -Name $matches[1].Trim() -Value $matches[2].Trim() -Scope Script | ||
} | ||
} | ||
$ARCH = "x86_64" # Explicitly set the architecture | ||
|
||
function Next-Version { | ||
return (git show -s --format=%h) | ||
} | ||
|
||
function Get-FullVersion { | ||
$version = Next-Version | ||
return "${IMAGE_NAME}:g${version}" | ||
} | ||
|
||
function Print-NextVersion { | ||
Write-Output (Get-FullVersion) | ||
} | ||
|
||
function Print-Registry { | ||
Write-Output $REGISTRY | ||
} | ||
|
||
function Print-ImageName { | ||
Write-Output $IMAGE_NAME | ||
} | ||
|
||
function Build-Tag { | ||
return "$(Get-FullVersion)_$ARCH" | ||
} | ||
|
||
function Check-ExitCode { | ||
param ( | ||
[int]$ExitCode, | ||
[string]$Message | ||
) | ||
|
||
if ($ExitCode -ne 0) { | ||
Write-Error $Message | ||
exit $ExitCode | ||
} | ||
} | ||
youngbash88 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
function Build-Container { | ||
# Check if running in Linux or Windows container mode | ||
$containerInfo = docker version --format '{{.Server.Os}}' | ||
$dockerfile = if ($containerInfo -eq "linux") { | ||
"Dockerfile" | ||
} else { | ||
"Dockerfile.windows.x86_64" | ||
} | ||
|
||
# Build the container and check for failures | ||
$tag = Build-Tag | ||
Write-Host "Building using $dockerfile in $containerInfo container mode..." | ||
|
||
docker build -t $tag ` | ||
--build-arg GIT_BRANCH=$GIT_BRANCH ` | ||
--build-arg GIT_COMMIT=$GIT_COMMIT ` | ||
--build-arg RUST_TOOLCHAIN=$RUST_TOOLCHAIN ` | ||
-f $dockerfile . | ||
Check-ExitCode $LASTEXITCODE "Build failed with exit code $LASTEXITCODE" | ||
Write-Host "Build completed for $tag" | ||
} | ||
|
||
function Publish-Container { | ||
$tag = Build-Tag | ||
Write-Host "Publishing $tag to dockerhub" | ||
|
||
# Check if image exists locally | ||
$imageExists = docker image inspect $tag 2>$null | ||
Check-ExitCode $LASTEXITCODE "Image $tag not found locally. Please run 'build' first." | ||
|
||
# Attempt to push | ||
docker push $tag | ||
Check-ExitCode $LASTEXITCODE "Failed to publish $tag" | ||
Write-Host "Successfully published $tag" | ||
} | ||
|
||
# Handle commands | ||
switch ($Command) { | ||
"build" { Build-Container } | ||
"publish" { Publish-Container } | ||
"print-registry" { Print-Registry } | ||
"print-image-name" { Print-ImageName } | ||
"print-next-version" { Print-NextVersion } | ||
default { | ||
Write-Host "Command $Command not supported. Try with 'publish', 'build', or 'print-next-version'." | ||
exit 1 | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.