Last active
August 29, 2015 14:28
-
-
Save martinrusev/b42be9d46512a761d569 to your computer and use it in GitHub Desktop.
blog/docker-in-production-for-the-average-devops
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Base container | |
RUN apt-get install gcc build-essential git python-dev ... | |
docker build --force-rm=true --rm=true --no-cache -t=yourapp/base . | |
# yourwebapp:latest | |
FROM yourwebapp:base | |
ADD yoursource .... | |
docker build --force-rm=true --rm=true --no-cache -t=yourapp:latest | |
# yourwebapp:1.0 | |
FROM yourwebapp:base | |
ADD yoursource .... | |
docker build --force-rm=true --rm=true --no-cache -t=yourapp:$(VERSION) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from fabric.api import * | |
from fabric.api import run, roles, sudo, local | |
from yourapp import version | |
env.roledefs = { | |
'docker_eu': ['root@127.0.0.1'], | |
'docker_us': ['root@127.0.0.2'] | |
} | |
def eu(): | |
env.hosts = ['docker_eu'] | |
def us(): | |
env.hosts = ['docker_us'] | |
def push_container(): | |
local('docker push username/app:{0}'.format(version)) | |
@roles('docker_eu', 'docker_us') | |
def deploy_container(): | |
sudo('docker pull username/app:{0}'.format(version)) | |
# To run this on different hosts | |
# fab eu run_container | |
# fab us run_container | |
def run_container(): | |
sudo('docker run username/app:{0}') | |
@roles('docker_eu', 'docker_us') | |
def list_images(): | |
sudo('docker images') | |
@roles('docker_eu', 'docker_us') | |
def running_containers(): | |
sudo('docker ps -a') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BUILD=build/package | |
SRC=../ | |
YOUR_APP=~/djangoapp | |
DYNAMIC="sh -c 'get some env variable'" | |
VERSION=`PYTHONPATH=$(SRC) python -c "from amonagent import __version__; print __version__"` | |
install_base: | |
mkdir -p $(BUILD) | |
cp $(YOUR_APP) $(BUILD) | |
@echo $(VERSION) | |
build_container_base: | |
cp $(YOUR_APP)/packaging/docker/Dockerfile.base Dockerfile | |
docker build --force-rm=true --rm=true --no-cache -t=yourapp/base . | |
rm Dockerfile | |
build_container: | |
cp $(YOUR_APP)/packaging/docker/Dockerfile Dockerfile | |
sed -i s/DYNAMIC_VARIABLE/"$(DYNAMIC)"/g Dockerfile | |
docker build --force-rm=true --rm=true --no-cache -t=yourapp:$(VERSION) . | |
rm Dockerfile | |
deploy: | |
docker push yourapp:$(VERSION) | |
# Dockerfile | |
FROM yourapp/base | |
ADD DYNAMIC_VARIABLE var/ | |
...... | |
CMD ["/usr/bin/supervisord"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment