Skip to content
This repository was archived by the owner on Aug 5, 2024. It is now read-only.

Commit 383b144

Browse files
committed
Added scripts to fetch/start and stop HELayers labs
1 parent 00aa422 commit 383b144

File tree

2 files changed

+245
-0
lines changed

2 files changed

+245
-0
lines changed

StartHELayers.sh

Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
#!/bin/bash
2+
3+
# MIT License
4+
#
5+
# Copyright (c) 2020 International Business Machines
6+
#
7+
# Permission is hereby granted, free of charge, to any person obtaining a copy
8+
# of this software and associated documentation files (the "Software"), to deal
9+
# in the Software without restriction, including without limitation the rights
10+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
# copies of the Software, and to permit persons to whom the Software is
12+
# furnished to do so, subject to the following conditions:
13+
#
14+
# The above copyright notice and this permission notice shall be included in all
15+
# copies or substantial portions of the Software.
16+
#
17+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
# SOFTWARE.
24+
25+
26+
# This script is intended for those who want to try a pre-built docker container for their toolkit distribution of choice.
27+
# see the script called BuildDockerContainer if you want to build or modify your own instance.
28+
29+
source ConfigConstants.sh
30+
31+
bold=$(tput bold)
32+
normal=$(tput sgr0)
33+
34+
BASEDIR="$PWD"/$(dirname $0)
35+
SCRIPTNAME=$(basename $0)
36+
37+
38+
print_usage(){
39+
cat <<EOF
40+
41+
${bold}Usage: $SCRIPTNAME [options] LAB_TYPE${normal}
42+
43+
${bold}LAB_TYPE${normal} Selects the type of lab to
44+
download the HELayers container from Docker Hub.
45+
Available lab types are:
46+
x86_64/amd64: {lab, python}
47+
s390x: {lab, python}
48+
49+
${bold}OPTIONS:${normal}
50+
-h Displays this help information.
51+
52+
${bold}Examples:${normal}
53+
Obtain the HELayers container with the python lab.
54+
$SCRIPTNAME python
55+
56+
Show this help message.
57+
$SCRIPTNAME -h
58+
59+
60+
EOF
61+
}
62+
63+
# The number of parameters passed to this script
64+
NPARAM=$#
65+
66+
# First we determine which architecture we are running on... AMD64 or s390x
67+
ARCH=`uname -m`
68+
69+
if [[ "$ARCH" == "x86_64" ]] || [[ "$ARCH" == "amd64" ]]; then
70+
#echo "Determined AMD64/x86_64 Architecture"
71+
architecture="AMD64/x86_64"
72+
ARCH="amd64"
73+
elif [[ $ARCH == "s390x" ]]; then
74+
# echo "Determined s390x Architecture"
75+
architecture="s390x"
76+
else
77+
echo " "
78+
echo " FATAL: Aborting. HELayers is not supported on the $ARCH platform."
79+
echo " "
80+
exit -1
81+
fi
82+
83+
#echo "$@"
84+
NPARAM=$#
85+
86+
while getopts ":h" opt; do
87+
case ${opt} in
88+
h ) # Usage
89+
print_usage
90+
exit 0
91+
;;
92+
\? ) # Usage
93+
echo "Fatal: Invalid options"
94+
print_usage
95+
exit -2
96+
;;
97+
: ) # Invalid option. Print usage
98+
echo "Fatal: Invalid option: $OPTARG requires an argument" 1>&2
99+
print_usage
100+
exit -3
101+
esac
102+
done
103+
104+
shift $((OPTIND -1))
105+
#echo "$@"
106+
107+
OPTINDNUMBER=$((OPTIND-1))
108+
109+
if [[ $((NPARAM - OPTINDNUMBER)) -ne 1 ]]; then
110+
echo "Fatal: Options and parameters mismatch or missing parameters. Please check order and number of parameters."
111+
print_usage
112+
exit -4
113+
fi
114+
115+
labtype=$1
116+
if [ $ARCH == "s390x" ]
117+
then
118+
if [[ "$labtype" = "python" ]]
119+
then
120+
imagesuffix="pylab-s390x"
121+
elif [[ "$labtype" = "lab" ]]
122+
then
123+
imagesuffix="lab-s390x"
124+
else
125+
echo "INFO: Lab type: $labtype on $ARCH is not supported on this release."
126+
echo " Please choose a supported lab type for your trials by specifying"
127+
echo " the command: ${bold}$SCRIPTNAME <lab | python>${normal}"
128+
echo " "
129+
exit -1
130+
fi
131+
else
132+
if [ $ARCH == "amd64" ]; then
133+
if [[ "$labtype" = "python" ]]
134+
then
135+
imagesuffix="pylab"
136+
labport="8888"
137+
elif [[ "$labtype" = "lab" ]]
138+
then
139+
imagesuffix="lab"
140+
labport="8443"
141+
else
142+
echo " "
143+
echo " Invalid lab type: $labtype Please specify a valid lab type"
144+
echo " "
145+
print_usage
146+
exit -5
147+
fi
148+
fi
149+
fi
150+
151+
152+
################################################################
153+
# The script has the following arguments:
154+
# $(1): list of tags of the image
155+
if [ $# -gt 0 ]; then
156+
tags=("$@")
157+
fi
158+
159+
# Looks for an environment var named DOCKER_BUILD_FLAGS. If not
160+
# defined, uses the default flag value '--no-cache' for the docker build.
161+
# Ex.: To enable docker caching, export DOCKER_BUILD_FLAGS="" (empty value)
162+
# To then disable docker caching again, unset DOCKER_BUILD_FLAGS
163+
#flags=${DOCKER_BUILD_FLAGS-"--no-cache"}
164+
flags=${DOCKER_BUILD_FLAGS-""}
165+
166+
echo "==============================================================="
167+
echo ""
168+
echo " Phase 1: Downloading dependencies locally"
169+
echo ""
170+
echo " Fetching HELayers (latest) for Linux"
171+
echo " Architecture: $architecture "
172+
echo " Lab: $labtype "
173+
echo ""
174+
echo "==============================================================="
175+
176+
docker pull ibmcom/helayers-$imagesuffix
177+
docker tag ibmcom/helayers-$imagesuffix ibmcom/helayers-$labtype
178+
if [ $? -ne 0 ]; then
179+
echo " "
180+
echo " FATAL: Aborting. There was an issue pulling the image ibmcom/helayers-$imagesuffix "
181+
echo " "
182+
exit -1
183+
fi
184+
185+
docker run -p $labport:$labport -d --rm --name helayers-$labtype ibmcom/helayers-$labtype:latest
186+
if [ $? -ne 0 ]; then
187+
echo " "
188+
echo " FATAL: Aborting. There was an issue running the image ibmcom/helayers-$imagesuffix "
189+
echo " "
190+
exit -1
191+
fi
192+
193+
if [[ "$labtype" = "python" ]]
194+
then
195+
echo " "
196+
echo " Container started. Navigate to: http://127.0.0.1:8888/lab/?token=demo-experience-with-fhe-and-python "
197+
echo " "
198+
elif [[ "$labtype" = "lab" ]]
199+
then
200+
echo " "
201+
echo " Container started. Navigate to: http://127.0.0.1:8443/ "
202+
echo " "
203+
fi
204+
205+
exit 0

StopHELayers.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#/bin/bash
2+
3+
# MIT License
4+
#
5+
# Copyright (c) 2020 International Business Machines
6+
#
7+
# Permission is hereby granted, free of charge, to any person obtaining a copy
8+
# of this software and associated documentation files (the "Software"), to deal
9+
# in the Software without restriction, including without limitation the rights
10+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
# copies of the Software, and to permit persons to whom the Software is
12+
# furnished to do so, subject to the following conditions:
13+
#
14+
# The above copyright notice and this permission notice shall be included in all
15+
# copies or substantial portions of the Software.
16+
#
17+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
# SOFTWARE.
24+
25+
source ConfigConstants.sh
26+
27+
# Retrieve Container ID and Image Name of running toolkit
28+
CONTAINER_ID=$(docker ps -a -q --filter name=helayers --format="{{.ID}}")
29+
IMAGE_NAME=$(docker ps -a -q --filter name=helayers --format="{{.Names}} ({{.Image}})")
30+
31+
if [ -z "$CONTAINER_ID" ]
32+
then
33+
echo "No HELayers Docker Container currently active"
34+
exit 0
35+
else
36+
echo " Stopping Docker Container: $IMAGE_NAME : $CONTAINER_ID ..."
37+
docker rm $(docker stop $CONTAINER_ID) > /dev/null 2>&1
38+
echo " Done"
39+
fi
40+

0 commit comments

Comments
 (0)