-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathrunNative.sh
77 lines (66 loc) · 2.57 KB
/
runNative.sh
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
#! /bin/sh
#
# runNative.sh <app dll> <sdk version>
# ./runNative /app/app.dll
#
APP_DLL=$1
APP_DIR=$(dirname "$APP_DLL")
DOTNET_VERSION=$(dotnet --info | grep Version | cut -f2 -d":" | xargs)
DOTNET_FRAMEWORK_PATH=/usr/share/dotnet/shared/Microsoft.NETCore.App/$DOTNET_VERSION
#todo: dynamically generate this with dotnet --list-runtimes
ADDITIONAL_PATHS=/usr/share/dotnet/shared/Microsoft.AspNetCore.All/$DOTNET_VERSION:/usr/share/dotnet/shared/Microsoft.AspNetCore.App/$DOTNET_VERSION
# using the shell name to guess the runtime id. can't find a better way to do this
# bash => linux-x64
# ash => linux-musl-x64
if [ -f /bin/bash ]; then
RUNTIME_ID=linux-x64
else
RUNTIME_ID=linux-musl-x64
fi
# get dotnet sdk
echo -- Grabbing netcore sdk $DOTNET_VERSION for runtime $RUNTIME_ID
# alpine containers have wget. standard have curl
if which curl; then
curl -L -o runtime.zip https://www.nuget.org/api/v2/package/runtime.$RUNTIME_ID.Microsoft.NETCore.App/$DOTNET_VERSION
elif which wget; then
wget -O runtime.zip https://www.nuget.org/api/v2/package/runtime.$RUNTIME_ID.Microsoft.NETCore.App/$DOTNET_VERSION
else
echo "Unable to pull runtime"
exit 1
fi
# install unzip if necessary
# alpine containers have unzip. others don't. use apt-get to bring it in.
which unzip || { apt-get update && apt-get install unzip -y; }
mkdir -p ./runtime
unzip runtime.zip -d ./runtime
cp ./runtime/tools/crossgen .
chmod 744 ./crossgen
rm -rf ./runtime
# find libjitclr.so
if [ -f $APP_DIR/libcrljit.so ]; then
JIT_PATH=$APP_DIR/libcrljit.so
elif [ -f $DOTNET_FRAMEWORK_PATH/libclrjit.so ]; then
JIT_PATH=$DOTNET_FRAMEWORK_PATH/libclrjit.so
else
# look in other places? use find?
echo "Unable to find libclrjit.so"
exit 1
fi
# generate native image and perf map
# todo: support netcore dependencies
APP_BASE_NAME=${APP_DLL%.*}
APP_NATIVE_IMAGE=$APP_BASE_NAME.ni.exe
./crossgen /JITPath $JIT_PATH \
/Platform_Assemblies_Paths $DOTNET_FRAMEWORK_PATH:$APP_DIR:$ADDITIONAL_PATHS \
$APP_DLL
./crossgen /Platform_Assemblies_Paths $DOTNET_FRAMEWORK_PATH:$APP_DIR:$ADDITIONAL_PATHS \
/CreatePerfMap /tmp \
$APP_NATIVE_IMAGE
# todo: support self contained builds. this assumes a framework dependent build
cp $APP_BASE_NAME.deps.json $APP_BASE_NAME.ni.deps.json
cp $APP_BASE_NAME.runtimeconfig.json $APP_BASE_NAME.ni.runtimeconfig.json
# required for dynamic tracing from the host machine. the pod must mount /app-profile on the host to
# /app-profile in container
cp -r $APP_DIR/* /app-profile
# run native image
dotnet /app-profile/$(basename $APP_NATIVE_IMAGE)