mirror of
https://github.com/OPCFoundation/UA-.NETStandard.git
synced 2026-10-16 21:02:51 +08:00
e78c648295
# Description
Images CI took 45–100 min per image. The arm64 half of every
`linux/amd64,linux/arm64` build ran `dotnet restore` and `dotnet
publish` in an arm64 SDK container under QEMU. For `refserver`, publish
took 8 min natively for amd64 and 92 min emulated for arm64. On top of
that, every one of the 10 matrix legs recompiled the whole stack.
The output is framework-dependent portable IL, so the compile is now
done once, natively. The image legs only copy files onto the
per-platform runtime base image.
### Dockerfiles (all 10)
- **SDK stage runs on the build platform.** The `build` stage is pinned
to `--platform=$BUILDPLATFORM`. `-p:UseAppHost=false` keeps an x64 app
host out of the arm64 image.
- **New `prebuilt` stage.** It is chosen with a global `ARG
PUBLISH_SOURCE`, which defaults to `build`. Local `docker build` and the
`docker-compose` files are unchanged.
```dockerfile
FROM scratch AS prebuilt
ARG PUBLISH_DIR=artifacts/docker/publish
COPY ${PUBLISH_DIR}/ /app/publish/
FROM ${PUBLISH_SOURCE} AS publish
```
- **Pump: final-stage `RUN`s moved to a native stage.** The `sed` on
`openssl.cnf` and the `mkdir`/`chown`/`chmod` steps now run in a
`$BUILDPLATFORM` `layout` stage. The final stage copies `/layout/` to
`/`, so `/app` and `/diag` keep the `$APP_UID:0` owner and `g=u` mode
they had before. `openssl.cnf` therefore comes from the build-platform
base image. It is a plain config file, so it is expected to match
between architectures.
### `docker-image.yml`
- **Single image list.** The image list lives once, in `env.IMAGES`
(image, project, Dockerfile). `discover` emits it as the matrix.
- **New `publish-samples` job.** It runs `dotnet publish` for each
sample sequentially, so shared libraries compile once. It uses the same
options and NBGV version properties as the Dockerfiles and uploads the
output as the `docker-publish` artifact.
- **`build-and-push-image` legs.** Each leg:
- downloads the artifact;
- builds with `PUBLISH_SOURCE=prebuilt` and
`PUBLISH_DIR=artifacts/docker/publish/<image>`;
- no longer uses `setup-qemu-action`;
- is named `build-and-push-image (<image>)`.
- **`images summary`.** It now also fails when `publish-samples` fails.
### Docs
- `ContainerReferenceServer.md` describes the publish-once / copy-only
flow and the build arguments.
- `DeveloperGuide.md` mentions the `publish-samples` job in the Images
CI section.
Expected: one native publish of about 7 min, then 10 parallel
copy-and-push legs of a few minutes each. Not yet confirmed on CI: the
sandbox could not pull MCR base images, so the prebuilt multi-platform
builds were checked against a Debian-based stand-in base, and the
build-from-source path was not built.
## Related Issues
## Checklist
- [ ] I have signed the
[CLA](https://opcfoundation.org/license/cla/ContributorLicenseAgreementv1.0.pdf)
and read the
[CONTRIBUTING](https://github.com/OPCFoundation/UA-.NETStandard/blob/master/CONTRIBUTING.md)
doc.
- [ ] I have added tests that prove my fix is effective or that my
feature works and increased code coverage.
- [x] I have added all necessary documentation.
- [ ] I have verified that my changes do not introduce (new) build or
analyzer warnings.
- [ ] I ran **all** tests locally using the **UA.slnx** solution against
at least .net **framework** and .net **10**, and all passed.
- [ ] I fixed **all** failing and flaky tests in the CI pipelines and
**all** CodeQL warnings.
- [ ] I have addressed **all** PR feedback received.
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: romanett <7413710+romanett@users.noreply.github.com>
66 lines
3.7 KiB
Docker
66 lines
3.7 KiB
Docker
# OPC UA ConsoleReferenceServer sample image.
|
|
#
|
|
# The build context must be the repository ROOT so the project references resolve.
|
|
# Build directly:
|
|
# docker build -f samples/Reference/ConsoleReferenceServer/Dockerfile -t opcua-reference-server .
|
|
#
|
|
# The SDK stages always run on the build platform ($BUILDPLATFORM): the
|
|
# publish output is portable IL, so a multi-platform build never compiles
|
|
# under emulation. Images CI publishes every sample once in a native pre-job
|
|
# and selects the "prebuilt" stage instead, so the image legs only copy files:
|
|
# --build-arg PUBLISH_SOURCE=prebuilt --build-arg PUBLISH_DIR=<folder>
|
|
ARG PUBLISH_SOURCE=build
|
|
|
|
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:10.0-azurelinux3.0 AS restore
|
|
WORKDIR /src
|
|
|
|
# copy csproj and restore as distinct layers
|
|
COPY *.* .
|
|
COPY ["samples/Reference/ConsoleReferenceServer/ConsoleReferenceServer.csproj", "samples/Reference/ConsoleReferenceServer/"]
|
|
# The generator projects import shared MSBuild logic; restore fails with
|
|
# "Invalid framework identifier ''" if these are not part of the restore layer.
|
|
COPY ["tools/SourceGeneratorVariant.targets", "tools/"]
|
|
COPY ["tools/Opc.Ua.SourceGeneration.Core/Opc.Ua.SourceGeneration.Core.csproj", "tools/Opc.Ua.SourceGeneration.Core/"]
|
|
COPY ["tools/Opc.Ua.SourceGeneration.Stack/Opc.Ua.SourceGeneration.Stack.csproj", "tools/Opc.Ua.SourceGeneration.Stack/"]
|
|
COPY ["tools/Opc.Ua.SourceGeneration.Stack/Opc.Ua.SourceGeneration.Stack.Sources.targets", "tools/Opc.Ua.SourceGeneration.Stack/"]
|
|
COPY ["tools/Opc.Ua.SourceGeneration/Opc.Ua.SourceGeneration.csproj", "tools/Opc.Ua.SourceGeneration/"]
|
|
COPY ["tools/Opc.Ua.SourceGeneration/Opc.Ua.SourceGeneration.Sources.targets", "tools/Opc.Ua.SourceGeneration/"]
|
|
COPY ["src/Opc.Ua.Core.Types/Opc.Ua.Core.Types.csproj", "src/Opc.Ua.Core.Types/"]
|
|
COPY ["src/Opc.Ua.Core/Opc.Ua.Core.csproj", "src/Opc.Ua.Core/"]
|
|
COPY ["src/Opc.Ua.Core.Schema/Opc.Ua.Core.Schema.csproj", "src/Opc.Ua.Core.Schema/"]
|
|
COPY ["src/Opc.Ua.Core.Diagnostics/Opc.Ua.Core.Diagnostics.csproj", "src/Opc.Ua.Core.Diagnostics/"]
|
|
COPY ["src/Opc.Ua.Bindings.Https/Opc.Ua.Bindings.Https.csproj", "src/Opc.Ua.Bindings.Https/"]
|
|
COPY ["src/Opc.Ua.Types/Opc.Ua.Types.csproj", "src/Opc.Ua.Types/"]
|
|
COPY ["src/Opc.Ua.Security.Certificates/Opc.Ua.Security.Certificates.csproj", "src/Opc.Ua.Security.Certificates/"]
|
|
COPY ["src/Opc.Ua.Client/Opc.Ua.Client.csproj", "src/Opc.Ua.Client/"]
|
|
COPY ["src/Opc.Ua.Configuration/Opc.Ua.Configuration.csproj", "src/Opc.Ua.Configuration/"]
|
|
COPY ["src/Opc.Ua.Server/Opc.Ua.Server.csproj", "src/Opc.Ua.Server/"]
|
|
COPY ["samples/Quickstarts.Servers/Quickstarts.Servers.csproj", "samples/Quickstarts.Servers/"]
|
|
COPY ["src/Opc.Ua.Gds/Opc.Ua.Gds.csproj", "src/Opc.Ua.Gds/"]
|
|
COPY ["src/Opc.Ua.Gds.Server/Opc.Ua.Gds.Server.csproj", "src/Opc.Ua.Gds.Server/"]
|
|
ENV DOTNET_EnableWriteXorExecute=0
|
|
RUN dotnet restore "samples/Reference/ConsoleReferenceServer/ConsoleReferenceServer.csproj" --force -p:CustomTestTarget=net10.0
|
|
COPY . .
|
|
|
|
WORKDIR "/src/samples/Reference/ConsoleReferenceServer"
|
|
ARG Version
|
|
ARG SimpleVersion
|
|
ARG InformationalVersion
|
|
ENV OPTIONS="-c Release -f net10.0 -p:PublishAot=false -p:Dockerbuild=true -p:Version=${Version} -p:AssemblyVersion=${SimpleVersion} -p:FileVersion=${Version} -p:InformationalVersion=${InformationalVersion} -p:CustomTestTarget=net10.0"
|
|
|
|
FROM restore AS build
|
|
ENV DOTNET_EnableWriteXorExecute=0
|
|
RUN dotnet publish "ConsoleReferenceServer.csproj" --no-restore ${OPTIONS} -p:UseAppHost=false -o /app/publish
|
|
|
|
FROM scratch AS prebuilt
|
|
ARG PUBLISH_DIR=artifacts/docker/publish
|
|
COPY ${PUBLISH_DIR}/ /app/publish/
|
|
|
|
FROM ${PUBLISH_SOURCE} AS publish
|
|
|
|
FROM mcr.microsoft.com/dotnet/aspnet:10.0-azurelinux3.0-distroless-extra AS final
|
|
WORKDIR /app
|
|
COPY --from=publish /app/publish .
|
|
EXPOSE 62541
|
|
ENTRYPOINT ["dotnet", "ConsoleReferenceServer.dll"]
|