build_docker.sh 2.6 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
RUN pip install -U nltk \
62 63 64 65
    && python3 -m pip install --user --upgrade pip==9.0.3 \
    && pip3 install -U nltk \
    && pip3.6 install -U nltk \
    && pip3.7 install -U nltk \
L
liaogang 已提交
66
    && python /book/.tools/cache_dataset.py
Y
Yancey1989 已提交
67

G
gongweibao 已提交
68
RUN ${update_mirror_cmd}
Y
Yancey1989 已提交
69
    apt-get update && \
L
liaogang 已提交
70
    apt-get install -y locales patch && \
Q
qiaolongfei 已提交
71
    apt-get -y install gcc curl git vim && \
Y
Yancey1989 已提交
72 73
    apt-get -y clean && \
    localedef -f UTF-8 -i en_US en_US.UTF-8 && \
74 75 76 77 78 79 80 81 82 83 84
    pip install -U notedown pillow matplotlib jupyter numpy requests scipy && \
    pip3 install -U notedown pillow matplotlib numpy requests scipy && \
    pip3.6 install -U notedown pillow matplotlib numpy requests scipy && \
    pip3.7 install -U notedown pillow matplotlib numpy requests scipy

RUN pip3.6 install ipykernel && \
    pip3.7 install ipykernel && \
    python3.6 -m ipykernel install --name python3.6 && \
    python3.7 -m ipykernel install --name python3.7 && \
    pip3 install ipykernel && \
    python3 -m ipykernel install --name python3
G
gongweibao 已提交
85

L
liaogang 已提交
86 87 88 89
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 已提交
90 91 92
ENV GOROOT /usr/local/go
ENV PATH \${GOROOT}/bin:\${PATH}

L
liaogang 已提交
93
#convert md to ipynb
L
liaogang 已提交
94
RUN /bin/bash /book/.tools/convert-markdown-into-ipynb-and-test.sh
L
liaogang 已提交
95

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

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