This repository has been archived by the owner on Oct 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathrun
executable file
·110 lines (91 loc) · 3.32 KB
/
run
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
#!/usr/bin/env bash
# Copyright (c) Microsoft. All rights reserved.
# Note: Windows Bash doesn't support shebang extra params
set -e
# Usage:
# Run the service in the local environment: ./scripts/run
# Run the service inside a Docker container: ./scripts/run -s
# Run the service inside a Docker container: ./scripts/run --in-sandbox
# Run the storage dependency: ./scripts/run --storage
# Show how to use this script: ./scripts/run -h
# Show how to use this script: ./scripts/run --help
# Debug|Release
CONFIGURATION=Release
APP_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )/"
source "$APP_HOME/scripts/.functions.sh"
# Folder where PCS sandboxes cache data. Reuse the same folder to speed up the
# sandbox and to save disk space.
# Use PCS_CACHE="$APP_HOME/.cache" to cache inside the project folder
PCS_CACHE="/tmp/azure/iotpcs/.cache"
help() {
echo "Usage:"
echo " Run the service in the local environment: ./scripts/run"
echo " Run the service inside a Docker container: ./scripts/run -s | --in-sandbox"
echo " Run the storage dependency: ./scripts/run --storage"
echo " Show how to use this script: ./scripts/run -h | --help"
}
setup_sandbox_cache() {
mkdir -p $PCS_CACHE/sandbox/.config
mkdir -p $PCS_CACHE/sandbox/.dotnet
mkdir -p $PCS_CACHE/sandbox/.nuget
echo "Note: caching build files in $PCS_CACHE"
}
run_in_sandbox() {
setup_sandbox_cache
cd $APP_HOME
# In Windows this script should use docker.exe, in which case
# the parameters syntax is different, e.g. volumes path
# (i.e. C:\path\path\... vs /c/path/path/...).
set +e
IS_WINDOWS=$(which cmd.exe)
set -e
if [[ -z "$IS_WINDOWS" ]]; then
check_dependency_docker
./scripts/env-vars-check
docker run -it \
-p 9003:9003 \
-e PCS_IOTHUB_CONNSTRING \
-e PCS_STORAGEADAPTER_WEBSERVICE_URL \
-e PCS_AUTH_REQUIRED \
-e PCS_CORS_WHITELIST \
-e PCS_AUTH_ISSUER \
-e PCS_AUTH_AUDIENCE \
-e PCS_TWIN_READ_WRITE_ENABLED \
-v "$PCS_CACHE/sandbox/.config:/root/.config" \
-v "$PCS_CACHE/sandbox/.dotnet:/root/.dotnet" \
-v "$PCS_CACHE/sandbox/.nuget:/root/.nuget" \
-v "$APP_HOME:/opt/code" \
azureiotpcs/code-builder-dotnet:1.0-dotnetcore /opt/code/scripts/run
else
# Note 'winpty' is required to provide a TTY to Docker
echo "Launching cmd.exe /c winpty ..."
cmd.exe /c "winpty .\scripts\run.cmd --in-sandbox"
fi
}
prepare_for_run() {
check_dependency_dotnet
cd $APP_HOME
./scripts/env-vars-check
dotnet restore --verbosity=quiet
}
run() {
echo "Starting simulation service..."
dotnet run --configuration $CONFIGURATION --project WebService/*.csproj
}
run_storageadapter() {
echo "Starting storage adapter..."
docker run -it -p 9022:9022 \
-e PCS_STORAGEADAPTER_DOCUMENTDB_CONNSTRING \
azureiotpcs/pcs-storage-adapter-dotnet:testing
}
if [[ "$1" == "--help" || "$1" == "-h" ]]; then
help
elif [[ "$1" == "--in-sandbox" || "$1" == "-s" ]]; then
run_in_sandbox
elif [[ "$1" == "" ]]; then
prepare_for_run
run
elif [[ "$1" == "--storage" ]]; then
run_storageadapter
fi
set +e