Skip to content

Commit

Permalink
Initial files.
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamDumpleton committed Mar 15, 2017
0 parents commit 5327cde
Show file tree
Hide file tree
Showing 35 changed files with 849 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.*.swp

*.py[cod]

db.sqlite3
37 changes: 37 additions & 0 deletions .s2i/action_hooks/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

# This is a 'build' action hook script. This script must be executable
# and will be run by the S2I process after the original S2I 'assemble'
# script has been run. This hook is to allow a user to run additional
# build steps which may need the source code or build artefacts in
# place, or to setup any data required for the application.

set -eo pipefail

# Dump out the set of environment variables which were used by the build.

echo " -----> Initial environment variables set by builder image."

env

# Dump out the name of the current working directory.

echo " -----> Current working directory."

pwd

# Run the application specific build steps for this project.

echo " -----> Running collection of Django static resources."

python manage.py collectstatic --noinput

echo " -----> Creating directory for uploaded image files."

mkdir -p media/images && chmod g+w media/images

# Dump out the contents of the current working directory.

echo " -----> Contents of the current working directory after build run."

ls -R .
17 changes: 17 additions & 0 deletions .s2i/action_hooks/build_env
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This is a 'build_env' action hook. This script will be executed inline
# to the custom 'assemble' script and therefore doesn't need to start
# with a '#!' line nor be marked as an executable file. This script will
# be interpreted as if it is a 'bash' script. This script can be used to
# dynamically set additional environment variables required by the build
# process. These might for example be environment variables which
# specify where third party libraries or packages installed from the
# 'pre_build' hook are located and which may be needed when building
# application artefacts. When we source the 'build_env' script, any
# environment variables set by it will be automatically exported.
# Although principally intended for setting environment variables, it
# can include other script logic, but this should be avoided exception
# to the extent it is required to work out what to set any environment
# variables to.

BUILD_OVERRIDE_VALUE=value
BUILD_DEFAULT_VALUE=${BUILD_DEFAULT_VALUE:-default}
39 changes: 39 additions & 0 deletions .s2i/action_hooks/deploy
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

# This is a 'deploy' action hook script. This script must be executable
# and will be run by the S2I process just before the original S2I 'run'
# script is run. This script is to allow a user to run any final steps
# just before the application is to be started. This can include running
# background tasks.

set -eo pipefail

# Dump out the set of environment variables which were used by the build.

echo " -----> Environment variables set for the deployed application."

env

# Dump out the name of the current working directory.

echo " -----> Current working directory."

pwd

# Run the application specific deploy steps for this project.

if [ x"$DATABASE_URL" != x"" ]; then
echo " -----> Running Django database table migrations."

python manage.py migrate --noinput
else
DJANGO_ADMIN_USERNAME=developer \
[email protected] \
DJANGO_ADMIN_PASSWORD=developer `dirname $0`/setup
fi

# Dump out the contents of the current working directory.

echo " -----> Contents of the current working directory after build run."

ls -R .
16 changes: 16 additions & 0 deletions .s2i/action_hooks/deploy_env
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This is a 'deploy_env' action hook. This script will be executed
# inline to the custom 'run' script as well as for any interactive shell
# if so enabled. As it is executed inline, it doesn't need to start with
# a '#!' line nor be marked as an executable file. This script will be
# interpreted as if it is a 'bash' script. This script allows a user to
# dynamically set additional environment variables required by the
# deploy process. These might for example be environment variables which
# tell an application where files it requires are located. When we
# source the 'deploy_env' script, any environment variables set by it
# will be automatically exported. Although principally intended for
# setting environment variables, it can include other script logic, but
# this should be avoided exception to the extent it is required to work
# out what to set any environment variables to.

DEPLOY_OVERRIDE_VALUE=value
DEPLOY_DEFAULT_VALUE=${DEPLOY_DEFAULT_VALUE:-default}
36 changes: 36 additions & 0 deletions .s2i/action_hooks/pre_build
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

# This is a 'pre_build' action hook script. This script must be
# executable and will be run by the S2I process as the very first step.
# This script can be used to install additional third party libraries
# or packages that may be required by the build process. If the
# 'pre_build' hook needs any files from the application source code, it
# must grab them from the '/tmp/src' directory as they will only be
# copied into place by the original S2I 'assemble' script later on in
# the build process.

set -eo pipefail

# Dump out the initial set of environment variables.

echo " -----> Initial environment variables set by builder image."

env

# Dump out the contents of the '/tmp/src' directory.

echo " -----> Initial contents of the /tmp/src directory."

ls -R /tmp/src

# Dump out the name of the current working directory.

echo " -----> Current working directory."

pwd

# Dump out the contents of the current working directory.

