Skip to content

Commit e42a08f

Browse files
Move building of Alpine to Alpine container host (#105)
1 parent f40a2a5 commit e42a08f

File tree

5 files changed

+166
-8
lines changed

5 files changed

+166
-8
lines changed

.pipelines/release.yml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,18 @@ extends:
8585
parameters:
8686
ARCHITECTURE: 'x64_arm64'
8787

88+
- stage: LinuxMuslBuild
89+
displayName: Linux Musl Build
90+
variables:
91+
- name: LinuxContainerImage
92+
value: mcr.microsoft.com/dotnet/sdk:10.0-alpine
93+
94+
jobs:
95+
- template: .pipelines/templates/build-alpine.yml@self
96+
parameters:
97+
ARCHITECTURE: 'linux-musl-x64'
98+
Name: 'Build_Linux_musl_x64'
99+
88100
- stage: LinuxBuild
89101
displayName: Linux Build
90102
jobs:
@@ -99,11 +111,6 @@ extends:
99111
Name: 'Build_Linux_arm64'
100112
hostArchitecture: 'arm64'
101113

102-
- template: .pipelines/templates/build-linux.yml@self
103-
parameters:
104-
ARCHITECTURE: 'linux-musl-x64'
105-
Name: 'Build_Linux_musl_x64'
106-
107114
- template: .pipelines/templates/build-linux.yml@self
108115
parameters:
109116
ARCHITECTURE: 'osx'
@@ -122,7 +129,7 @@ extends:
122129
Name: 'Build_Linux_arm'
123130

124131
- stage: Build_Nuget
125-
dependsOn: [WinBuildAndSign, LinuxBuild, LinuxBuildARM]
132+
dependsOn: [WinBuildAndSign, LinuxBuild, LinuxBuildARM, LinuxMuslBuild]
126133
displayName: Build NuGet
127134
jobs:
128135
- template: .pipelines/templates/build-nuget.yml@self
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
parameters:
2+
- name: ARCHITECTURE
3+
type: string
4+
default: 'x64'
5+
- name: Name
6+
type: string
7+
default: 'Build_musl_x64'
8+
- name: hostArchitecture
9+
type: string
10+
default: 'amd64'
11+
12+
jobs:
13+
- job: PrepareDockerBuild
14+
pool:
15+
type: linux
16+
${{ if eq(parameters.hostArchitecture, 'arm64') }}:
17+
hostArchitecture: 'arm64'
18+
displayName: Prepare_Docker_Build
19+
variables:
20+
- name: ob_outputDirectory
21+
value: '$(Build.ArtifactStagingDirectory)/ONEBRANCH_ARTIFACT'
22+
- name: ob_signing_setup_enabled
23+
value: true
24+
- name: LinuxContainerImage
25+
value: mcr.microsoft.com/onebranch/azurelinux/build:3.0
26+
steps:
27+
- checkout: self
28+
clean: true
29+
30+
- pwsh: |
31+
Get-ChildItem Env:\ | Out-String -Stream | Write-Verbose -Verbose
32+
displayName: Capture environment variables
33+
34+
- pwsh: |
35+
New-Item -ItemType Directory -Path "$(ob_outputDirectory)" | Out-Null
36+
displayName: 'Create output directory'
37+
38+
- pwsh: |
39+
Copy-Item -Path "$(Build.SourcesDirectory)/*" -Destination "$(ob_outputDirectory)" -Force -Verbose -Recurse
40+
displayName: 'Copy Dockerfile to output directory'
41+
42+
- job: ${{ parameters.Name }}
43+
pool:
44+
type: docker
45+
os: linux
46+
${{ if eq(parameters.hostArchitecture, 'arm64') }}:
47+
hostArchitecture: 'arm64'
48+
displayName: Linux_MUSL_${{ parameters.ARCHITECTURE }}
49+
dependsOn: PrepareDockerBuild
50+
variables:
51+
- name: LinuxContainerImage
52+
value: mcr.microsoft.com/dotnet/sdk:10.0-alpine
53+
- name: ob_outputDirectory
54+
value: '$(Build.ArtifactStagingDirectory)/ONEBRANCH_ARTIFACT'
55+
- name: ob_signing_setup_enabled
56+
value: true
57+
- name: ARCHITECTURE
58+
value: ${{ parameters.ARCHITECTURE }}
59+
- name: DOTNET_SYSTEM_GLOBALIZATION_INVARIANT
60+
value: 1
61+
- ${{ if eq(parameters.ARCHITECTURE, 'linux-musl-arm64') }}:
62+
- name: ob_sdl_binskim_enabled
63+
value: false
64+
- name: ob_sdl_credscan_enabled
65+
value: false
66+
steps:
67+
- task: DownloadPipelineArtifact@2
68+
displayName: 'Download prepared Docker build context'
69+
inputs:
70+
buildType: 'current'
71+
artifactName: 'drop_LinuxMuslBuild_PrepareDockerBuild'
72+
targetPath: '$(Build.SourcesDirectory)/dst/drop_LinuxMuslBuild_PrepareDockerBuild'
73+
74+
- task: onebranch.pipeline.imagebuildinfo@1
75+
displayName: 'Build Alpine Image'
76+
inputs:
77+
repositoryName: 'psnative-alpine'
78+
dockerFileRelPath: 'drop_LinuxMuslBuild_PrepareDockerBuild/powershell-native/Dockerfile'
79+
dockerFileContextPath: 'drop_LinuxMuslBuild_PrepareDockerBuild/powershell-native'
80+
addPipelineData: false
81+
saveImageToPath: docker-images/psnative-alpine.tar
82+
build_tag: $(Build.BuildId)
83+
compress: false
84+
enable_isolated_acr_push: false
85+
enable_service_tree_acr_path: false
86+
enable_network: true
87+
88+
- job: ExtractLibPSL
89+
displayName: 'Extract libpsl-native.so'
90+
dependsOn: ${{ parameters.Name }}
91+
pool:
92+
type: linux
93+
variables:
94+
- name: LinuxContainerImage
95+
value: mcr.microsoft.com/onebranch/azurelinux/build:3.0
96+
- name: ob_outputDirectory
97+
value: '$(Build.ArtifactStagingDirectory)/ONEBRANCH_ARTIFACT'
98+
- name: ob_signing_setup_enabled
99+
value: false
100+
101+
steps:
102+
- checkout: self
103+
clean: true
104+
105+
- download: current
106+
artifact: drop_LinuxMuslBuild_Build_Linux_musl_x64
107+
patterns: docker-images/psnative-alpine.tar
108+
displayName: 'Download Docker image artifact'
109+
110+
- pwsh: |
111+
Get-ChildItem $(Pipeline.Workspace)/drop_LinuxMuslBuild_Build_Linux_musl_x64 -Recurse | Out-String -Stream | Write-Verbose -Verbose
112+
displayName: Capture downloaded artifacts
113+
114+
- pwsh: |
115+
New-Item -ItemType Directory -Path "$(ob_outputDirectory)" | Out-Null
116+
New-Item -ItemType Directory -Path $(Pipeline.Workspace)/temp | Out-Null
117+
tar -xvf $(Pipeline.Workspace)/drop_LinuxMuslBuild_Build_Linux_musl_x64/docker-images/psnative-alpine.tar -C $(Pipeline.Workspace)/temp
118+
$manifest = Get-Content "$(Pipeline.Workspace)/temp/manifest.json"
119+
$manifest | Out-String -Stream | Write-Verbose -Verbose
120+
121+
$manifestJson = $manifest | ConvertFrom-Json
122+
$imageId = $manifestJson[0].Layers[0]
123+
$libPSLPath = "$(Pipeline.Workspace)/temp/$imageId"
124+
125+
Write-Verbose "Extracted layer path: $libPSLPath" -Verbose
126+
Get-ChildItem -Path "$libPSLPath" -Recurse | Out-String -Stream | Write-Verbose -Verbose
127+
128+
tar -xvf $libPSLPath
129+
130+
Get-ChildItem -Path . | Out-String -Stream | Write-Verbose -Verbose
131+
132+
Copy-Item -Path ./libpsl-native.so -Destination "$(ob_outputDirectory)/libpsl-native.so" -Force -Verbose
133+
displayName: 'Extract libpsl-native.so from image'

.pipelines/templates/build-nuget.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
3535
- pwsh: |
3636
$platforms = @("drop_LinuxBuild_Build_Linux_arm64",
37-
"drop_LinuxBuild_Build_Linux_musl_x64",
37+
"drop_LinuxMuslBuild_ExtractLibPSL",
3838
"drop_LinuxBuild_Build_Linux_x64",
3939
"drop_LinuxBuildARM_Build_Linux_arm",
4040
"drop_WinBuildAndSign_Build_Sign_x64",
@@ -50,7 +50,7 @@ jobs:
5050
$LinuxZipPath = "$(ob_outputDirectory)/drop_LinuxBuild_Build_Linux_x64.zip"
5151
$LinuxARMZipPath = "$(ob_outputDirectory)/drop_LinuxBuildARM_Build_Linux_arm.zip"
5252
$LinuxARM64ZipPath = "$(ob_outputDirectory)/drop_LinuxBuild_Build_Linux_arm64.zip"
53-
$LinuxAlpineZipPath = "$(ob_outputDirectory)/drop_LinuxBuild_Build_Linux_musl_x64.zip"
53+
$LinuxAlpineZipPath = "$(ob_outputDirectory)/drop_LinuxMuslBuild_ExtractLibPSL.zip"
5454
$macOSZipPath = "$(ob_outputDirectory)/drop_osx.zip"
5555
5656
$symbolsRoot = "$(ob_outputDirectory)/symbols"
@@ -67,6 +67,9 @@ jobs:
6767
}
6868
}
6969
70+
Write-Verbose -Verbose "Compressed platform artifacts"
71+
Get-ChildItem -Path "$(ob_outputDirectory)" | Out-String -Stream | Write-Verbose -Verbose
72+
7073
Import-Module $(Build.SourcesDirectory)/build.psm1 -Force
7174
$PackageRoot = New-Item -ItemType Directory -Path $(ob_outputDirectory)\NugetPackageSrc
7275
Start-BuildPowerShellNativePackage -PackageRoot $PackageRoot -Version $(PackageVersion) -WindowsX64ZipPath $WindowsX64ZipPath -WindowsX86ZipPath $WindowsX86ZipPath -WindowsARM64ZipPath $WindowsARM64ZipPath -LinuxZipPath $LinuxZipPath -LinuxARMZipPath $LinuxARMZipPath -LinuxARM64ZipPath $LinuxARM64ZipPath -LinuxAlpineZipPath $LinuxAlpineZipPath -macOSZipPath $macOSZipPath

Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM mcr.microsoft.com/dotnet/sdk:10.0-alpine AS build
2+
3+
RUN apk update \
4+
&& apk add build-base gcc abuild binutils git python3 bash cmake \
5+
&& apk upgrade
6+
7+
COPY . .
8+
9+
RUN pwsh -c "Import-Module ./build.psm1; Start-BuildNativeUnixBinaries";
10+
11+
FROM scratch AS export
12+
COPY --from=build /src/powershell-unix/libpsl-native.so /libpsl-native.so

build.psm1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,9 @@ function Start-BuildNativeUnixBinaries {
541541
if (-not (Test-Path $Lib)) {
542542
throw "Compilation of $Lib failed"
543543
}
544+
545+
Write-Verbose -Verbose "Build completed - $Lib"
546+
Get-ChildItem $Lib | Out-String -Stream | Write-Verbose -Verbose
544547
}
545548

546549
<#

0 commit comments

Comments
 (0)