-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdockerbuild.sh
executable file
·60 lines (54 loc) · 1.75 KB
/
dockerbuild.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
#!/bin/bash
SYSTEM_TYPE=$(uname)
user=`id -n -u`
GID=`id -g`
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
if [ -e "$SCRIPT_DIR/.hub_token" ]; then
TOKEN=`cat "$SCRIPT_DIR/.hub_token"`
else
TOKEN=""
fi
BUILD="latest"
for argwhole in "$@"; do
IFS='=' read -r -a array <<< "$argwhole"
arg="${array[0]}"
val=$(printf "=%s" "${array[@]:1}")
val=${val:1}
case "$arg" in
--hub_token) TOKEN="$val";;
--build) BUILD="$val"
esac
done
if [ "$TOKEN" != "" ]; then
if [ "$TOKEN" != "public" ]; then
echo "$TOKEN" | docker login -u jferlez --password-stdin
if [ $? != 0 ]; then
echo "ERROR: Unable to login to DockerHub using available access token! Quitting..."
exit 1
fi
fi
docker pull jferlez/fastbatllnn-deps:$BUILD
if [ $? != 0 ]; then
echo "ERROR: docker pull command failed! Quitting..."
exit 1
fi
PROCESSING="s/fastbatllnn-deps:local/jferlez\/fastbatllnn-deps:$BUILD/"
cd "$SCRIPT_DIR"
echo "$TOKEN" > .hub_token
else
cd "$SCRIPT_DIR/DockerDeps"
docker build --platform linux/amd64 -t fastbatllnn-deps:local .
PROCESSING="s/fastbatllnn/fastbatllnn/"
fi
cd "$SCRIPT_DIR"
if [ $SYSTEM_TYPE = "Darwin" ];
then
CORES=$(( `sysctl -n hw.ncpu` / 2 ))
PYTHON="python3.10"
else
CORES_PER_SOCKET=`lscpu | grep "Core(s) per socket:" | sed -e 's/[^0-9]//g'`
SOCKETS=`lscpu | grep "Socket(s):" | sed -e 's/[^0-9]//g'`
CORES=$(( $CORES_PER_SOCKET * $SOCKETS ))
PYTHON=""
fi
cat Dockerfile | sed -u -e $PROCESSING | docker build --platform linux/amd64 --no-cache --build-arg USER_NAME=$user --build-arg UID=$UID --build-arg GID=$GID --build-arg CORES=$CORES -t fastbatllnn-run:${user} -f- .