echo " -----> Initial contents of the current working directory."

ls -R .
24 changes: 24 additions & 0 deletions .s2i/action_hooks/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

echo " -----> Running Django database table migrations."

python manage.py migrate --noinput

if [ x"$DJANGO_ADMIN_USERNAME" != x"" ]; then
echo " -----> Creating predefined Django super user"
(cat - | python manage.py shell) << !
from django.contrib.auth.models import User;
User.objects.create_superuser('$DJANGO_ADMIN_USERNAME',
'$DJANGO_ADMIN_EMAIL',
'$DJANGO_ADMIN_PASSWORD')
!
else
if (tty > /dev/null 2>&1); then
echo " -----> Running Django super user creation"
python manage.py createsuperuser
fi
fi

echo " -----> Pre-loading Django database with blog posts."

python manage.py loaddata `dirname $0`/../../posts.json
108 changes: 108 additions & 0 deletions .s2i/bin/assemble
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#!/bin/bash

echo " -----> Running application assemble script."

# Ensure we fail fast if there is a problem.

set -eo pipefail

# It is presumed the current working directory is where the application
# code will reside, or at least that this directory is writable and we
# can add our own files for hook scripts there. This would normally be
# the HOME directory for the builder account.

S2I_SOURCE_PATH=`pwd`
export S2I_SOURCE_PATH

# At this point the application source code is still located under the
# directory '/tmp/src'. The source code or application artefacts
# compiled from it will not be moved into place until the original
# 'assemble' script is run. What we will do at this point is move the
# contents of the '.s2i' directory across so that any hook scripts are
# where we need them to be. This shouldn't upset anything as the 's2i'
# program has already extracted out the '.s2i/bin' directory and other
# files it wants separately.

test -d /tmp/src/.s2i && mv /tmp/src/.s2i .

# Now run the 'pre_build' hook from the '.s2i/action_hooks' directory if
# it exists. This hook is to allow a user to install additional third
# party libraries or packages that may be required by the build process.
# If the 'pre_build' hook needs any files from the application source
# code, it must grab them from the '/tmp/src' directory.

if [ -f $S2I_SOURCE_PATH/.s2i/action_hooks/pre_build ]; then
if [ ! -x $S2I_SOURCE_PATH/.s2i/action_hooks/pre_build ]; then
echo "WARNING: Script $S2I_SOURCE_PATH/.s2i/action_hooks/pre_build not executable."
else
echo " -----> Running $S2I_SOURCE_PATH/.s2i/action_hooks/pre_build"
$S2I_SOURCE_PATH/.s2i/action_hooks/pre_build
fi
fi

# Now source the 'build_env' script from the '.s2i/action_hooks'
# directory if it exists. This script allows a user to dynamically set
# additional environment variables required by the build process. These
# might for example be environment variables which specify where third
# party libraries or packages installed form the 'pre_build' hook are
# located and which may be needed when building application artefacts.
# When we source the 'build_env' script, any environment variables set
# by it will be automatically exported.

if [ -f $S2I_SOURCE_PATH/.s2i/action_hooks/build_env ]; then
echo " -----> Running $S2I_SOURCE_PATH/.s2i/action_hooks/build_env"
S2I_SHELL_PWD=$PWD
set -a; . $S2I_SOURCE_PATH/.s2i/action_hooks/build_env; set +a
cd $S2I_SHELL_PWD
fi

# Now run the original 'assemble' script. This will move source code into
# the correct location or otherwise build application artefacts from the
# source code and move that into place.

echo " -----> Running builder assemble script ($S2I_SCRIPTS_PATH/assemble)"

$S2I_SCRIPTS_PATH/assemble

# Now run the 'build' hook from '.s2i/action_hooks' directory if it
# exists. This hook is to allow a user to run additional build steps
# which may need the source code or build artefacts in place, or to
# setup any data required for the application.

if [ -f $S2I_SOURCE_PATH/.s2i/action_hooks/build ]; then
if [ ! -x $S2I_SOURCE_PATH/.s2i/action_hooks/build ]; then
echo "WARNING: Script $S2I_SOURCE_PATH/.s2i/action_hooks/build not executable."
else
echo " -----> Running $S2I_SOURCE_PATH/.s2i/action_hooks/build"
$S2I_SOURCE_PATH/.s2i/action_hooks/build
fi
fi

# Now fix up the shell login environment so it will trigger 'deploy_env'.

