Metalstorm
Metalstorm

Reputation: 3232

Supporting docker based and non docker based deployments

Currently for my python project I have a deploy.sh file which runs some apt-get's, pip installs, creates some dirs and copies some files.... so the process is git clone my private repo then run deploy.sh.

Now I'm playing with docker, and the basic question is, should the dockerfile RUN a git clone and then RUN deploy.sh or should the dockerfile have its own RUNs for each apt-get, pip, etc and ignore deploy.sh... which seems like duplicating work (typing) and has the possibility of going out of sync?

Upvotes: 0

Views: 41

Answers (1)

jordanm
jordanm

Reputation: 34934

That work should be duplicated in the dockerfile. The reason for this is to take advantage of docker's layer and caching system. Take this example:

# 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/

Also, you should not do a git checkout of your code in the docker build. Just simply add the files from the local checkout to the images like in the above example.

Upvotes: 1

Related Questions