-
Notifications
You must be signed in to change notification settings - Fork 1
/
dockMe
111 lines (93 loc) · 2.26 KB
/
dockMe
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
111
#!/bin/bash
# get env from env.sh
. env.sh
# Linux docker build
function set_docker {
#
# generate docker file from
# a template
#
OS_=$1
IMAGE_=$2
TAG_=$3
NAME_=$4
USER_=$5
DOCKER_USER_=$6
SUDO_FLAG_=$7
source ~/.bashrc
if [[ -z ${DOCKER_PASSWORD} ]];
then
echo -n "DOCKER_PASSWORD for ${DOCKER_USER_}: "
read -s DOCKER_PASSWORD
fi
touch ~/.bashrc
grep -v 'DOCKER_PASSWORD=' < ~/.bashrc > ~/.bashrc.fwd
echo "DOCKER_PASSWORD=${DOCKER_PASSWORD}" >> ~/.bashrc.fwd
mv ~/.bashrc.fwd ~/.bashrc
TEMPLATE=docker-template/Dockerfile.template
DOCKER_DIR=docker-${OS_}
# subdir for docker
mkdir -p ${DOCKER_DIR}
DOCKERFILE=${DOCKER_DIR}/Dockerfile
DOCKER=${DOCKER_USER_}/${NAME_}:${TAG_}
# escape any slash
#IMAGE_=`echo $IMAGE_|sed 's/\//\\\//g'`
# get the login over with now
docker login -u "${DOCKER_USER_}" -p "${DOCKER_PASSWORD}"
# filter the dockerfile
sed < $TEMPLATE 's/__BASE_IMAGE__/'${IMAGE_}'/g' | \
sed 's/__SUDO__/'${SUDO_FLAG_}'/g' | \
sed 's/__NB_USER__/'${USER_}'/g' > ${DOCKERFILE}
echo "generating docker image in ${DOCKER_DIR} at ${DOCKER}"
docker build --tag ${DOCKER} --file ${DOCKERFILE} .
echo "pushing ${DOCKER}"
docker push ${DOCKER}
}
source env.sh
TAG=${SETUP_DOCER_TAG}
NAME="${SETUP_NAME}"
USER=${SETUP_NB_USER}
DOCKER_USER=${SETUP_DOCKER_USER}
# command line parsing
OS='Linux'
# escape the /
IMAGE='jupyter\/datascience-notebook'
THIS=`basename $0`
POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"
SUDO='-n'
case $key in
-o|--os)
OS="$2"
shift # past argument
shift # past value
;;
-b|--base_image)
IMAGE="$2"
shift # past argument
shift # past value
;;
-s|--sudo)
SUDO=-s
shift # past argument
;;
-n|--no_sudo)
SUDO=-n
shift # past argument
;;
-h|--help)
echo "$THIS [-o|--os 'Linux'] [-b|--base_image 'jupyter\/minimal-notebook']"
echo " [-s|--sudo] | [-n|-no_sudo]']"
echo "for the moment, you need to make sure to escape the / in the base image"
shift # past argument
exit
esac
done
set -- "${POSITIONAL[@]}"
echo "OS: $OS"
echo "base image: $IMAGE"
echo "sudo flag is $SUDO"
set_docker $OS $IMAGE $TAG $NAME $USER $DOCKER_USER $SUDO
echo ${DOCKER_USER}/${NAME}:${TAG}