if [ x"$S2I_BASH_ENV" != x"" ]; then
if [ -f $S2I_BASH_ENV ]; then
cat >> $S2I_BASH_ENV << EOF
# Now source the 'deploy_env' script from the '.s2i/action_hooks'
# directory if it exists. This script allows a user to dynamically set
# additional environment variables required by the deploy process. These
# might for example be environment variables which tell an application
# where files it requires are located. When we source the 'deploy_env'
# script, any environment variables set by it will be automatically
# exported. Note that we only source the 'deploy_env' script if it
# hasn't already been run.
if [ x"S2I_MARKERS_ENVIRON" != x"" ]; then
S2I_MARKERS_ENVIRON=OK
export S2I_MARKERS_ENVIRON
if [ -f $S2I_SOURCE_PATH/.s2i/action_hooks/deploy_env ]; then
S2I_SHELL_PWD=$PWD
cd $S2I_SOURCE_PATH
set -a; . $S2I_SOURCE_PATH/.s2i/action_hooks/deploy_env; set +a
cd $S2I_SHELL_PWD
fi
fi
EOF
fi
fi
60 changes: 60 additions & 0 deletions .s2i/bin/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash

echo " -----> Running application run script."

# Ensure we fail fast if there is a problem.

set -eo pipefail

# It is presumed the current working directory is where the application
# code will reside, or at least that this directory is writable and we
# can add our own files for hook scripts there. This would normally be
# the HOME directory for the builder account.

S2I_SOURCE_PATH=`pwd`
export S2I_SOURCE_PATH

# Now source the 'deploy_env' script from the '.s2i/action_hooks'
# directory if it exists. This script allows a user to dynamically set
# additional environment variables required by the deploy process. These
# might for example be environment variables which tell an application
# where files it requires are located. When we source the 'deploy_env'
# script, any environment variables set by it will be automatically
# exported. Note that we only source the 'deploy_env' script if it hasn't
# already been run. It could have already been run from the shell login
# environment.

if [ x"S2I_MARKER_ENVIRON" != x"" ]; then
S2I_MARKER_ENVIRON=`date`
export S2I_MARKER_ENVIRON

if [ -f $S2I_SOURCE_PATH/.s2i/action_hooks/deploy_env ]; then
echo " -----> Running $S2I_SOURCE_PATH/.s2i/action_hooks/deploy_env"
S2I_SHELL_PWD=$PWD
set -a; . $S2I_SOURCE_PATH/.s2i/action_hooks/deploy_env; set +a
cd $S2I_SHELL_PWD
fi
fi

# Now run the 'deploy' hook from the '.s2i/action_hooks' directory if it
# exists. This hook is to allow a user to run any final steps just before
# the application is to be started. This can include running background
# tasks.

if [ -f $S2I_SOURCE_PATH/.s2i/action_hooks/deploy ]; then
if [ ! -x $S2I_SOURCE_PATH/.s2i/action_hooks/deploy ]; then
echo "WARNING: Script $S2I_SOURCE_PATH/.s2i/action_hooks/deploy not executable."
else
echo " -----> Running $S2I_SOURCE_PATH/.s2i/action_hooks/deploy"
$S2I_SOURCE_PATH/.s2i/action_hooks/deploy
fi
fi

# Now run the original 'run' script to start up the application. This
# must be run using 'exec' so that the original 'run' script will take
# over process ID 1. This is necessary so that the application will
# receive signals properly.

echo " -----> Running builder run script ($S2I_SCRIPTS_PATH/run)"

exec $S2I_SCRIPTS_PATH/run
4 changes: 4 additions & 0 deletions .s2i/environment
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
S2I_SCRIPTS_PATH=/usr/libexec/s2i
S2I_BASH_ENV=/opt/app-root/etc/scl_enable
DISABLE_COLLECTSTATIC=1
DISABLE_MIGRATE=1
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM centos/python-35-centos7:latest

USER root

COPY . /tmp/src

RUN mv /tmp/src/.s2i/bin /tmp/scripts

RUN rm -rf /tmp/src/.git* && \
chown -R 1001 /tmp/src && \
chgrp -R 0 /tmp/src && \
chmod -R g+w /tmp/src

USER 1001

ENV S2I_SCRIPTS_PATH=/usr/libexec/s2i \
S2I_BASH_ENV=/opt/app-root/etc/scl_enable \
DISABLE_COLLECTSTATIC=1 \
DISABLE_MIGRATE=1

RUN /tmp/scripts/assemble

CMD [ "/tmp/scripts/run" ]
4 changes: 4 additions & 0 deletions app.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

exec python manage.py runmodwsgi --log-to-terminal --port 8080 \
--url-alias /media media
Empty file added blog/__init__.py
Empty file.
4 changes: 4 additions & 0 deletions blog/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from django.contrib import admin
from .models import Post

admin.site.register(Post)
5 changes: 5 additions & 0 deletions blog/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class BlogConfig(AppConfig):
name = 'blog'
Loading

0 comments on commit 5327cde

Please sign in to comment.