-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
61 lines (50 loc) · 1.75 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
60
61
ARG CSPROJ_PATH="./src/Aiursoft.ChessServer/"
ARG PROJ_NAME="Aiursoft.ChessServer"
# ============================
# Prepare NPM Environment
FROM hub.aiursoft.cn/node:21-alpine AS npm-env
ARG CSPROJ_PATH
WORKDIR /src
COPY . .
# NPM Build at PGK_JSON_PATH
RUN npm install --prefix "${CSPROJ_PATH}wwwroot" --loglevel verbose
# ============================
# Prepare Building Environment
FROM hub.aiursoft.cn/mcr.microsoft.com/dotnet/sdk:8.0 AS build-env
ARG CSPROJ_PATH
ARG PROJ_NAME
WORKDIR /src
COPY --from=npm-env /src .
# Build
RUN dotnet publish ${CSPROJ_PATH}${PROJ_NAME}.csproj --configuration Release --no-self-contained --runtime linux-x64 --output /app
RUN cp -r ${CSPROJ_PATH}/wwwroot/* /app/wwwroot
# ============================
# Prepare Runtime Environment
FROM hub.aiursoft.cn/mcr.microsoft.com/dotnet/aspnet:8.0
ARG PROJ_NAME
WORKDIR /app
COPY --from=build-env /app .
# Install wget and curl
RUN apt update; DEBIAN_FRONTEND=noninteractive apt install -y wget curl
# Edit appsettings.json
RUN sed -i 's/DataSource=app.db/DataSource=\/data\/app.db/g' appsettings.json
RUN sed -i 's/\/tmp\/data/\/data/g' appsettings.json
RUN mkdir -p /data
VOLUME /data
EXPOSE 5000
ENV SRC_SETTINGS=/app/appsettings.json
ENV VOL_SETTINGS=/data/appsettings.json
ENV DLL_NAME=${PROJ_NAME}.dll
#ENTRYPOINT dotnet $DLL_NAME --urls http://*:5000
ENTRYPOINT ["/bin/bash", "-c", "\
if [ ! -f \"$VOL_SETTINGS\" ]; then \
cp $SRC_SETTINGS $VOL_SETTINGS; \
fi && \
if [ -f \"$SRC_SETTINGS\" ]; then \
rm $SRC_SETTINGS; \
fi && \
ln -s $VOL_SETTINGS $SRC_SETTINGS && \
dotnet $DLL_NAME --urls http://*:5000 \
"]
HEALTHCHECK --interval=10s --timeout=3s --start-period=180s --retries=3 CMD \
wget --quiet --tries=1 --spider http://localhost:5000/health || exit 1