2025-05-14 17:42:10 +08:00
|
|
|
# ===== 第一阶段:构建阶段 =====
|
|
|
|
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
|
|
|
|
2025-05-15 09:09:28 +08:00
|
|
|
# 配置 apt-get 使用 apt-cacher-ng 作为代理
|
|
|
|
RUN echo 'Acquire::http::Proxy "http://192.168.1.140:3142";' > /etc/apt/apt.conf.d/01proxy
|
2025-05-15 08:50:47 +08:00
|
|
|
|
2025-05-15 08:46:52 +08:00
|
|
|
# 配置阿里云镜像源
|
|
|
|
RUN echo "deb http://mirrors.aliyun.com/debian/ bookworm main contrib non-free" > /etc/apt/sources.list && \
|
|
|
|
echo "deb http://mirrors.aliyun.com/debian/ bookworm-updates main contrib non-free" >> /etc/apt/sources.list && \
|
|
|
|
echo "deb http://mirrors.aliyun.com/debian-security/ bookworm-security main contrib non-free" >> /etc/apt/sources.list
|
2025-05-14 17:42:10 +08:00
|
|
|
|
|
|
|
# 允许使用不安全的软件源
|
|
|
|
RUN echo 'Acquire::AllowInsecureRepositories "true";' > /etc/apt/apt.conf.d/99allow-insecure && \
|
|
|
|
echo 'Acquire::AllowDowngradeToInsecureRepositories "true";' >> /etc/apt/apt.conf.d/99allow-insecure
|
|
|
|
|
|
|
|
WORKDIR /src
|
|
|
|
|
|
|
|
# 安装 Fortran 编译器
|
|
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
|
|
gfortran \
|
|
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
# 复制 Fortran 源文件并编译
|
|
|
|
COPY Fortran/*.f90 /src/Fortran/
|
|
|
|
WORKDIR /src/Fortran
|
|
|
|
|
|
|
|
# 编译所有 .f90 文件为 .o 文件
|
|
|
|
RUN for file in *.f90; do gfortran -fPIC -c "$file" -o "${file%.f90}.o"; done
|
|
|
|
|
|
|
|
# 链接所有 .o 文件为共享库
|
|
|
|
RUN gfortran -shared *.o -o libMAIN_UFRN.so
|
|
|
|
|
|
|
|
# 回到主工作目录
|
|
|
|
WORKDIR /src
|
|
|
|
|
|
|
|
# 只复制项目文件
|
|
|
|
COPY ["FortranWebApi.csproj", "./"]
|
|
|
|
RUN dotnet restore
|
|
|
|
|
|
|
|
# 复制源代码
|
|
|
|
COPY . .
|
|
|
|
|
|
|
|
# 合并 build 和 publish 命令
|
|
|
|
RUN dotnet publish -c Release -o /app/publish
|
|
|
|
|
|
|
|
# 复制编译好的 .so 文件到发布目录
|
|
|
|
RUN mkdir -p /app/publish && \
|
|
|
|
cp /src/Fortran/libMAIN_UFRN.so /app/publish/
|
|
|
|
|
|
|
|
# ===== 第二阶段:运行阶段 =====
|
|
|
|
FROM mcr.microsoft.com/dotnet/aspnet:8.0
|
|
|
|
|
2025-05-15 09:09:28 +08:00
|
|
|
# 配置 apt-get 使用 apt-cacher-ng 作为代理
|
|
|
|
RUN echo 'Acquire::http::Proxy "http://192.168.1.140:3142";' > /etc/apt/apt.conf.d/01proxy
|
2025-05-14 17:42:10 +08:00
|
|
|
|
2025-05-15 08:57:13 +08:00
|
|
|
# 配置阿里云镜像源
|
|
|
|
RUN echo "deb http://mirrors.aliyun.com/debian/ bookworm main contrib non-free" > /etc/apt/sources.list && \
|
|
|
|
echo "deb http://mirrors.aliyun.com/debian/ bookworm-updates main contrib non-free" >> /etc/apt/sources.list && \
|
|
|
|
echo "deb http://mirrors.aliyun.com/debian-security/ bookworm-security main contrib non-free" >> /etc/apt/sources.list
|
2025-05-14 17:42:10 +08:00
|
|
|
|
|
|
|
# 允许使用不安全的软件源
|
|
|
|
RUN echo 'Acquire::AllowInsecureRepositories "true";' > /etc/apt/apt.conf.d/99allow-insecure && \
|
|
|
|
echo 'Acquire::AllowDowngradeToInsecureRepositories "true";' >> /etc/apt/apt.conf.d/99allow-insecure
|
|
|
|
|
|
|
|
# 安装运行时依赖
|
|
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
|
|
libc6-dev \
|
|
|
|
libgfortran5 \
|
|
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
WORKDIR /app
|
|
|
|
COPY --from=build /app/publish .
|
|
|
|
|
|
|
|
# 确保 .so 文件的权限正确
|
|
|
|
RUN chmod 755 /app/libMAIN_UFRN.so
|
|
|
|
|
|
|
|
# 设置 LD_LIBRARY_PATH
|
|
|
|
ENV LD_LIBRARY_PATH=/app
|
|
|
|
|
|
|
|
# 设置端口和监听地址
|
|
|
|
ENV ASPNETCORE_URLS=http://+:5000
|
|
|
|
EXPOSE 5000
|
|
|
|
|
|
|
|
ENTRYPOINT ["dotnet", "FortranWebApi.dll"]
|