-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathDockerfile
59 lines (48 loc) · 2.23 KB
/
Dockerfile
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
FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine AS build
# Set the working directory witin the container
WORKDIR /build
# Copy the sln and csproj files. These are the only files
# required in order to restore
COPY ./dwCheckApi.Common/dwCheckApi.Common.csproj ./dwCheckApi.Common/dwCheckApi.Common.csproj
COPY ./dwCheckApi.DAL/dwCheckApi.DAL.csproj ./dwCheckApi.DAL/dwCheckApi.DAL.csproj
COPY ./dwCheckApi.DTO/dwCheckApi.DTO.csproj ./dwCheckApi.DTO/dwCheckApi.DTO.csproj
COPY ./dwCheckApi.Entities/dwCheckApi.Entities.csproj ./dwCheckApi.Entities/dwCheckApi.Entities.csproj
COPY ./dwCheckApi.Persistence/dwCheckApi.Persistence.csproj ./dwCheckApi.Persistence/dwCheckApi.Persistence.csproj
COPY ./dwCheckApi.Tests/dwCheckApi.Tests.csproj ./dwCheckApi.Tests/dwCheckApi.Tests.csproj
COPY ./dwCheckApi/dwCheckApi.csproj ./dwCheckApi/dwCheckApi.csproj
COPY ./dwCheckApi.sln ./dwCheckApi.sln
COPY ./global.json ./global.json
# Restore all packages
RUN dotnet restore --force --no-cache
# Copy the remaining source
COPY ./dwCheckApi.Common/ ./dwCheckApi.Common/
COPY ./dwCheckApi.DAL/ ./dwCheckApi.DAL/
COPY ./dwCheckApi.DTO/ ./dwCheckApi.DTO/
COPY ./dwCheckApi.Entities/ ./dwCheckApi.Entities/
COPY ./dwCheckApi.Persistence/ ./dwCheckApi.Persistence/
COPY ./dwCheckApi.Tests/ ./dwCheckApi.Tests/
COPY ./dwCheckApi/ ./dwCheckApi/
# Build the source code
RUN dotnet build --configuration Release --no-restore
# Install the dotnet ef global tool
## The following was taken from https://itnext.io/database-development-in-docker-with-entity-framework-core-95772714626f
RUN dotnet tool install -g dotnet-ef
ENV PATH $PATH:/root/.dotnet/tools
# Ensure that we generate and migrate the database
WORKDIR ./dwCheckApi.Persistence
RUN dotnet ef database update
# # Run all tests
WORKDIR ./dwCheckApi.Tests
RUN dotnet test --configuration Release --no-build
# Publish application
WORKDIR ../dwCheckApi
RUN dotnet publish dwCheckApi.csproj --configuration Release --no-restore --no-build --output "../dist"
# Copy the created database
WORKDIR ..
RUN cp ./dwCheckApi/dwDatabase.db ./dist/dwDatabase.db
# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:6.0-alpine AS app
WORKDIR /app
COPY --from=build /dist .
ENV ASPNETCORE_URLS http://+:5000
ENTRYPOINT ["dotnet", "dwCheckApi.dll"]