-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDockerfile
More file actions
73 lines (57 loc) · 2.56 KB
/
Dockerfile
File metadata and controls
73 lines (57 loc) · 2.56 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
# Set the major version of dotnet
ARG DOTNET_VERSION=8.0
# ==============================================
# .NET: SDK Builder
# ==============================================
FROM mcr.microsoft.com/dotnet/sdk:${DOTNET_VERSION}-azurelinux3.0 AS builder
WORKDIR /build
# Update and install dependencies
RUN tdnf update --security -y && \
tdnf clean all
ARG CI
ENV CI=${CI}
# Copy entrypoint script
COPY ./script/web-docker-entrypoint.sh /app/docker-entrypoint.sh
# Restore Packages
COPY ./TramsDataApi.sln ./
COPY ./TramsDataApi/TramsDataApi.csproj ./TramsDataApi/
COPY ./Dfe.Academies.Api.Infrastructure/Dfe.Academies.Infrastructure.csproj ./Dfe.Academies.Api.Infrastructure/
COPY ./Dfe.Academies.Application/Dfe.Academies.Application.csproj ./Dfe.Academies.Application/
COPY ./Dfe.Academies.Domain/Dfe.Academies.Domain.csproj ./Dfe.Academies.Domain/
COPY ./Dfe.Academies.Utils/Dfe.Academies.Utils.csproj ./Dfe.Academies.Utils/
# Mount GitHub Token and restore
RUN --mount=type=secret,id=github_token dotnet nuget add source --username USERNAME --password $(cat /run/secrets/github_token) --store-password-in-clear-text --name github "https://nuget.pkg.github.com/DFE-Digital/index.json" && \
dotnet restore TramsDataApi
# Copy remaining source and publish
COPY ./TramsDataApi/ ./TramsDataApi/
COPY ./Dfe.Academies.Api.Infrastructure/ ./Dfe.Academies.Api.Infrastructure/
COPY ./Dfe.Academies.Application/ ./Dfe.Academies.Application/
COPY ./Dfe.Academies.Domain/ ./Dfe.Academies.Domain/
COPY ./Dfe.Academies.Utils/ ./Dfe.Academies.Utils/
RUN dotnet publish TramsDataApi -c Release -o /app --no-restore
FROM builder AS efbuilder
WORKDIR /build
ENV PATH=$PATH:/root/.dotnet/tools
RUN mkdir /sql
COPY ./script/init-docker-entrypoint.sh /sql/entrypoint.sh
RUN chmod +x /sql/entrypoint.sh
FROM mcr.microsoft.com/dotnet/aspnet:${DOTNET_VERSION}-azurelinux3.0 AS initcontainer
WORKDIR /sql
# Copy migration bundles and appsettings
COPY --from=efbuilder /sql /sql
COPY --from=builder /app/appsettings* /TramsDataApi/
# Set ownership and switch user
RUN chown "$APP_UID" /sql -R && \
chown "$APP_UID" /TramsDataApi -R
USER $APP_UID
# ==============================================
# .NET: Runtime
# ==============================================
FROM mcr.microsoft.com/dotnet/aspnet:${DOTNET_VERSION}-azurelinux3.0 AS final
WORKDIR /app
LABEL org.opencontainers.image.source="https://github.com/DFE-Digital/academies-api"
LABEL org.opencontainers.image.description="Academies API"
# Copy published app and set permissions
COPY --from=builder /app /app
RUN chmod +x ./docker-entrypoint.sh
USER $APP_UID