Daily Windows Docker Build #19
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
| name: Daily Windows Docker Build | |
| on: | |
| schedule: | |
| - cron: "0 16 * * *" # Run daily at 8:00am Pacific Time (UTC-8) | |
| workflow_dispatch: # Allow manual triggering | |
| jobs: | |
| build-windows: | |
| runs-on: windows-2022 | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set date | |
| id: date | |
| run: echo "DATE=$(Get-Date -Format 'yyyy-MM-dd')" >> $env:GITHUB_ENV | |
| shell: pwsh | |
| - name: Get bootstrap script hash | |
| id: bootstrap-hash | |
| run: | | |
| $content = (Invoke-WebRequest -Uri 'https://raw.githubusercontent.com/oven-sh/bun/main/scripts/bootstrap.ps1').Content | |
| $bytes = [System.Text.Encoding]::UTF8.GetBytes($content) | |
| $hash = (Get-FileHash -InputStream ([System.IO.MemoryStream]::new($bytes)) -Algorithm SHA256).Hash | |
| $shortHash = $hash.Substring(0, 7) | |
| echo "HASH=$shortHash" >> $env:GITHUB_OUTPUT | |
| shell: pwsh | |
| - name: Get Bun repo commit SHA | |
| id: bun-sha | |
| run: | | |
| $sha = gh api repos/oven-sh/bun/commits/main --jq .sha | |
| $shortSha = $sha.Substring(0, 7) | |
| echo "SHA=$shortSha" >> $env:GITHUB_OUTPUT | |
| shell: pwsh | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Log in to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| # clear some space on windows runner | |
| # https://github.com/hugoalh/disk-space-optimizer-ghaction/blob/main/list.yml | |
| - name: Clear some space on windows runner | |
| run: | | |
| $disk = Get-WmiObject -Class Win32_LogicalDisk -Filter "DeviceID='C:'" | |
| $totalGB = [math]::Round($disk.Size / 1GB, 2) | |
| $usedGB = [math]::Round(($disk.Size - $disk.FreeSpace) / 1GB, 2) | |
| $usedPercent = [math]::Round((($disk.Size - $disk.FreeSpace) / $disk.Size) * 100, 1) | |
| Write-Host "Disk space before cleanup: $usedGB GB used / $totalGB GB total ($usedPercent%)" -ForegroundColor Yellow | |
| $paths = @( | |
| "C:\Program Files\dotnet", | |
| "C:\Program Files (x86)\dotnet", | |
| "C:\Users\Default\.dotnet", | |
| "C:\Android", | |
| "C:\Program Files (x86)\Android", | |
| "$Env:AGENT_TOOLSDIRECTORY\CodeQL", | |
| "$Env:AGENT_TOOLSDIRECTORY\Ruby", | |
| "$Env:AGENT_TOOLSDIRECTORY\go", | |
| # "$Env:AGENT_TOOLSDIRECTORY\node", | |
| "$Env:AGENT_TOOLSDIRECTORY\Python", | |
| "$Env:AGENT_TOOLSDIRECTORY\PyPy", | |
| "$Env:AGENT_TOOLSDIRECTORY\stack", | |
| "C:\Program Files\MySQL", | |
| "C:\Program Files\PostgreSQL", | |
| "C:\Rust", | |
| "C:\vcpkg", | |
| "C:\msys64", | |
| "C:\Strawberry", | |
| "C:\SeleniumWebDrivers", | |
| "C:\Program Files (x86)\Google", | |
| "C:\Program Files\Mozilla Firefox", | |
| "C:\Program Files (x86)\pipx", | |
| "C:\Program Files (x86)\pipx_bin", | |
| "C:\Julia", | |
| "C:\cf-cli", | |
| "C:\tools\php", | |
| "C:\tools\nginx", | |
| "C:\tools\Apache", | |
| "C:\Miniconda", | |
| "C:\Program Files\R", | |
| "C:\selenium", | |
| "C:\Program Files (x86)\Inno Setup 6", | |
| "C:\Program Files (x86)\Epic Games", | |
| "C:\Program Files (x86)\Internet Explorer", | |
| "C:\Program Files (x86)\IIS Express", | |
| "C:\Program Files (x86)\IIS", | |
| "C:\Program Files\Microsoft SQL Server", | |
| "C:\ProgramData\Microsoft\VisualStudio" | |
| ) | |
| foreach ($path in $paths) { | |
| if (Test-Path $path) { | |
| try { | |
| [System.IO.Directory]::Delete($path, $true) | |
| } catch { } | |
| } | |
| } | |
| Get-ChildItem "$Env:AGENT_TOOLSDIRECTORY" -Filter "Java*" -Directory -ErrorAction SilentlyContinue | ForEach-Object { | |
| try { | |
| [System.IO.Directory]::Delete($_.FullName, $true) | |
| } catch { } | |
| } | |
| try { | |
| Remove-Item -Recurse -Force -ErrorAction SilentlyContinue "C:\Windows\Temp\*" | |
| Remove-Item -Recurse -Force -ErrorAction SilentlyContinue "$env:TEMP\*" | |
| } catch { } | |
| $diskAfter = Get-WmiObject -Class Win32_LogicalDisk -Filter "DeviceID='C:'" | |
| $usedGBAfter = [math]::Round(($diskAfter.Size - $diskAfter.FreeSpace) / 1GB, 2) | |
| $reclaimedGB = [math]::Round(($usedGB - $usedGBAfter), 2) | |
| Write-Host "Reclaimed $reclaimedGB GB of disk space" -ForegroundColor Green | |
| shell: pwsh | |
| # === BOOTSTRAP STAGE === | |
| # important to cache as its really big, so it will allow `docker pull` on external users to be faster | |
| - name: Pull bootstrap cache | |
| continue-on-error: true | |
| timeout-minutes: 30 | |
| shell: pwsh | |
| run: try { docker pull ghcr.io/${{ github.repository }}-windows:bootstrap-amd64-${{ steps.bootstrap-hash.outputs.HASH }} } catch { } | |
| - name: Build bootstrap stage | |
| uses: nick-fields/retry@v3 | |
| with: | |
| timeout_minutes: 80 | |
| max_attempts: 5 | |
| shell: pwsh | |
| command: | | |
| docker build ` | |
| --isolation=process ` | |
| --memory 14g ` | |
| --pull ` | |
| --build-arg BOOTSTRAP_HASH=${{ steps.bootstrap-hash.outputs.HASH }} ` | |
| -f Dockerfile.windows ` | |
| --target bootstrap ` | |
| --cache-from ghcr.io/${{ github.repository }}-windows:bootstrap-amd64-${{ steps.bootstrap-hash.outputs.HASH }} ` | |
| -t ghcr.io/${{ github.repository }}-windows:bootstrap-amd64-${{ steps.bootstrap-hash.outputs.HASH }} ` | |
| -t ghcr.io/${{ github.repository }}-windows:bootstrap-amd64 ` | |
| -t ghcr.io/${{ github.repository }}-windows:bootstrap ` | |
| . | |
| - name: Push bootstrap stage | |
| uses: nick-fields/retry@v3 | |
| with: | |
| timeout_minutes: 120 | |
| max_attempts: 5 | |
| shell: pwsh | |
| command: | | |
| docker push ghcr.io/${{ github.repository }}-windows:bootstrap-amd64-${{ steps.bootstrap-hash.outputs.HASH }} | |
| docker push ghcr.io/${{ github.repository }}-windows:bootstrap-amd64 | |
| docker push ghcr.io/${{ github.repository }}-windows:bootstrap | |
| # === BASE STAGE === | |
| - name: Pull base cache | |
| continue-on-error: true | |
| timeout-minutes: 15 | |
| shell: pwsh | |
| run: try { docker pull ghcr.io/${{ github.repository }}-windows:base-amd64-${{ steps.bun-sha.outputs.SHA }} } catch { } | |
| - name: Build base stage | |
| uses: nick-fields/retry@v3 | |
| with: | |
| timeout_minutes: 15 | |
| max_attempts: 10 | |
| shell: pwsh | |
| command: | | |
| docker build ` | |
| --isolation=process ` | |
| --build-arg BOOTSTRAP_HASH=${{ steps.bootstrap-hash.outputs.HASH }} ` | |
| --build-arg GIT_SHA=${{ steps.bun-sha.outputs.SHA }} ` | |
| -f Dockerfile.windows ` | |
| --target base ` | |
| --cache-from ghcr.io/${{ github.repository }}-windows:bootstrap-amd64-${{ steps.bootstrap-hash.outputs.HASH }} ` | |
| --cache-from ghcr.io/${{ github.repository }}-windows:base-amd64-${{ steps.bun-sha.outputs.SHA }} ` | |
| -t ghcr.io/${{ github.repository }}-windows:base-amd64-${{ steps.bun-sha.outputs.SHA }} ` | |
| -t ghcr.io/${{ github.repository }}-windows:base-amd64-${{ env.DATE }} ` | |
| -t ghcr.io/${{ github.repository }}-windows:base-${{ env.DATE }} ` | |
| -t ghcr.io/${{ github.repository }}-windows:base-amd64 ` | |
| -t ghcr.io/${{ github.repository }}-windows:base ` | |
| . | |
| - name: Push base stage | |
| uses: nick-fields/retry@v3 | |
| with: | |
| timeout_minutes: 15 | |
| max_attempts: 5 | |
| shell: pwsh | |
| command: | | |
| docker push ghcr.io/${{ github.repository }}-windows:base-amd64-${{ steps.bun-sha.outputs.SHA }} | |
| docker push ghcr.io/${{ github.repository }}-windows:base-amd64-${{ env.DATE }} | |
| docker push ghcr.io/${{ github.repository }}-windows:base-${{ env.DATE }} | |
| docker push ghcr.io/${{ github.repository }}-windows:base-amd64 | |
| docker push ghcr.io/${{ github.repository }}-windows:base | |
| # === PREBUILT STAGE === | |
| - name: Pull prebuilt cache | |
| continue-on-error: true | |
| timeout-minutes: 15 | |
| shell: pwsh | |
| run: try { docker pull ghcr.io/${{ github.repository }}-windows:prebuilt-amd64-${{ steps.bun-sha.outputs.SHA }} } catch { } | |
| - name: Build prebuilt stage | |
| uses: nick-fields/retry@v3 | |
| with: | |
| timeout_minutes: 80 | |
| max_attempts: 5 | |
| shell: pwsh | |
| command: | | |
| docker build ` | |
| --isolation=process ` | |
| --memory 14g ` | |
| --cpu-quota="300000" ` | |
| --build-arg BOOTSTRAP_HASH=${{ steps.bootstrap-hash.outputs.HASH }} ` | |
| --build-arg GIT_SHA=${{ steps.bun-sha.outputs.SHA }} ` | |
| -f Dockerfile.windows ` | |
| --target prebuilt ` | |
| --cache-from ghcr.io/${{ github.repository }}-windows:bootstrap-amd64-${{ steps.bootstrap-hash.outputs.HASH }} ` | |
| --cache-from ghcr.io/${{ github.repository }}-windows:base-amd64-${{ steps.bun-sha.outputs.SHA }} ` | |
| --cache-from ghcr.io/${{ github.repository }}-windows:prebuilt-amd64-${{ steps.bun-sha.outputs.SHA }} ` | |
| -t ghcr.io/${{ github.repository }}-windows:prebuilt-amd64-${{ steps.bun-sha.outputs.SHA }} ` | |
| -t ghcr.io/${{ github.repository }}-windows:prebuilt-amd64-${{ env.DATE }} ` | |
| -t ghcr.io/${{ github.repository }}-windows:prebuilt-${{ env.DATE }} ` | |
| -t ghcr.io/${{ github.repository }}-windows:prebuilt-amd64 ` | |
| -t ghcr.io/${{ github.repository }}-windows:prebuilt ` | |
| . | |
| - name: Push prebuilt stage | |
| uses: nick-fields/retry@v3 | |
| with: | |
| timeout_minutes: 30 | |
| max_attempts: 5 | |
| shell: pwsh | |
| command: | | |
| docker push ghcr.io/${{ github.repository }}-windows:prebuilt-amd64-${{ steps.bun-sha.outputs.SHA }} | |
| docker push ghcr.io/${{ github.repository }}-windows:prebuilt-amd64-${{ env.DATE }} | |
| docker push ghcr.io/${{ github.repository }}-windows:prebuilt-${{ env.DATE }} | |
| docker push ghcr.io/${{ github.repository }}-windows:prebuilt-amd64 | |
| docker push ghcr.io/${{ github.repository }}-windows:prebuilt | |
| # === ARTIFACTS STAGE === | |
| - name: Pull artifacts cache | |
| continue-on-error: true | |
| timeout-minutes: 15 | |
| shell: pwsh | |
| run: try { docker pull ghcr.io/${{ github.repository }}-windows:artifacts-amd64-${{ steps.bun-sha.outputs.SHA }} } catch { } | |
| - name: Build artifacts stage | |
| uses: nick-fields/retry@v3 | |
| with: | |
| timeout_minutes: 15 | |
| max_attempts: 5 | |
| shell: pwsh | |
| command: | | |
| docker build ` | |
| --isolation=process ` | |
| --build-arg BOOTSTRAP_HASH=${{ steps.bootstrap-hash.outputs.HASH }} ` | |
| --build-arg GIT_SHA=${{ steps.bun-sha.outputs.SHA }} ` | |
| -f Dockerfile.windows ` | |
| --target artifacts ` | |
| --cache-from ghcr.io/${{ github.repository }}-windows:bootstrap-amd64-${{ steps.bootstrap-hash.outputs.HASH }} ` | |
| --cache-from ghcr.io/${{ github.repository }}-windows:base-amd64-${{ steps.bun-sha.outputs.SHA }} ` | |
| --cache-from ghcr.io/${{ github.repository }}-windows:prebuilt-amd64-${{ steps.bun-sha.outputs.SHA }} ` | |
| --cache-from ghcr.io/${{ github.repository }}-windows:artifacts-amd64-${{ steps.bun-sha.outputs.SHA }} ` | |
| -t ghcr.io/${{ github.repository }}-windows:artifacts-amd64-${{ steps.bun-sha.outputs.SHA }} ` | |
| -t ghcr.io/${{ github.repository }}-windows:artifacts-amd64-${{ env.DATE }} ` | |
| -t ghcr.io/${{ github.repository }}-windows:artifacts-${{ env.DATE }} ` | |
| -t ghcr.io/${{ github.repository }}-windows:artifacts-amd64 ` | |
| -t ghcr.io/${{ github.repository }}-windows:artifacts ` | |
| . | |
| - name: Push artifacts stage | |
| uses: nick-fields/retry@v3 | |
| with: | |
| timeout_minutes: 15 | |
| max_attempts: 5 | |
| shell: pwsh | |
| command: | | |
| docker push ghcr.io/${{ github.repository }}-windows:artifacts-amd64-${{ steps.bun-sha.outputs.SHA }} | |
| docker push ghcr.io/${{ github.repository }}-windows:artifacts-amd64-${{ env.DATE }} | |
| docker push ghcr.io/${{ github.repository }}-windows:artifacts-${{ env.DATE }} | |
| docker push ghcr.io/${{ github.repository }}-windows:artifacts-amd64 | |
| docker push ghcr.io/${{ github.repository }}-windows:artifacts | |
| # === RUN STAGE === | |
| - name: Pull run cache | |
| continue-on-error: true | |
| timeout-minutes: 15 | |
| shell: pwsh | |
| run: try { docker pull ghcr.io/${{ github.repository }}-windows:run-amd64-${{ steps.bun-sha.outputs.SHA }} } catch { } | |
| - name: Build run stage | |
| uses: nick-fields/retry@v3 | |
| with: | |
| timeout_minutes: 15 | |
| max_attempts: 5 | |
| shell: pwsh | |
| command: | | |
| docker build ` | |
| --isolation=process ` | |
| --build-arg BOOTSTRAP_HASH=${{ steps.bootstrap-hash.outputs.HASH }} ` | |
| --build-arg GIT_SHA=${{ steps.bun-sha.outputs.SHA }} ` | |
| -f Dockerfile.windows ` | |
| --target run ` | |
| --cache-from ghcr.io/${{ github.repository }}-windows:bootstrap-amd64-${{ steps.bootstrap-hash.outputs.HASH }} ` | |
| --cache-from ghcr.io/${{ github.repository }}-windows:base-amd64-${{ steps.bun-sha.outputs.SHA }} ` | |
| --cache-from ghcr.io/${{ github.repository }}-windows:prebuilt-amd64-${{ steps.bun-sha.outputs.SHA }} ` | |
| --cache-from ghcr.io/${{ github.repository }}-windows:run-amd64-${{ steps.bun-sha.outputs.SHA }} ` | |
| -t ghcr.io/${{ github.repository }}-windows:run-amd64-${{ steps.bun-sha.outputs.SHA }} ` | |
| -t ghcr.io/${{ github.repository }}-windows:run-amd64-${{ env.DATE }} ` | |
| -t ghcr.io/${{ github.repository }}-windows:run-${{ env.DATE }} ` | |
| -t ghcr.io/${{ github.repository }}-windows:run-amd64 ` | |
| -t ghcr.io/${{ github.repository }}-windows:run ` | |
| -t ghcr.io/${{ github.repository }}-windows:latest ` | |
| . | |
| - name: Push run stage | |
| uses: nick-fields/retry@v3 | |
| with: | |
| timeout_minutes: 15 | |
| max_attempts: 5 | |
| shell: pwsh | |
| command: | | |
| docker push ghcr.io/${{ github.repository }}-windows:run-amd64-${{ steps.bun-sha.outputs.SHA }} | |
| docker push ghcr.io/${{ github.repository }}-windows:run-amd64-${{ env.DATE }} | |
| docker push ghcr.io/${{ github.repository }}-windows:run-${{ env.DATE }} | |
| docker push ghcr.io/${{ github.repository }}-windows:run-amd64 | |
| docker push ghcr.io/${{ github.repository }}-windows:run | |
| docker push ghcr.io/${{ github.repository }}-windows:latest | |
| # === TEST === | |
| - name: Test prebuilt container | |
| run: | | |
| @" | |
| FROM ghcr.io/${{ github.repository }}-windows:prebuilt-amd64-${{ steps.bun-sha.outputs.SHA }} | |
| RUN C:\workspace\bun\build\debug\bun-debug.exe --version | |
| CMD ["C:\\workspace\\bun\\build\\debug\\bun-debug.exe", "--version"] | |
| "@ | Out-File -FilePath Dockerfile.test -Encoding utf8 | |
| docker build --isolation=process -f Dockerfile.test -t test-bun . | |
| docker run --isolation=process --rm test-bun | |
| shell: pwsh |