-
Notifications
You must be signed in to change notification settings - Fork 13
/
Dockerfile
74 lines (63 loc) · 2.44 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
62
63
64
65
66
67
68
69
70
71
72
73
74
# 运行时基础镜像
FROM mcr.microsoft.com/dotnet/aspnet:3.1 AS base
WORKDIR /app
# 复制sources.list
COPY sources.list .
# 安装Consul
ENV CONSUL_VERSION=1.4.2
ENV HASHICORP_RELEASES=https://releases.hashicorp.com
RUN set -eux && \
rm -rf /etc/localtime && \
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
mv /etc/apt/sources.list /etc/apt/sources.list.bak && \
mv /app/sources.list /etc/apt/ && \
apt-get update && \
apt-get install -y wget unzip iproute iproute-doc && \
mkdir -p /tmp/build && \
cd /tmp/build && \
apkArch="$(lscpu | grep 'Architecture' | sed -e 's/^Architecture:[[:space:]]*//')" && \
case "${apkArch}" in \
aarch64) consulArch='arm64' ;; \
armhf) consulArch='arm' ;; \
x86) consulArch='386' ;; \
x86_64) consulArch='amd64' ;; \
*) echo >&2 "error: unsupported architecture: ${apkArch} (see ${HASHICORP_RELEASES}/consul/${CONSUL_VERSION}/)" && exit 1 ;; \
esac && \
wget ${HASHICORP_RELEASES}/consul/${CONSUL_VERSION}/consul_${CONSUL_VERSION}_linux_${consulArch}.zip && \
mkdir /app/consul && \
unzip -d /app/consul consul_${CONSUL_VERSION}_linux_${consulArch}.zip && \
ln -s /app/consul/consul /usr/local/bin/consul && \
cd /tmp && \
rm -rf /tmp/build && \
mkdir -p /app/consul/data && \
mkdir -p /app/consul/config && \
chown 777 /app/consul/data && \
consul version
# 编译项目基础镜像
FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
WORKDIR /src
# 复制项目主文件,还原项目依赖项
#COPY Swift/Swift.csproj Swift/
#COPY Swift.Core/Swift.Core.csproj Swift.Core/
#COPY Swift.Management/Swift.Management.csproj Swift.Management/
# 复制所有项目源文件,然后发布项目
COPY . .
RUN dotnet restore Swift/Swift.csproj
RUN dotnet restore Swift.Management/Swift.Management.csproj
FROM build AS publish
WORKDIR /src/Swift
#RUN dotnet build --configuration Release
RUN dotnet publish -c Release -o /app/swift
WORKDIR /src/Swift.Management
RUN dotnet publish -c Release -o /app/management
# 复制发布的项目文件到运行时目录,然后生成镜像
FROM base AS final
WORKDIR /app
COPY --from=publish /app/swift ./swift
COPY --from=publish /app/management ./management
# 开放端口
EXPOSE 8300 8301 8301/udp 8302 8302/udp 9631 9632
# 启动时执行的命令
COPY docker-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
ENTRYPOINT ["docker-entrypoint.sh"]