NewGaoKaoApi/New_College.Api/Dockerfile

40 lines
1.1 KiB
Docker

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
RUN echo 'Asia/Shanghai' >/etc/timezone
WORKDIR /source
# 设置 Git 凭据为可传递的构建参数
ARG GIT_USERNAME
ARG GIT_PERSONAL_ACCESS_TOKEN
# 更新系统和安装 Git 和证书
RUN apt-get update && apt-get install -y git
# 配置 Git 以进行稀疏检出,使用全局设置
RUN git config --global core.sparseCheckout true
# 初始化 Git 仓库
RUN git init
RUN git remote add origin http://$GIT_USERNAME:$GIT_PERSONAL_ACCESS_TOKEN@nas.jinzejk.com:3000/yly/NewGaoKaoApi.git
# 启用稀疏检出并指定要拉取的目录
#RUN echo "Admin.NET" >> .git/info/sparse-checkout
RUN git pull --depth 1 origin develop
RUN git checkout develop
# 打印 Git 状态和日志以验证代码拉取情况
RUN git status
RUN git log -1
# 进入项目所在目录并恢复和发布项目
WORKDIR /source/new_college.api
RUN dotnet restore
RUN dotnet publish -c release -o /app --no-restore -f net6.0
# 运行镜像
FROM mcr.microsoft.com/dotnet/aspnet:6.0
WORKDIR /app
COPY --from=build /app ./
EXPOSE 8081
ENTRYPOINT ["dotnet", "New_College.Api.dll","-b","0.0.0.0"]