build_docker.sh 2.0 KB
Newer Older
G
gongweibao 已提交
1
#!/bin/bash
L
liaogang 已提交
2
set -xe
L
liaogang 已提交
3

G
gongweibao 已提交
4
cur_path="$(cd "$(dirname "$0")" && pwd -P)"
L
liaogang 已提交
5
cd "$cur_path"/../
G
gongweibao 已提交
6

7 8 9 10 11 12 13 14 15
#paddle production image name
if [ ! -n "$1" ]; then
  paddle_image=paddlepaddle/paddle
else
  paddle_image=$1
fi

#paddle production image tag
if [ ! -n "$2" ]; then
L
liaogang 已提交
16
  paddle_tag=0.10.0
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
else
  paddle_tag=$2
fi

#paddle book image name
if [ ! -n "$3" ]; then
  book_image=paddlepaddle/book
else
  book_image=$3
fi

#paddle book image tag
if [ ! -n "$4" ]; then
  book_tag=latest
else
  book_tag=$4
fi
G
gongweibao 已提交
34 35 36

#generate docker file
if [ ${USE_UBUNTU_REPO_MIRROR} ]; then
G
gongweibao 已提交
37
  update_mirror_cmd="sed 's@http:\/\/archive.ubuntu.com\/ubuntu\/@mirror:\/\/mirrors.ubuntu.com\/mirrors.txt@' -i /etc/apt/sources.list && \\"
G
gongweibao 已提交
38
else
G
gongweibao 已提交
39
  update_mirror_cmd="\\"
G
gongweibao 已提交
40 41
fi

G
gongweibao 已提交
42 43 44
#build docker image
echo "paddle_tag:"$paddle_tag
echo "book_tag:"$book_tag
Y
Yancey1989 已提交
45

G
gongweibao 已提交
46
cat > Dockerfile <<EOF
47
FROM ${paddle_image}:${paddle_tag}
G
gongweibao 已提交
48 49
MAINTAINER PaddlePaddle Authors <paddle-dev@baidu.com>

Y
Yancey1989 已提交
50
COPY . /book
Y
Yu Yang 已提交
51 52
EOF

L
liaogang 已提交
53
if [ -n "${http_proxy}" ]; then
Y
Yu Yang 已提交
54 55 56 57 58
cat >> Dockerfile <<EOF
ENV http_proxy ${http_proxy}
ENV https_proxy ${http_proxy}
EOF
fi
G
gongweibao 已提交
59

Y
Yu Yang 已提交
60
cat >> Dockerfile <<EOF
L
liaogang 已提交
61 62
RUN pip install -U nltk \
    && python /book/.tools/cache_dataset.py
Y
Yancey1989 已提交
63

G
gongweibao 已提交
64
RUN ${update_mirror_cmd}
Y
Yancey1989 已提交
65
    apt-get update && \
L
liaogang 已提交
66
    apt-get install -y locales patch && \
L
liaogang 已提交
67
    apt-get -y install gcc curl git && \
Y
Yancey1989 已提交
68 69
    apt-get -y clean && \
    localedef -f UTF-8 -i en_US en_US.UTF-8 && \
L
liaogang 已提交
70
    pip install --upgrade pip && \
L
liaogang 已提交
71
    pip install -U notedown pillow matplotlib jupyter numpy requests scipy
G
gongweibao 已提交
72

L
liaogang 已提交
73 74 75 76
RUN curl https://storage.googleapis.com/golang/go1.8.linux-amd64.tar.gz -o go1.8.linux-amd64.tar.gz && \
    tar -zxvf go1.8.linux-amd64.tar.gz -C /usr/local/ && \
    rm go1.8.linux-amd64.tar.gz

Y
Yancey1989 已提交
77 78 79
ENV GOROOT /usr/local/go
ENV PATH \${GOROOT}/bin:\${PATH}

L
liaogang 已提交
80
#convert md to ipynb
L
liaogang 已提交
81
RUN /bin/bash /book/.tools/convert-markdown-into-ipynb-and-test.sh
L
liaogang 已提交
82

G
gongweibao 已提交
83
EXPOSE 8888
Y
Yancey1989 已提交
84
CMD ["sh", "-c", "jupyter notebook --ip=0.0.0.0 --no-browser --allow-root --NotebookApp.token='' --NotebookApp.disable_check_xsrf=True /book/"]
Y
Yancey1989 已提交
85
EOF
G
gongweibao 已提交
86

L
liaogang 已提交
87
docker build --no-cache -t ${book_image}:${paddle_tag} -t ${book_image}:${book_tag} .