-
-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathdockerfile
More file actions
92 lines (74 loc) · 3.72 KB
/
Copy pathdockerfile
File metadata and controls
92 lines (74 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# Start with the official .NET 11 RC 1 SDK image
# Cache the dependencies so we don't have to restore them every time
#
# --platform=$BUILDPLATFORM: the build stages always run natively on the build
# host and cross-publish for $TARGETARCH (see the publish step below). Emulating
# the full .NET publish under QEMU is slow and unreliable, so multi-arch images
# only emulate the final runtime stage, which runs nothing at build time.
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:11.0.100-rc.1 AS dependencies
# Install Node.js (needed for the TypeScript compile during publish) from the
# official dist tarballs. The NodeSource apt script broke when the SDK image
# moved to Ubuntu 26.04, and a curl failure piped into bash passes silently;
# nodejs.org is distro-agnostic and -f makes any fetch failure fail the build.
ARG NODE_VERSION=24.18.0
RUN ARCH=$(dpkg --print-architecture) \
&& case "$ARCH" in \
amd64) NODE_ARCH=x64 ;; \
arm64) NODE_ARCH=arm64 ;; \
*) echo "Unsupported architecture: $ARCH" && exit 1 ;; \
esac \
&& curl -fsSL "https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-${NODE_ARCH}.tar.gz" -o /tmp/node.tar.gz \
&& tar -xzf /tmp/node.tar.gz -C /usr/local --strip-components=1 \
&& rm /tmp/node.tar.gz \
&& node --version
# Set the working directory to the app's source code directory
WORKDIR /app
# We need python for some reason
RUN apt-get update && apt-get install -y python3
RUN apt-get install -y libatomic1
# Restore the .NET dependencies
FROM dependencies AS dotnet-restore
# Copy the app's source code to the container image
COPY . .
# Stamp the $(SHORTHASH) asset-version placeholders (index.html, Version.cs, ...).
# CI passes the git short hash; local source builds default to "dev" because .git
# is dockerignored and the hash cannot be derived here. A no-op when the source
# was already stamped (as in CI, which replaces placeholders before docker build).
ARG SHORTHASH=dev
RUN grep -RIlZ '\$(SHORTHASH)' Valour | xargs -0 -r perl -pi -e 's/\$\(SHORTHASH\)/$ENV{SHORTHASH}/g'
# Restore workloads required by the server publish graph
RUN dotnet workload restore Valour/Server/Valour.Server.csproj
# Restore the app's dependencies
RUN dotnet restore Valour/BuildTools/CssBundler/CssBundler.csproj
RUN dotnet restore Valour/Server/Valour.Server.csproj
# Build stage for building/publishing the app
FROM dotnet-restore AS build
# Remove .js files that have corresponding .ts files
# RUN find . -name "*.ts" | while read tsfile; do \
# jsfile="${tsfile%.ts}.js"; \
# if [ -f "$jsfile" ]; then \
# echo "Deleting $jsfile because $tsfile exists"; \
# rm "$jsfile"; \
# fi; \
# done
# Build the app for the image's target architecture (framework-dependent,
# RID-specific). TARGETARCH is amd64/arm64 from buildx; the .NET CLI accepts
# those aliases directly.
ARG TARGETARCH
RUN dotnet publish Valour/Server/Valour.Server.csproj -c Release -a $TARGETARCH -o out
# Staging dir for the media mount point (see COPY --chown below)
RUN mkdir -p /staging/media
# Start with a smaller runtime image for the final image
FROM mcr.microsoft.com/dotnet/aspnet:11.0.0-rc.1-resolute-chiseled-extra AS final
# Set the working directory to the app's output directory
WORKDIR /app
# Copy the app's output files from the build-env image
COPY --from=build /app/out .
# Media storage mount point, owned by the non-root app user (uid 1654 in
# chiseled images) so named volumes inherit writable ownership on first use.
# Chiseled images have no shell, so this must be a COPY, not RUN mkdir.
COPY --from=build --chown=1654:1654 /staging/media /app/media
# Expose the app's port (if needed)
EXPOSE 80
# Start the app
ENTRYPOINT ["dotnet", "Valour.Server.dll"]