|
1 | | -# prepare base image |
2 | | -FROM mcr.microsoft.com/dotnet/runtime:8.0 AS base |
| 1 | +# Get build image |
| 2 | +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build |
| 3 | + |
3 | 4 | WORKDIR /app |
4 | 5 |
|
5 | | -# get build image |
6 | | -FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build |
7 | | -WORKDIR /src |
| 6 | +# Copy source |
| 7 | +COPY . ./ |
| 8 | + |
| 9 | +# Bring in metadata via --build-arg for build |
| 10 | +ARG IMAGE_VERSION=unknown |
8 | 11 |
|
9 | | -# run dotnet restore |
10 | | -COPY ["buildscript/buildscript.csproj", "buildscript/"] |
11 | | -RUN dotnet restore "buildscript/buildscript.csproj" |
| 12 | +# Restore packages |
| 13 | +RUN dotnet restore |
12 | 14 |
|
13 | | -# copy source and build |
14 | | -COPY . . |
15 | | -WORKDIR "/src/buildscript" |
16 | | -RUN dotnet build "buildscript.csproj" -c Release -o /app/build |
| 15 | +# Build project and run tests |
| 16 | +RUN dotnet test -v m /property:WarningLevel=0 |
17 | 17 |
|
18 | | -# create publish image |
19 | | -FROM build AS publish |
20 | | -RUN dotnet publish "buildscript.csproj" -c Release -o /app/publish |
| 18 | +# Publish release project |
| 19 | +RUN dotnet publish -v m /property:WarningLevel=0 -c Release --property:PublishDir=/app/publish/ |
| 20 | + |
| 21 | +# Copy release-publish.bash script |
| 22 | +RUN cp /app/release-publish.bash "/app/publish/" |
| 23 | + |
| 24 | +# Copy actual build script |
| 25 | +RUN cp /app/build.bash "/app/publish/" |
| 26 | + |
| 27 | +# Get runtime image |
| 28 | +FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS publish |
21 | 29 |
|
22 | | -# copy published app to final |
23 | | -FROM base AS final |
24 | 30 | WORKDIR /app |
25 | 31 |
|
26 | | -# Bring in metadata via --build-arg |
| 32 | +# Bring in metadata via --build-arg to publish |
27 | 33 | ARG BRANCH=unknown |
28 | 34 | ARG IMAGE_CREATED=unknown |
29 | 35 | ARG IMAGE_REVISION=unknown |
30 | 36 | ARG IMAGE_VERSION=unknown |
31 | 37 |
|
32 | 38 | # Configure image labels |
33 | | -LABEL branch=$branch \ |
34 | | -maintainer= "Maricopa County Library District developers <[email protected]>" \ |
35 | | -org.opencontainers.image.authors= "Maricopa County Library District developers <[email protected]>" \ |
36 | | -org.opencontainers.image.created=$IMAGE_CREATED \ |
37 | | -org.opencontainers.image.description="Build script test project" \ |
38 | | -org.opencontainers.image.licenses="MIT" \ |
39 | | -org.opencontainers.image.revision=$IMAGE_REVISION \ |
40 | | -org.opencontainers.image.source="https://github.com/MCLD/buildscript" \ |
41 | | -org.opencontainers.image.title="Build script test project" \ |
42 | | -org.opencontainers.image.vendor="Maricopa County Library District" \ |
43 | | -org.opencontainers.image.version=$IMAGE_VERSION |
| 39 | +LABEL branch=$BRANCH \ |
| 40 | + maintainer= "Maricopa County Library District developers <[email protected]>" \ |
| 41 | + org.opencontainers.image.authors= "Maricopa County Library District developers <[email protected]>" \ |
| 42 | + org.opencontainers.image.created=$IMAGE_CREATED \ |
| 43 | + org.opencontainers.image.description="Build script test project" \ |
| 44 | + org.opencontainers.image.licenses="MIT" \ |
| 45 | + org.opencontainers.image.revision=$IMAGE_REVISION \ |
| 46 | + org.opencontainers.image.source="https://github.com/MCLD/buildscript" \ |
| 47 | + org.opencontainers.image.title="Build scrip test project" \ |
| 48 | + org.opencontainers.image.vendor="Maricopa County Library District" \ |
| 49 | + org.opencontainers.image.version=$IMAGE_VERSION |
44 | 50 |
|
45 | 51 | # Default image environment variable settings |
46 | 52 | ENV org.opencontainers.image.created=$IMAGE_CREATED \ |
47 | | -org.opencontainers.image.revision=$IMAGE_REVISION \ |
48 | | -org.opencontainers.image.version=$IMAGE_VERSION |
| 53 | + org.opencontainers.image.revision=$IMAGE_REVISION \ |
| 54 | + org.opencontainers.image.version=$IMAGE_VERSION |
| 55 | + |
| 56 | +# Copy source |
| 57 | +COPY --from=build "/app/publish/" . |
49 | 58 |
|
50 | | -COPY --from=publish /app/publish . |
| 59 | +# Set entrypoint |
51 | 60 | ENTRYPOINT ["dotnet", "buildscript.dll"] |
0 commit comments