Skip to content

Commit af9783f

Browse files
authored
ci: full multi-stage docker build (#392)
* ci: full multi-stage docker build * catch build failure * add readme instructions * move dockerfile to root * update readme
1 parent 7eba32c commit af9783f

File tree

3 files changed

+42
-9
lines changed

3 files changed

+42
-9
lines changed

Dockerfile

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM mcr.microsoft.com/dotnet/sdk:5.0-alpine as builder
2+
3+
RUN apk add --no-cache python3 py3-pip
4+
RUN ln -s /usr/bin/python3 /usr/bin/python
5+
6+
COPY src ./src
7+
COPY restler ./restler
8+
COPY build-restler.py .
9+
10+
RUN python3 build-restler.py --dest_dir /build
11+
12+
RUN python3 -m compileall -b /build/engine
13+
14+
FROM mcr.microsoft.com/dotnet/aspnet:5.0-alpine as target
15+
16+
RUN apk add --no-cache python3 py3-pip
17+
RUN ln -s /usr/bin/python3 /usr/bin/python
18+
RUN pip3 install requests applicationinsights
19+
20+
COPY --from=builder /build /RESTler

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ RESTler was designed to run on 64-bit machines with Windows or Linux. Experimen
4040

4141
### **Build instructions**
4242

43+
#### Docker
44+
45+
In the root of this repo, run
46+
47+
```shell
48+
docker build -t restler .
49+
```
50+
51+
#### Local
52+
4353
Prerequisites: Install [Python 3.8.2](https://www.python.org/downloads/) and
4454
[.NET 5.0](https://dotnet.microsoft.com/download/dotnet-core?utm_source=getdotnetcorecli&utm_medium=referral), for your appropriate OS.
4555

build-restler.py

+12-9
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,11 @@ def publish_engine_py(dirs):
116116
try:
117117
copy_python_files(dirs.repository_root_dir, dirs.engine_build_dir)
118118

119-
output = subprocess.run(f'{dirs.python_path} -m compileall {dirs.engine_build_dir}', shell=True, capture_output=True)
120-
if output.stderr:
119+
try:
120+
output = subprocess.run(f'{dirs.python_path} -m compileall {dirs.engine_build_dir}', shell=True, capture_output=True, check=True)
121+
except subprocess.CalledProcessError as e:
121122
print("Build failed!")
122-
print(output.stderr)
123+
print(e.stderr)
123124
sys.exit(-1)
124125

125126
stdout = str(output.stdout)
@@ -163,15 +164,17 @@ def publish_dotnet_apps(dirs, configuration, dotnet_package_source):
163164
restore_args = f"dotnet restore \"{proj_file_path}\" --use-lock-file --locked-mode --force"
164165
if dotnet_package_source is not None:
165166
restore_args = f"{restore_args} -s {dotnet_package_source}"
166-
output = subprocess.run(restore_args, shell=True, stderr=subprocess.PIPE)
167-
if output.stderr:
167+
try:
168+
subprocess.run(restore_args, shell=True, stderr=subprocess.PIPE, check=True)
169+
except subprocess.CalledProcessError as e:
168170
print("Build failed!")
169-
print(str(output.stderr))
171+
print(str(e.stderr))
170172
sys.exit(-1)
171-
output = subprocess.run(f"dotnet publish \"{proj_file_path}\" --no-restore -o \"{proj_output_dir}\" -c {configuration} -f netcoreapp5.0", shell=True, stderr=subprocess.PIPE)
172-
if output.stderr:
173+
try:
174+
subprocess.run(f"dotnet publish \"{proj_file_path}\" --no-restore -o \"{proj_output_dir}\" -c {configuration} -f netcoreapp5.0", shell=True, stderr=subprocess.PIPE, check=True)
175+
except subprocess.CalledProcessError as e:
173176
print("Build failed!")
174-
print(str(output.stderr))
177+
print(str(e.stderr))
175178
sys.exit(-1)
176179

177180
if __name__ == '__main__':

0 commit comments

Comments
 (0)