-
Notifications
You must be signed in to change notification settings - Fork 94
Refactor inline powershell into separate script #591
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
aholstrup1
wants to merge
15
commits into
microsoft:main
Choose a base branch
from
aholstrup1:buildrefactor
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
9674eb9
Build and markstale scripts
aholstrup1 fed23f5
PR Build
aholstrup1 8949843
Merge branch 'main' of https://github.com/microsoft/nav-docker
aholstrup1 88f644a
CI
aholstrup1 e17316a
master
aholstrup1 32791d6
Merge branch 'main' of https://github.com/microsoft/nav-docker
aholstrup1 853c800
Merge branch 'main' of https://github.com/microsoft/nav-docker
aholstrup1 a5bd8fb
Small fixes
aholstrup1 b1d1afd
documentation
aholstrup1 8ba417c
Update docs
aholstrup1 cb0c583
return image
aholstrup1 c682e02
Move analyze inline script into separate script
aholstrup1 90d7179
prbuild fix
aholstrup1 6408185
PR Build fix 2
aholstrup1 74575a4
Merge branch 'main' into buildrefactor
mazhelez 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| name: CI | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: [ master ] | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| defaults: | ||
| run: | ||
| shell: PowerShell | ||
|
|
||
| jobs: | ||
| AnalyzeImages: | ||
| runs-on: [ windows-latest ] | ||
| outputs: | ||
| genericTag: ${{ steps.Analyze.outputs.genericTag }} | ||
| buildImagesJson: ${{ steps.Analyze.outputs.buildImagesJson }} | ||
| digestsJson: ${{ steps.Analyze.outputs.digestsJson }} | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Analyze | ||
| id: Analyze | ||
| run: | | ||
| $erroractionpreference = "STOP" | ||
| try { | ||
| $bctags = @('ltsc2016','ltsc2019','ltsc2022','ltsc2025') | ||
| $servercoretags = @{ | ||
| "ltsc2016" = "4.8-windowsservercore-ltsc2016" | ||
| "ltsc2019" = "4.8-windowsservercore-ltsc2019" | ||
| "ltsc2022" = "4.8.1-windowsservercore-ltsc2022" | ||
| "ltsc2025" = "4.8.1-windowsservercore-ltsc2025" | ||
| } | ||
| $tags = @($bctags | ForEach-Object { "$_-dev"; "$_-filesonly-dev" }) | ||
| if ($prod) { | ||
| $tags += @($bctags | ForEach-Object { "$_"; "$_-filesonly" }) | ||
| } | ||
| $digests = $tags | ForEach-Object { | ||
| Write-Host -NoNewline "$_ : " | ||
| $manifest = docker manifest inspect mcr.microsoft.com/businesscentral:$_ -v | ConvertFrom-Json | ||
| $manifest.Descriptor.digest | ||
| } | Select-Object -Unique | ||
| Set-Location "generic" | ||
| $rootPath = Get-Location | ||
| $genericTag = (Get-Content -Raw -Path (Join-Path $RootPath 'tag.txt')).Trim(@(13,10,32)) | ||
| $tagver = [System.Version]$genericTag | ||
| $revision = [int]($ENV:GITHUB_RUN_NUMBER) | ||
| $genericTag = "$($tagver.Major).$($tagver.Minor).$($tagver.Build).$revision" | ||
| Write-Host "Using generic Tag $genericTag" | ||
| $webclient = New-Object System.Net.WebClient | ||
| $webclient.Headers.Add('Accept', "application/json") | ||
| $neededBcTags = $bctags | ForEach-Object { | ||
| $osVersion = [System.Version](($webclient.DownloadString("https://mcr.microsoft.com/v2/dotnet/framework/runtime/manifests/$($serverCoreTags."$_")") | ConvertFrom-Json).history[0].v1Compatibility | ConvertFrom-Json)."os.version" | ||
| "$osVersion-$genericTag|mcr.microsoft.com/dotnet/framework/runtime:$($serverCoreTags."$_")|$_" | ||
| "$osVersion-$genericTag-filesonly|mcr.microsoft.com/dotnet/framework/runtime:$($serverCoreTags."$_")|$_" | ||
| } | ||
| Write-Host "Needed Tags ($($neededBcTags.Count))" | ||
| $neededBcTags | ForEach-Object { Write-Host "- $_" } | ||
| $alltags = (($webclient.DownloadString("https://mcr.microsoft.com/v2/businesscentral/tags/list") | ConvertFrom-Json)).tags | ||
| $imagesBcTags = @($neededBcTags | Where-Object { $alltags -notcontains $_ }) | ||
| Write-Host "Image Tags ($($imagesBcTags.Count))" | ||
| if ($imagesBcTags) { | ||
| $imagesBcTags | ForEach-Object { Write-Host "- $_" } | ||
| } | ||
| else { | ||
| Write-Host '- none' | ||
| } | ||
| $buildImagesJson = ConvertTo-Json -InputObject $imagesBcTags -Compress | ||
| $digestsJson = ConvertTo-Json -InputObject $digests -Compress | ||
| Add-Content -encoding utf8 -Path $ENV:GITHUB_OUTPUT -Value "digestsJson=$digestsJson" | ||
| Write-Host "digestsJson=$digestsJson" | ||
| Add-Content -encoding utf8 -Path $ENV:GITHUB_OUTPUT -Value "genericTag=$genericTag" | ||
| Write-Host "genericTag=$genericTag" | ||
| Add-Content -encoding utf8 -Path $ENV:GITHUB_OUTPUT -Value "buildImagesJson=$buildImagesJson" | ||
| Write-Host "buildImagesJson=$buildImagesJson" | ||
| } | ||
| catch { | ||
| Write-Host "::Error::Error analyzing images. Error was $($_.Exception.Message)" | ||
| $host.SetShouldExit(1) | ||
| } | ||
|
|
||
| BuildImages: | ||
| runs-on: [ Windows-2025 ] | ||
| needs: [ AnalyzeImages ] | ||
| strategy: | ||
| matrix: | ||
| tag: ${{ fromJson(needs.AnalyzeImages.outputs.buildImagesJson) }} | ||
| fail-fast: false | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Build Image | ||
| env: | ||
| Tag: ${{ matrix.tag }} | ||
| GenericTag: ${{ needs.AnalyzeImages.outputs.genericTag }} | ||
| run: | | ||
| $osversion = $env:Tag.split('|')[0].split('-')[0] | ||
| $filesonly = ($env:Tag -like '*-filesonly|*') | ||
| $only24 = ($env:Tag -like '*-24|*' -or $env:Tag -like '*-24-filesonly|*') | ||
| $baseImage = $env:Tag.split('|')[1] | ||
| $ltscTag = $env:Tag.split('|')[2] | ||
|
|
||
| . ${{ github.workspace }}/build/build.ps1 ` | ||
| -BaseImage $baseImage ` | ||
| -LtscTag $ltscTag ` | ||
| -FilesOnly $filesonly ` | ||
| -Only24 $only24 ` | ||
| -GenericTag $env:GenericTag | ||
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,28 @@ | ||
| # How to build and test images locally | ||
|
|
||
| ## Prerequisites | ||
| - Install and run [Docker Desktop](https://docs.docker.com/desktop/install/windows-install/). Make sure it is running Windows containers. | ||
| - Install [BcContainerHelper PS module](https://www.powershellgallery.com/packages/BcContainerHelper) (latest available version). | ||
| `Install-Module BCContainerHelper -AllowPrerelease` would do. | ||
|
|
||
| ## Build a new image locally | ||
|
|
||
| If you want to build a new docker image locally you can use the build.ps1 script. The following will produce a new docker image based on Windows Server Core 2025. | ||
| ```powershell | ||
| $GenericTag = "1.2.3.4" | ||
| $baseImage = "mcr.microsoft.com/dotnet/framework/runtime:4.8.1-windowsservercore-ltsc2025" | ||
| ./build/build.ps1 -BaseImage $baseImage -LtscTag 'ltsc2025' -FilesOnly $false -Only24 $false -GenericTag $GenericTag | ||
| ``` | ||
|
|
||
| If you'd rather use a different base image, you can also use one of the following: | ||
| * mcr.microsoft.com/dotnet/framework/runtime:4.8-windowsservercore-ltsc2016 | ||
| * mcr.microsoft.com/dotnet/framework/runtime:4.8-windowsservercore-ltsc2019 | ||
| * mcr.microsoft.com/dotnet/framework/runtime:4.8.1-windowsservercore-ltsc2022 | ||
| * mcr.microsoft.com/dotnet/framework/runtime:4.8.1-windowsservercore-ltsc2025 | ||
|
|
||
| ## Create a docker container with the image | ||
|
|
||
| Once you have a local image you can use New-BCContainer to spin up a Business Central container that uses your image. | ||
| ```powershell | ||
| New-BcContainer -accept_eula -accept_insiderEula -containerName "MyTestContainer" -artifactUrl (Get-BCArtifactUrl -select NextMajor -accept_insiderEula -country W1) -useGenericImage "my:$GenericTag" | ||
| ``` |
Oops, something went wrong.
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.