-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate OpenAPI document generation from build-env stage
Signed-off-by: Yasumasa Suenaga <suenaga@oss.nttdata.com>
- Loading branch information
Showing
1 changed file
with
16 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,24 +1,33 @@ | ||
# For OpenAPI document | ||
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0 AS openapi-env | ||
WORKDIR /app | ||
ENV DOTNET_ROLL_FORWARD LatestMajor | ||
COPY . ./ | ||
RUN dotnet build CarbonAware.WebApi/src/CarbonAware.WebApi.csproj -o build | ||
WORKDIR /app/CarbonAware.WebApi/src | ||
RUN dotnet tool restore && \ | ||
dotnet tool run swagger tofile --output /app/build/swagger.yaml --yaml /app/build/CarbonAware.WebApi.dll v1 | ||
|
||
|
||
# Builder | ||
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0 AS build-env | ||
ARG TARGETARCH | ||
WORKDIR /app | ||
|
||
ENV DOTNET_ROLL_FORWARD LatestMajor | ||
# Copy everything from source | ||
COPY . ./ | ||
# Use implicit restore to build and publish | ||
RUN dotnet publish CarbonAware.WebApi/src/CarbonAware.WebApi.csproj -a $TARGETARCH -o publish | ||
# Generate OpenAPI spec | ||
WORKDIR /app/CarbonAware.WebApi/src | ||
RUN dotnet tool restore && \ | ||
mkdir -p /app/publish/wwwroot/api/v1 && \ | ||
dotnet tool run swagger tofile --output /app/publish/wwwroot/api/v1/swagger.yaml --yaml /app/publish/CarbonAware.WebApi.dll v1 | ||
|
||
|
||
# Build runtime image | ||
FROM mcr.microsoft.com/dotnet/aspnet:8.0 | ||
# Install curl for health check | ||
RUN apt-get update && \ | ||
apt-get install -y --no-install-recommends curl | ||
# Copy artifacts from build-env | ||
# Copy artifacts | ||
WORKDIR /app | ||
COPY --from=build-env /app/publish . | ||
RUN mkdir -p /app/wwwroot/api/v1 | ||
COPY --from=openapi-env /app/build/swagger.yaml /app/wwwroot/api/v1/ | ||
ENTRYPOINT ["dotnet", "CarbonAware.WebApi.dll"] |