Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add script for creating docker images. Refactor handling. #2

Merged
merged 7 commits into from
Apr 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
*.egg-info
.coverage
Dockerfile-*
bin/
!bin/pld-docker-app
docs/modules/palladium.rst
docs/modules/palladium.tests.rst
examples/*/*db
Expand Down
53 changes: 0 additions & 53 deletions addons/docker/palladium_app_image/readme.txt

This file was deleted.

16 changes: 7 additions & 9 deletions addons/docker/palladium_base_image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ FROM continuumio/miniconda3
# File Author / Maintainer
MAINTAINER Palladium

# copy palladium
ADD palladium.tar.gz /root/palladium
RUN conda config --add channels https://conda.binstar.org/ottogroup \
&& conda config --set ssl_verify false \
&& conda update --yes conda

RUN conda config --add channels https://conda.binstar.org/asmeurer \
&& conda config --add channels https://conda.binstar.org/menpo \
&& conda config --set ssl_verify false # please deactivate if not needed
RUN wget --no-check-certificate https://raw.githubusercontent.com/ottogroup/palladium/0.9.1/requirements.txt

RUN conda install --yes --file /root/palladium/requirements.txt

# Install palladium
RUN cd root/palladium && python setup.py install
RUN conda install --yes --file requirements.txt

RUN conda install --no-deps palladium==0.9.1
17 changes: 0 additions & 17 deletions addons/docker/palladium_base_image/create_base.sh

This file was deleted.

92 changes: 67 additions & 25 deletions addons/docker/palladium_app_image/create.sh → bin/pld-dockerize
Original file line number Diff line number Diff line change
@@ -1,14 +1,54 @@
#!/bin/bash
###############################################
# Script to build an Palladium app docker image
# Assumption: palladium_base image available
# Assumption: palladium-base image available
###############################################


# $1 = File location
# $2 = Imagename
# $3 = Baseimagename

# Usage info
usage() {
cat << EOF
Usage: ${0##*/} [-d] PATH_TO_APP BASE_IMAGE_NAME IMAGE_NAME

Create a Docker image for a Palladium application that lives in
PATH_TO_APP. BASE_IMAGE_NAME is the Docker image that we'll base our
image on, while IMAGE_NAME is the name that you want to use for the
Docker container that I'll create.

Example values:
- PATH_TO_APP: .../examples/iris/
- BASE_IMAGE_NAME: ottogroup/palladium-base:0.9.1
- IMAGE_NAME: myname/my-palladium-app:1.0

Options:
-h display this help and exit
-d create the Dockerfile files but do not build them
EOF
}

# Initialize our own variables:
dry_run=0

OPTIND=1
while getopts "hd" opt; do
case "$opt" in
h)
usage
exit 0
;;
d) dry_run=1
;;
'?')
usage >&2
exit 1
;;
esac
done
shift "$((OPTIND-1))" # Shift off the options and optional --.

if [ "$3" = "" ]; then
usage >&2
exit 1
fi

# Copy files into same directory as Dockerfile
tar cvzf app.tar.gz --exclude .git --directory=$1 .
Expand All @@ -30,14 +70,14 @@ fi
# Write Dockerfile
FILE="Dockerfile"

/bin/cat <<EOM >$FILE
/bin/cat <<EOM >$FILE-app
#############################################################
# Dockerfile to build palladium app
# Based on palladium_base image
# Based on palladium-base image
#############################################################

# Set the base image to $3
FROM $3
# Set the base image to $2
FROM $2

# Copy file
# COPY $f /root/palladium/app
Expand All @@ -61,36 +101,37 @@ EOM

# Install dependencies if needed. Look for directory "python_packages"
if [ -f $p\requirements.txt ]; then
echo "RUN conda install --yes --file requirements.txt" >> $FILE
echo "RUN conda install --yes --file requirements.txt" >> $FILE-app
fi

if [ -d $p\python_packages ]; then
FILES=$1python_packages/*
echo "RUN cd python_packages \ " >> $FILE
echo "RUN cd python_packages \ " >> $FILE-app
for f in $FILES
do
f="${f##*python_packages/}"
fname="${f%.tar.gz}"
echo " && tar -xvf $f && rm $f && cd $fname && python setup.py install && cd .. && rm -r $fname \ " >> $FILE
echo " && tar -xvf $f && rm $f && cd $fname && python setup.py install && cd .. && rm -r $fname \ " >> $FILE-app
done
echo " && echo 'Done installing packages' " >> $FILE
echo " && echo 'Done installing packages' " >> $FILE-app
fi

/bin/cat <<EOM >>$FILE
/bin/cat <<EOM >>$FILE-app
# Set PALLADIUM_CONFIG
ENV PALLADIUM_CONFIG /root/palladium/app/config.py
EOM

if [ -f $p\setup.py ]; then
# Install app
echo "RUN python setup.py install" >>$FILE
echo "RUN python setup.py install" >>$FILE-app
fi

# Build image
sudo docker build -t $2 .
if [ "$dry_run" -eq 0 ]; then
sudo docker build -f $FILE-app -t $3 .
rm app.tar.gz
fi

# Remove app folder
rm app.tar.gz



Expand All @@ -100,13 +141,13 @@ rm app.tar.gz
#########################################


/bin/cat <<EOM >$FILE
/bin/cat <<EOM >$FILE-predict
############################################################
# Dockerfile to build palladium with gunicorn autostart
# Based on $2
# Based on $3
############################################################

FROM $2
FROM $3

# File Author / Maintainer
MAINTAINER Palladium
Expand All @@ -123,8 +164,9 @@ EXPOSE 8000

EOM

echo "CMD gunicorn --workers=3 -b" '$'"(ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1'):8000 palladium.server:app" >>$FILE
echo "CMD gunicorn --workers=3 -b" '$'"(ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1'):8000 palladium.server:app" >>$FILE-predict

# Build image
sudo docker build -t ${2%%:*}_predict:${2##*:} .

if [ "$dry_run" -eq 0 ]; then
sudo docker build -f $FILE-predict -t ${3%%:*}-predict:${3##*:} .;
fi
Loading