Skip to content

Commit

Permalink
Add Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
espenfjo committed Apr 30, 2015
1 parent b28faa9 commit 528daf6
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 12 deletions.
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM python:2.7.9-slim
MAINTAINER [email protected]
ENV LC_ALL C
ENV DEBIAN_FRONTEND noninteractive

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

RUN apt-get update && \
apt-get install -y --no-install-recommends --force-yes git
COPY docker-requirements.txt /usr/src/app/
RUN pip install git+https://github.com/django-nonrel/[email protected]
RUN pip install git+https://github.com/django-nonrel/mongodb-engine.git
RUN pip install pymongo==2.8 docker-py simplejson

COPY . /usr/src/app

EXPOSE 8080
ENTRYPOINT ["./entrypoint.sh"]

10 changes: 3 additions & 7 deletions SpidieFace/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'u8fh97qio4wpeafidj98aiow$q@aifjsd$T%$Y"tyc546SADFCEVTRJOECHXP'
SECRET_KEY = os.environ['SECRET_KEY']

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
Expand Down Expand Up @@ -64,7 +64,8 @@
'default': {
'ENGINE' : 'django_mongodb_engine',
'NAME': 'fjospidie',
'HOST': 'x.x.x.x'
'HOST': os.environ['MONGO_HOST'],
'PORT': os.environ['MONGO_PORT']
}
}
INTERCEPT_REDIRECTS=True
Expand All @@ -75,15 +76,10 @@

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/

Expand Down
3 changes: 3 additions & 0 deletions docker-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
simplejson
pymongo
docker-py
48 changes: 48 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash
set_config() {
key="$1"
value="${*:2}"

sed -ri "s/%$key%/$value/" SpidieFace/settings.py

}

if [ ! -z "$MONGO_HOST" ] && [ ! -z "$MONGO_PORT_27017_TCP_ADDR" ]; then
echo "This FjoSpidie container is linked to a MongoDB Docker container, and given MONGO_HOST environment variable. Using linked MongoDB at $MONGO_PORT_27017_TCP_ADDR:$MONGO_PORT_27017_TCP_PORT"
exit 1
fi
if [ -z "$MONGO_HOST" ] && [ -z "$MONGO_PORT_27017_TCP_ADDR" ]; then
echo "Not linked to a MongoDB container, or 'MONGO_HOST' not given as an environment variable"
exit 1;
fi

if [ -z "$MONGO_PORT" ] && [ -z "$MONGO_PORT_27017_TCP_PORT" ]; then
MONGO_PORT=27017
fi

if [ ! -z "$MONGO_PORT_27017_TCP_ADDR" ]; then
MONGO_HOST=$MONGO_PORT_27017_TCP_ADDR
fi
if [ ! -z "$MONGO_PORT_27017_TCP_PORT" ]; then
MONGO_PORT=$MONGO_PORT_27017_TCP_PORT
fi


NET=$(ip a show dev eth0 |grep -w inet| awk '{print $2}' | sed "s/[0-9]*\/16/0\/16/") # Hack to replace IP with .0 :(
bpf="not ip6 and not net $NET"


pw=$(dd if=/dev/urandom bs=1 count=32 2>/dev/null | base64 -w 0 | rev | cut -b 2- | rev)
export SECRET_KEY=$(dd if=/dev/urandom bs=1 count=62 2>/dev/null | base64 -w 0 | rev | cut -b 2- | rev)
export MONGO_HOST
export MONGO_PORT

echo "from django.contrib.auth.models import User; exit(User.objects.count())" | python manage.py shell
if [ $? == 0 ]; then
echo -e "from django.contrib.auth.models import User; u = User(username='admin');u.set_password(\"$pw\");u.is_superuser = True;u.is_staff = True;u.save()" | python manage.py shell
echo "Admin user/pass is: admin/$pw"
else
echo "User(s) already present in database"
fi

python manage.py runserver 0.0.0.0:8080
5 changes: 0 additions & 5 deletions requirements.txt

This file was deleted.

0 comments on commit 528daf6

Please sign in to comment.