diff --git a/cookiecutter.json b/cookiecutter.json index b10b73902..dd8d7b1dd 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -13,5 +13,6 @@ "use_celery": "n", "use_maildump": "n", "use_sentry": "n", + "docker": "y", "windows": "n" } diff --git a/{{cookiecutter.repo_name}}/compose/django/entrypoint.sh b/{{cookiecutter.repo_name}}/compose/django/entrypoint.sh index 8c07a6411..9c5073dcf 100644 --- a/{{cookiecutter.repo_name}}/compose/django/entrypoint.sh +++ b/{{cookiecutter.repo_name}}/compose/django/entrypoint.sh @@ -15,4 +15,4 @@ export DATABASE_URL=postgres://$POSTGRES_ENV_POSTGRES_USER:$POSTGRES_ENV_POSTGRE {% if cookiecutter.use_celery == 'y' %} export CELERY_BROKER_URL=$DJANGO_CACHE_URL {% endif %} -exec "$@" \ No newline at end of file +exec "$@" diff --git a/{{cookiecutter.repo_name}}/compose/pycharm/.dockerignore b/{{cookiecutter.repo_name}}/compose/pycharm/.dockerignore new file mode 100644 index 000000000..ea7761d6f --- /dev/null +++ b/{{cookiecutter.repo_name}}/compose/pycharm/.dockerignore @@ -0,0 +1,3 @@ +.git +.gitignore +README.md \ No newline at end of file diff --git a/{{cookiecutter.repo_name}}/compose/pycharm/.gitignore b/{{cookiecutter.repo_name}}/compose/pycharm/.gitignore new file mode 100644 index 000000000..485dee64b --- /dev/null +++ b/{{cookiecutter.repo_name}}/compose/pycharm/.gitignore @@ -0,0 +1 @@ +.idea diff --git a/{{cookiecutter.repo_name}}/compose/pycharm/Dockerfile b/{{cookiecutter.repo_name}}/compose/pycharm/Dockerfile new file mode 100644 index 000000000..a73bbc24f --- /dev/null +++ b/{{cookiecutter.repo_name}}/compose/pycharm/Dockerfile @@ -0,0 +1,22 @@ +FROM {{cookiecutter.repo_name}}_django + +ENV SFTP_USER docker +ENV SFTP_PASS changeme +ENV PASS_ENCRYPTED false + +# Install setuptools, pip and OpenSSH +RUN \ + apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get -y install python-pip python-setuptools python3-pip python3-setuptools openssh-server && \ + rm -rf /var/lib/apt/lists/* + +# sshd needs this directory to run +RUN mkdir -p /var/run/sshd + +# Copy configuration and entrypoint script +COPY sshd_config /etc/ssh/sshd_config +COPY entrypoint / + +EXPOSE 22 + +ENTRYPOINT ["/entrypoint"] diff --git a/{{cookiecutter.repo_name}}/compose/pycharm/README.md b/{{cookiecutter.repo_name}}/compose/pycharm/README.md new file mode 100644 index 000000000..34953ff11 --- /dev/null +++ b/{{cookiecutter.repo_name}}/compose/pycharm/README.md @@ -0,0 +1,58 @@ +docker-pycharm-python [![Docker Build Status](http://hubstatus.container42.com/tehsphinx/docker-pycharm-python)](https://registry.hub.docker.com/u/tehsphinx/docker-pycharm-python/) +==== + +Easy to use and [fig](http://www.fig.sh/index.html) compatible Python development box to be used with [PyCharm (JetBrains)](https://www.jetbrains.com/pycharm/). +This box is NOT meant to be used in production. It comes with SSH/SFTP for PyCharm access. + +For me this was a test to see if docker could be used as a "vagrant replacement" especially when it comes down to +running unit tests and debugging from PyCharm IDE. So far it looks promising... + +Note: SSH/SFTP User and Password implementation is based on [atmoz/sftp](https://registry.hub.docker.com/u/atmoz/sftp), +but changed to use ENV variables for fig support. + +Usage +----- + +Best used with [fig](http://www.fig.sh/index.html). + +Example +-------- + +Dockerfile + +``` +# Pull base image. +FROM tehsphinx/docker-pycharm-python + +# copy application to image +ADD . /data/ +WORKDIR /data + +# If needed: +# install any python requirements found in requirements.txt (this file must be in root path of your app) +RUN pip install -r requirements.txt +``` + +Configuration for fig (fig.yml) + +``` +web: + build: . + command: python app.py + ports: + - "8080:8080" + - "2222:22" + volumes: + - .:/data + environment: + SFTP_USER: docker + SFTP_PASS: docker + links: + - db +db: + image: postgres +``` + +This samples a web server app (app.py) running on port 8080. PyCharm will be able to access the docker image with the +given user and on port 2222. If you do not want to store your password in plain text, you can use the +Environment Variable "PASS_ENCRYPTED: true" to create the user with the already encrypted password. diff --git a/{{cookiecutter.repo_name}}/compose/pycharm/entrypoint b/{{cookiecutter.repo_name}}/compose/pycharm/entrypoint new file mode 100755 index 000000000..63c647bf7 --- /dev/null +++ b/{{cookiecutter.repo_name}}/compose/pycharm/entrypoint @@ -0,0 +1,43 @@ +#!/bin/bash + +# creating user. Default ist user=docker, pass=changeme +# can be changed by setting ENV Variables SFTP_USER, SFTP_PASS +user="${SFTP_USER}" +pass="${SFTP_PASS}" + +if [ "${PASS_ENCRYPTED}" == "true" ]; then + chpasswdOptions="-e" +fi + +useraddOptions="--create-home --shell /bin/bash" + +if [ -n "${USER_UID}" ]; then + useraddOptions="$useraddOptions --non-unique --uid ${USER_UID}" +fi + +if [ -n "${USER_GID}" ]; then + useraddOptions="$useraddOptions --gid ${USER_GID}" + groupadd --gid ${USER_GID} ${USER_GID} +fi + +useradd $useraddOptions $user +chown $user:$user /home/$user +chmod 755 /home/$user + +ln -s /pycharm_helpers/ /home/$user/.pycharm_helpers + +# TODO: get public key authorization to work +mkdir /home/$user/.ssh +chmod 700 /home/$user/.ssh + +if [ -z "$pass" ]; then + pass="$(echo `