支持基于docker和非docker的部署

目前对于我的Python项目,我有一个deploy.sh文件,运行一些apt-get的,PIP安装,创build一些目录和复制一些文件….所以这个过程是git克隆我的私人回购,然后运行deploy.sh。

现在我正在玩Docker,基本的问题是,如果dockerfile运行一个git克隆,然后运行deploy.sh,或者dockerfile应该为每个apt-get,pip等自己运行并忽略deploy.sh。 ..这似乎是复制工作(打字),并有可能不同步?

该工作应该在dockerfile中重复。 其原因是利用docker层和caching系统。 以这个例子:

# this will only execute the first time you build the image, all future builds will use a cached layer RUN apt-get update && apt-get install somepackage -y # this will only run pip if your requirements file changes ADD requirements.txt /app/requirements.txt RUN pip install -r requirements.txt ADD . /app/ 

另外,你不应该在docker build中做你的代码的git checkout 。 只需简单地将本地签出的文件添加到上面示例中的图像即可。