Commit 442d214b authored by Omer Zak's avatar Omer Zak

Initial commit.

parents
.git
.gitignore
*.sh
*.txt
tmp*
# Ignore all subdirectories.
*/*
# Shell scripts that we do want to include in the Docker image.
!init_and_run.sh
*~
.docker.uids_gids
*/*
FROM ubuntu:18.04
MAINTAINER Omer Zak "w1@zak.co.il"
# Support building a Django project for deployment to Heroku.
# The pain point that this image is intended to solve:
# In Debian Stretch, we have Python 3.5.
# Heroku wants Python 3.6 (as of 2018-jun-22).
RUN apt-get update && \
# Source: https://stackoverflow.com/questions/44331836/apt-get-install-tzdata-noninteractive
# postgresql depends upon tzdata.
export DEBIAN_FRONTEND=noninteractive && \
apt-get install -y tzdata && \
ln -fs /usr/share/zoneinfo/Greenwich /etc/localtime && \
dpkg-reconfigure --frontend noninteractive tzdata && \
# Our packages
apt-get install -y --no-install-recommends \
python3.6 python3-pip virtualenv \
postgresql libpq-dev \
curl git sudo vim \
# Following is Heroku stuff - needs add-apt-repository etc.
software-properties-common gnupg gnupg-agent && \
curl -L https://cli-assets.heroku.com/apt/release.key | apt-key add - && \
add-apt-repository "deb https://cli-assets.heroku.com/branches/stable/apt ./" && \
apt-get update && \
export DEBIAN_FRONTEND=noninteractive && \
apt-get install -y --no-install-recommends \
heroku && \
# If the user wants to install more packages, he may build a container from this one.
rm -rf /var/lib/apt/lists/*
RUN pip3 install pipenv
ADD .docker.uids_gids /tmp
RUN . /tmp/.docker.uids_gids && \
echo "developer:x:${uid}:${gid}:Developer,,,:/home/developer:/bin/bash" >> /etc/passwd && \
echo "developer:x:${gid}:" >> /etc/group && \
chmod 0660 /etc/sudoers && \
echo "developer ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers && \
chmod 0440 /etc/sudoers
RUN mkdir -p /home/developer
ADD init_and_run.sh /tmp/init_and_run.sh
RUN chown -R developer:developer /home/developer
USER developer
WORKDIR /home/developer
ENV HOME=/home/developer SHELL=/bin/bash
ENV PATH=$PATH:$HOME/bin
VOLUME ["/home/developer"]
EXPOSE 5000
ENTRYPOINT /bin/bash --rcfile /tmp/init_and_run.sh
FROM tddpirate/herokudjango:latest
MAINTAINER Omer Zak "w1@zak.co.il"
# Add the following packages to tddpirate/herokudjango:
# - imagemagick
# - less
RUN sudo apt-get update && \
export DEBIAN_FRONTEND=noninteractive && \
sudo apt-get install -y --no-install-recommends \
imagemagick less && \
sudo rm -rf /var/lib/apt/lists/*
ENTRYPOINT /bin/bash --rcfile /tmp/init_and_run.sh
This diff is collapsed.
# herokudjango
Heroku for Debian Stretch in a Docker container
## What problem does this project solve?
The pain point, which this project seeks to solve, is:
- Heroku needs Python 3.6 to work (as of June 22, 2018).
- Debian Stretch (Debian Stable as of June 22, 2018) and its backports have only Python 3.5.
The solution is to build a Docker image based upon Ubuntu 18.04, which does have Python 3.6.
## How to use the project?
1. We assume that your computer runs Debian Stretch (Debian 9.x) with an up-to-date version of Docker.
2. We assume that your project is in a subdirectory of directory `workdir`
3. Build the Docker images as follows: `./build_herokudjango_image.sh workdir`. Whenever the script prompts you for anything, accept the default values.
4. Now you should have two Docker images:
-- tddpirate/herokudjango which is the basic image.
-- tddpirate/herokudjango_enhanced which includes also some extra Ubuntu packages.
5. The script also starts a container based upon the second Docker image. Your own files are accessed from outside of the container, so you will lose no work when you exit the container.
6. To resume working: `./start_herokudjango.sh workdir`
## I need to install more Ubuntu packages in my image
This is why we have two Docker images. The first image, built using Dockerfile, needs a long time to be built. The second image, built using Dockerfile.2, is based upon the first time and builds quickly.
1. Edit the file Dockerfile.2 by adding more package names to the apt-get install command.
2. Remove the second image by 'docker rmi tddpirate/herokudjango_enhanced`
3. Run `./build_herokudjango_image.sh workdir`
\ No newline at end of file
#!/bin/bash
# Build Docker image and container for running Heroku/Django development
# environment.
#
# Usage: build_herokudjango_image.sh homedirectory [uid gid]
# homedirectory - a directory which will be used as home directory by
# the container.
# uid - optional, the UID of the 'developer' user inside the
# container. Default - same as your UID (usually 1000).
# gid - must be specified together with uid, the GID of the
# 'developer' user inside the container. Default - same
# as your GID (usually 1000).
#
########################################################################
if [ -z $1 ] ; then
echo "You did not specify directory to serve as home directory in the container"
exit 1
fi
HEROKU_HOME_DIRECTORY=$(readlink -f $1)
cd `dirname $0`
# Validate build context
echo "Verifying build context by checking for existence of files"
for file in Dockerfile .dockerignore start_herokudjango.sh ; do
if [ ! -e ${file} ] ; then
echo "${file} was not found"
exit 1
fi
done
# Validate 1st argument - will be the home directory of the 'developer' user inside the container.
if [ ! -d ${HEROKU_HOME_DIRECTORY} ] ; then
echo "You specified a nonexistent directory to serve as home directory in the container"
exit 1
fi
# Optional 2nd argument is the UID of 'developer', default is the same as your UID.
if [ -z $2 ] || [ -z $3 ] ; then
DEV=`whoami`
DEV_UID=`egrep ^$DEV: /etc/passwd|cut -d':' -f3`
DEV_GID=`egrep ^$DEV: /etc/passwd|cut -d':' -f4`
echo "UID and GID were not both specified, will use your UID and GID which are respectively ${DEV_UID} and ${DEV_GID}"
else
DEV_UID=$2
DEV_GID=$3
echo "You specified UID = ${DEV_UID} and GID = ${DEV_GID}"
fi
UIDS_GIDS_SCRIPT=./.docker.uids_gids
echo "export uid=$DEV_UID gid=$DEV_GID" > $UIDS_GIDS_SCRIPT
# Actually build the image
echo "Enter a name for the image:"
read -ei "tddpirate/herokudjango" IMAGE_NAME
docker images --format "{{.Repository}}" | grep -q ${IMAGE_NAME}
STATUS=$?
if [ $STATUS == 0 ]; then
echo "Image ${IMAGE_NAME} exists, will delete and recreate it."
docker rmi --no-prune ${IMAGE_NAME}
fi
docker build -t $IMAGE_NAME .
# Now build 2nd image - which is an enhanced version of the above image.
if [ "$IMAGE_NAME" != "tddpirate/herokudjango" ] ; then
echo "You chose a nondefault image name - no 2nd image for you!"
./start_herokudjango.sh $HEROKU_HOME_DIRECTORY $IMAGE_NAME
else
for file in Dockerfile.2 ; do
if [ ! -e ${file} ] ; then
echo "${file} was not found - no 2nd image will be built"
exit 0
fi
done
echo "Enter a name for the 2nd image:"
read -ei "tddpirate/herokudjango_enhanced" IMAGE2_NAME
docker build -f Dockerfile.2 -t $IMAGE2_NAME .
./start_herokudjango.sh $HEROKU_HOME_DIRECTORY $IMAGE2_NAME
fi
# End of build_herokudjango_image.sh
#!/bin/bash
export LC_ALL=C.UTF-8
export LANG=C.UTF-8
# End of .bashrc for /bin/bash running inside the tddpirate/herokudjango based container.
#!/bin/bash
#
# Running container based upon the image tddpirate/herokudjango
#
# Usage: ./start_herokudjango.sh homedirectory [image_name]
# homedirectory - the directory in which .venv was created.
# image_name - optional, default is tddpirate/herokudjango
########################################################################
# Process command line arguments
if [ -z $1 ] ; then
echo "You did not specify directory to serve as home directory in the container"
exit 1
fi
HEROKU_HOME_DIRECTORY=$(readlink -f $1)
cd `dirname $0`
if [ -z $2 ] ; then
IMAGE_NAME=tddpirate/herokudjango_enhanced
echo "Image name not specified, defaulting to $IMAGE_NAME"
else
IMAGE_NAME=$2
echo "Will run image $IMAGE_NAME"
fi
docker inspect --type=image $IMAGE_NAME > /dev/null
if [ $? != 0 ]; then
echo "*** Image $IMAGE_NAME does not exist ***"
exit 1
else
docker run -ti --rm \
--mount type=bind,source=$HEROKU_HOME_DIRECTORY,target=/home/developer \
-p 5000:5000 \
$IMAGE_NAME
fi
# End of start_herokudjango.sh
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment