一、环境准备
本次打算使用”tutor”的 “release/hawthorn”的分支,在使用的过程中发现该分支需要使用”python3.6″的版本,因此先在Ubuntu16.04安装python3.6,安装过程不再描述。安装后使用virtualenv创建虚拟环境,创建并激活虚拟环境后用源码的方式安装”tutor”,下载并安装tutor的过程如下:
git clone https://github.com/overhangio/tutor.git –branch release/hawthorn –depth 1
cd tutor
pip install -e .
二、开始构建镜像
构建镜像使用tutor的命令即可,命令如下:
tutor images build openedx #第一次执行该命令会提示输入域名信息
运行命令完成后会在”~/.local/share/tutor/env/build/”目录中创建几个目录,这些目录按项目组织,每个目录含有Dockerfile和一些配置,目录结构如下:
tree ~/.local/share/tutor/env/build/
├── android
│ ├── Dockerfile
│ └── edx.properties
├── forum
│ └── Dockerfile
├── notes
│ └── Dockerfile
├── openedx
│ ├── bin
│ │ ├── docker-entrypoint.sh
│ │ └── openedx-assets
│ ├── Dockerfile
│ ├── requirements
│ │ └── private.txt
│ ├── settings
│ │ ├── cms
│ │ │ ├── assets.py
│ │ │ └── __init__.py
│ │ └── lms
│ │ ├── assets.py
│ │ └── __init__.py
│ └── themes
│ └── README
└── xqueue
└── Dockerfile
其中执行”tutor images build openedx”会调用openedx目录下的Dockerfile文件,可以修改该文件中设计到镜像的配置,用来加速安装过程。文件内容和修改部分如下:
FROM ubuntu:16.04
MAINTAINER Régis Behmo <regis@behmo.com>
############ common to lms & cms
RUN sed -i s/archive.ubuntu.com/mirrors.aliyun.com/g /etc/apt/sources.list #使用国内的apt源
RUN sed -i s/security.ubuntu.com/mirrors.aliyun.com/g /etc/apt/sources.list #使用国内的apt源
# Install system requirements
RUN apt update && \
# Global requirements
apt install -y language-pack-en git python-virtualenv build-essential software-properties-common curl git-core libxml2-dev libxslt1-dev python-virtualenv libmysqlclient-dev python-apt python-dev libxmlsec1-dev libfreetype6-dev swig gcc g++ \
# openedx requirements
gettext gfortran graphviz graphviz-dev libffi-dev libfreetype6-dev libgeos-dev libjpeg8-dev liblapack-dev libpng12-dev libsqlite3-dev libxml2-dev libxmlsec1-dev libxslt1-dev lynx nodejs npm ntp pkg-config \
# Our requirements
mysql-client \
&& rm -rf /var/lib/apt/lists/*
# Dockerize will be useful to wait for mysql DB availability
ARG DOCKERIZE_VERSION=v0.6.1
RUN curl -L -o /tmp/dockerize.tar.gz http://software-qiniu.heyuantao.cn/tutor/dockerize-linux-amd64-v0.6.1.tar.gz \
&& tar -C /usr/local/bin -xzvf /tmp/dockerize.tar.gz \
&& rm /tmp/dockerize.tar.gz
## Checkout edx-platform code
ARG EDX_PLATFORM_REPOSITORY=https://github.com/edx/edx-platform.git
ARG EDX_PLATFORM_VERSION=open-release/hawthorn.2
RUN mkdir -p /openedx/edx-platform && \
git clone $EDX_PLATFORM_REPOSITORY –branch $EDX_PLATFORM_VERSION –depth 1 /openedx/edx-platform
WORKDIR /openedx/edx-platform
# Download extra locales to /openedx/locale
RUN cd /tmp \
&& curl -L -o openedx-i18n.tar.gz https://github.com/regisb/openedx-i18n/archive/hawthorn.tar.gz \
&& tar xzf /tmp/openedx-i18n.tar.gz \
&& mv openedx-i18n-hawthorn/edx-platform/locale/ /openedx/locale/ \
&& rm -rf openedx-i18n*
# Install python requirements (clone source repos in a separate dir, otherwise
# they will be overwritten when we mount edx-platform)
ENV NO_PYTHON_UNINSTALL 1
RUN virtualenv /openedx/venv
ENV PATH /openedx/venv/bin:${PATH}
ENV VIRTUAL_ENV /openedx/venv/
RUN pip install setuptools==39.0.1 pip==9.0.3
##fix something can not install
##下面的一行命令安装pystach_custom包,这个安装过程本应在”requirements/edx/development.txt”进行,但发现该软件安装过程存在bug,必须连续两次安装才能成功(第一次会失败)
RUN pip install -e git+https://github.com/dementrock/pystache_custom.git@776973740bdaad83a3b029f96e415a7d1e8bec2f#egg=pystache_custom-dev -i https://pypi.douban.com/simple || pip install -e git+https://github.com/dementrock/pystache_custom.git@776973740bdaad83a3b029f96e415a7d1e8bec2f#egg=pystache_custom-dev -i https://pypi.douban.com/simple
RUN pip install -r requirements/edx/development.txt -i https://pypi.douban.com/simple
# Install patched version of ora2
RUN pip uninstall -y ora2 && \
pip install git+https://github.com/regisb/edx-ora2.git@open-release/hawthorn.2#egg=ora2==2.1.17
# Install a recent version of nodejs
RUN nodeenv /openedx/nodeenv –node=8.9.3 –prebuilt
ENV PATH /openedx/nodeenv/bin:${PATH}
# Install nodejs requirements
RUN npm set progress=false \
&& npm install –registry https://registry.npm.taobao.org #使用国内的npm镜像
ENV PATH ./node_modules/.bin:${PATH}
# Install private requirements: this is useful for installing custom xblocks.
COPY ./requirements/ /openedx/requirements
RUN pip install -r /openedx/requirements/private.txt -i https://pypi.douban.com/simple
# Create folder that will store *.env.json and *.auth.json files, as well as
# the tutor-specific settings files.
RUN mkdir -p /openedx/config ./lms/envs/tutor ./cms/envs/tutor
ENV CONFIG_ROOT /openedx/config
COPY settings/lms/*.py ./lms/envs/tutor/
COPY settings/cms/*.py ./cms/envs/tutor/
# Copy scripts
COPY ./bin /openedx/bin
ENV PATH /openedx/bin:${PATH}
# Collect production assets. By default, only assets from the default theme
# will be processed. This makes the docker image lighter and faster to build.
# Only the custom themes added to /openedx/themes will be compiled.
# Here, we don’t run “paver update_assets” which is slow, compiles all themes
# and requires a complex settings file. Instead, we decompose the commands
# and run each one individually to collect the production static assets to
# /openedx/staticfiles.
RUN openedx-assets xmodule \
&& openedx-assets npm \
&& openedx-assets webpack –env=prod \
&& openedx-assets common
COPY ./themes/ /openedx/themes/
RUN openedx-assets themes \
&& openedx-assets collect –settings=tutor.assets
# service variant is “lms” or “cms”
ENV SERVICE_VARIANT lms
ENV SETTINGS tutor.production
# Entrypoint will fix permissions of all files and run commands as openedx
ENTRYPOINT [“docker-entrypoint.sh”]
# Run server
EXPOSE 8000
CMD gunicorn –name ${SERVICE_VARIANT} –bind=0.0.0.0:8000 –max-requests=1000 ${SERVICE_VARIANT}.wsgi:application
在安装的过程中,部分python库是用pip在github上安装的,但有一个安装一直失败,对其在命令行下进行安装,发现该软件每次都在第二次才能安装成功,第一次总是失败。因此采用执行多条命令的”||”运算符来解决,同时将该命令行单独在Dockerfile进行处理,在Dockerfile的关键行修改内容如下:
RUN pip install -e git+https://github.com/dementrock/pystache_custom.git@776973740bdaad83a3b029f96e415a7d1e8bec2f#egg=pystache_custom-dev -i https://pypi.douban.com/simple || pip install -e git+https://github.com/dementrock/pystache_custom.git@776973740bdaad83a3b029f96e415a7d1e8bec2f#egg=pystache_custom-dev -i https://pypi.douban.com/simple
#该命令加在有pip install -r xxx 命令行之前,因为该命令行总是二次才能执行成功,所以只能这么写
在安装的过程中还会在nodeenv的安装会卡下,如果长时间没反应中断该过程重新试下就过去了。最终生成了regis/openedx:hawthorn这个镜像,大小为2.96GB。
当前用的tutor版本不是较新的版本,后续打算使用3.12.X的版本来构建镜像。
参考资料:
1、edx-platform代码下载的命令:
git clone https://github.com/edx/edx-platform.git –branch open-release/hawthorn.2 –depth 1 /openedx/edx-platform