-
Notifications
You must be signed in to change notification settings - Fork 4
/
Build.dockerfile
170 lines (160 loc) · 5.26 KB
/
Build.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# Build docs
FROM python:3.12-bookworm AS doc-build-env
WORKDIR /app
COPY . ./
RUN cd docs/httpl-docs && pip install -r requirements.txt && python sync.py && mkdocs build && cp -r site /app
# Build UI
FROM node:20 AS gui-build-env
WORKDIR /app
COPY --from=doc-build-env /app/site/. ./docs
COPY . ./
RUN cd gui && rm -rf public/docs && mv ../docs public && npm install && npm run build
# Run .NET unit tests
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS test-env
WORKDIR /app
COPY . ./
RUN cd src && dotnet test
# Build .NET client
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS dotnet-nuget-build-env
WORKDIR /app
COPY . ./
RUN VERSION=$(cat version.txt) && \
ROOT_DIR=/app && \
DIST_DIR=$ROOT_DIR/dist && \
mkdir $DIST_DIR && \
cd $ROOT_DIR/src/HttPlaceholder.Client && \
dotnet pack -c Release \
-o $DIST_DIR \
/p:Version=$VERSION \
/p:AssemblyVersion=$VERSION \
/p:FileVersion=$VERSION
# Create OpenAPI file
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS swagger-build-env
WORKDIR /app
COPY . ./
RUN VERSION=$(cat version.txt) && \
ROOT_DIR=/app && \
DIST_DIR=$ROOT_DIR/dist && \
mkdir $DIST_DIR && \
cd $ROOT_DIR/src/HttPlaceholder.SwaggerGenerator && \
dotnet run -c Release && \
cp bin/Release/net8.0/swagger.json $DIST_DIR
# Build for Linux
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS linux-app-build-env
WORKDIR /app
COPY . ./
COPY --from=gui-build-env /app/gui/dist ./gui-dist
RUN VERSION=$(cat version.txt) && \
ROOT_DIR=/app && \
GUI_DIR=$ROOT_DIR/gui-dist && \
DIST_DIR=$ROOT_DIR/dist && \
DOCS_DIR=$ROOT_DIR/docs && \
cd $ROOT_DIR/src/HttPlaceholder && \
mkdir $DIST_DIR && \
dotnet publish --configuration=release \
--self-contained \
--runtime=linux-x64 \
/p:Version=$VERSION \
/p:AssemblyVersion=$VERSION \
/p:FileVersion=$VERSION \
-o $DIST_DIR && \
rm -rf $DIST_DIR/gui && \
cp -r $GUI_DIR $DIST_DIR/gui && \
cp -r $ROOT_DIR/scripts/buildscript/installscripts/linux/. $DIST_DIR && \
cp -r $DOCS_DIR $DIST_DIR
# Build for Mac OSX
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS mac-app-build-env
WORKDIR /app
COPY . ./
COPY --from=gui-build-env /app/gui/dist ./gui-dist
RUN VERSION=$(cat version.txt) && \
ROOT_DIR=/app && \
GUI_DIR=$ROOT_DIR/gui-dist && \
DIST_DIR=$ROOT_DIR/dist && \
DOCS_DIR=$ROOT_DIR/docs && \
cd $ROOT_DIR/src/HttPlaceholder && \
mkdir $DIST_DIR && \
dotnet publish --configuration=release \
--self-contained \
--runtime=osx-x64 \
/p:Version=$VERSION \
/p:AssemblyVersion=$VERSION \
/p:FileVersion=$VERSION \
-o $DIST_DIR && \
rm -rf $DIST_DIR/gui && \
cp -r $GUI_DIR $DIST_DIR/gui && \
cp -r $ROOT_DIR/scripts/buildscript/installscripts/mac/. $DIST_DIR && \
cp -r $DOCS_DIR $DIST_DIR
# Build for Windows
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS windows-app-build-env
WORKDIR /app
COPY . ./
COPY --from=gui-build-env /app/gui/dist ./gui-dist
RUN VERSION=$(cat version.txt) && \
ROOT_DIR=/app && \
GUI_DIR=$ROOT_DIR/gui-dist && \
DIST_DIR=$ROOT_DIR/dist && \
DOCS_DIR=$ROOT_DIR/docs && \
cd $ROOT_DIR/src/HttPlaceholder && \
mkdir $DIST_DIR && \
dotnet publish --configuration=release \
--self-contained \
--runtime=win-x64 \
/p:Version=$VERSION \
/p:AssemblyVersion=$VERSION \
/p:FileVersion=$VERSION \
-o $DIST_DIR && \
rm -rf $DIST_DIR/gui && \
cp -r $GUI_DIR $DIST_DIR/gui && \
cp -r $ROOT_DIR/scripts/buildscript/installscripts/windows/. $DIST_DIR && \
cp -r $DOCS_DIR $DIST_DIR && \
mv $DIST_DIR/web.config $DIST_DIR/_web.config
# Build tool
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS tool-build-env
WORKDIR /app
COPY . ./
COPY --from=gui-build-env /app/gui/dist ./gui-dist
RUN VERSION=$(cat version.txt) && \
ROOT_DIR=/app && \
GUI_DIR=$ROOT_DIR/gui-dist && \
DIST_DIR=$ROOT_DIR/dist && \
DOCS_DIR=$ROOT_DIR/docs && \
cd $ROOT_DIR/src/HttPlaceholder && \
mkdir $DIST_DIR && \
rm -rf gui && \
cp -r $GUI_DIR ./gui && \
sed -i 's/<PackAsTool>false<\/PackAsTool>/<PackAsTool>true<\/PackAsTool>/' HttPlaceholder.csproj && \
dotnet pack -c Tool \
-o $DIST_DIR \
/p:Version=$VERSION \
/p:AssemblyVersion=$VERSION \
/p:FileVersion=$VERSION
# Pack everything up
FROM ubuntu:22.04
WORKDIR /app
COPY . ./
COPY --from=linux-app-build-env /app/dist ./linux
COPY --from=mac-app-build-env /app/dist ./mac
COPY --from=windows-app-build-env /app/dist ./windows
COPY --from=tool-build-env /app/dist ./tool
COPY --from=dotnet-nuget-build-env /app/dist ./nuget
COPY --from=swagger-build-env /app/dist ./swagger
COPY --from=doc-build-env /app/site/. ./docs
RUN mkdir dist && \
apt update && \
apt install zip -y && \
ROOT_DIR=$(pwd) && \
cd $ROOT_DIR/linux && \
tar -cvzf ../dist/httplaceholder_linux-x64.tar.gz . && \
cd $ROOT_DIR/mac && \
tar -cvzf ../dist/httplaceholder_osx-x64.tar.gz . && \
cd $ROOT_DIR/windows && \
zip -r ../dist/httplaceholder_win-x64.zip . && \
cd $ROOT_DIR/tool && \
cp -r *.nupkg ../dist && \
cd $ROOT_DIR/nuget && \
cp -r *.nupkg ../dist && \
cd $ROOT_DIR/swagger && \
cp swagger.json ../dist && \
cd $ROOT_DIR/docs && \
tar -cvzf ../dist/docs.tar.gz .