mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2025-07-31 10:19:54 +03:00
WIP - debug docker container
This commit is contained in:
parent
63753ac078
commit
912aa36505
|
@ -13,5 +13,6 @@
|
|||
"use_celery": "n",
|
||||
"use_maildump": "n",
|
||||
"use_sentry": "n",
|
||||
"docker": "y",
|
||||
"windows": "n"
|
||||
}
|
||||
|
|
|
@ -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 "$@"
|
||||
exec "$@"
|
||||
|
|
3
{{cookiecutter.repo_name}}/compose/pycharm/.dockerignore
Normal file
3
{{cookiecutter.repo_name}}/compose/pycharm/.dockerignore
Normal file
|
@ -0,0 +1,3 @@
|
|||
.git
|
||||
.gitignore
|
||||
README.md
|
1
{{cookiecutter.repo_name}}/compose/pycharm/.gitignore
vendored
Normal file
1
{{cookiecutter.repo_name}}/compose/pycharm/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
.idea
|
22
{{cookiecutter.repo_name}}/compose/pycharm/Dockerfile
Normal file
22
{{cookiecutter.repo_name}}/compose/pycharm/Dockerfile
Normal file
|
@ -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"]
|
58
{{cookiecutter.repo_name}}/compose/pycharm/README.md
Normal file
58
{{cookiecutter.repo_name}}/compose/pycharm/README.md
Normal file
|
@ -0,0 +1,58 @@
|
|||
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.
|
43
{{cookiecutter.repo_name}}/compose/pycharm/entrypoint
Executable file
43
{{cookiecutter.repo_name}}/compose/pycharm/entrypoint
Executable file
|
@ -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 `</dev/urandom tr -dc A-Za-z0-9 | head -c256`)"
|
||||
chpasswdOptions=""
|
||||
fi
|
||||
|
||||
echo "$user:$pass" | chpasswd $chpasswdOptions
|
||||
|
||||
# starting ssh (detached)
|
||||
exec /etc/init.d/ssh start &
|
||||
|
||||
exec "$@"
|
82
{{cookiecutter.repo_name}}/compose/pycharm/sshd_config
Normal file
82
{{cookiecutter.repo_name}}/compose/pycharm/sshd_config
Normal file
|
@ -0,0 +1,82 @@
|
|||
# TODO: this could use some cleanup...
|
||||
|
||||
# der Port auf dem der ssh Server auf Verbindungen "warten" soll
|
||||
Port 22
|
||||
|
||||
# Wenn AllowUsers definiert wurde, dann ist das anmelden auf dem SSH Server nur diesen Usern erlaubt.
|
||||
# Man kann mehrere User angeben. Sie werden dann durch Leerzeichen getrennt.
|
||||
#AllowUsers SystemUsername
|
||||
|
||||
# Mit der aktuellen Version ist nur noch SSH2 erlaubt, aber bei älteren Versionen wäre auch SSH1 möglich.
|
||||
# Mit der Angabe von Protocol 2 beschränkt man es aber auf SSH2.
|
||||
Protocol 2
|
||||
|
||||
# Mit ListenAddress kann man angeben an welchen Interfaces der sshd lauschen soll.
|
||||
# Der Standard 0.0.0.0 lauscht an alles verfügbaren Interfaces.
|
||||
# Man sollte es auf 1 Interface beschränken.
|
||||
ListenAddress 0.0.0.0
|
||||
|
||||
# Der Pfad zum private Key
|
||||
HostKey /etc/ssh/ssh_host_rsa_key
|
||||
HostKey /etc/ssh/ssh_host_dsa_key
|
||||
|
||||
# Logging
|
||||
SyslogFacility AUTH
|
||||
LogLevel INFO
|
||||
|
||||
# Wenn aktiviert, dann wird eine eingehende Verbindung vom Hauptprozess getrennt.
|
||||
# Außerdem läuft sie dann unter den Rechten das angemeldeten Users.
|
||||
# Default ist yes und so sollte es auch bleiben.
|
||||
UsePrivilegeSeparation yes
|
||||
|
||||
# Nach den hier angegebenen Sekunden wird die Verbindung getrennt
|
||||
# wenn der User sich nicht erfolgreich angemeldet hat
|
||||
LoginGraceTime 120
|
||||
|
||||
# Mit PermitRootLogin kann man dem User root verbieten sich per SSH anzumelden.
|
||||
# Auch das ist eine Sicherheitseinstellung die Bruteforce Attacken auf den root User verhindern soll.
|
||||
# no = keine Rootanmeldung per SSH erlaubt | yes = root kann sich anmelden
|
||||
PermitRootLogin no
|
||||
|
||||
# Überprüft die Besitzrechte der Userdateien und des Homedirs bevor sich ein User anmelden kann
|
||||
StrictModes yes
|
||||
|
||||
# Erlaubt Public Key Authentification
|
||||
# Default ist yes, wenn man es nicht benutzt kann man es auch abschalten
|
||||
PubkeyAuthentication no
|
||||
|
||||
# Erlaubt die Anmeldung mit Passwörtern. Bevor man dies abschaltet, sollte man einen anderen Weg haben!
|
||||
PasswordAuthentication yes
|
||||
|
||||
# Da es nur Protocol Version 1 betrifft ist es nicht wichtig zu setzen.
|
||||
# Am besten man setzt es trotzdem, aber dann auf no!
|
||||
RSAAuthentication no
|
||||
|
||||
# Es sollen keine ~/.rhosts und ~/.shosts Dateien im Homedir geladen werden
|
||||
IgnoreRhosts yes
|
||||
|
||||
# Auch ein Überbleibsel von SSH1. No ist richtig!
|
||||
RhostsRSAAuthentication no
|
||||
|
||||
# Eine vergleichbare Funktion von RhostsRSAAuthentication, aber für SSH2.
|
||||
# Hab ich noch nie gebraucht.
|
||||
HostbasedAuthentication no
|
||||
|
||||
# Wenn man es auch yes setzt, kann man sich mit leeren Passwörtern anmelden.
|
||||
# Da sagt der gesunde Menschenverstand schon etwas anderes.
|
||||
PermitEmptyPasswords no
|
||||
|
||||
# Ist ein Brutforce Schutz, der die maximalen unautorisierten Verbindungen steuert.
|
||||
MaxStartups 10:30:60
|
||||
|
||||
# Aktiviert das Subsystem sftp
|
||||
#Subsystem sftp /usr/lib/openssh/sftp-server
|
||||
Subsystem sftp internal-sftp
|
||||
|
||||
# Wenn man dies auf yes setzt wird einem User die /etc/motd angezeigt wenn er sich verbindet.
|
||||
PrintMotd no
|
||||
|
||||
# Diese Settings sollten selbsterklärend sein.
|
||||
KeepAlive yes
|
||||
PrintLastLog yes
|
||||
UsePAM yes
|
|
@ -99,7 +99,11 @@ MANAGERS = ADMINS
|
|||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#databases
|
||||
DATABASES = {
|
||||
# Raises ImproperlyConfigured exception if DATABASE_URL not in os.environ
|
||||
{% if cookiecutter.docker == 'y' %}
|
||||
'default': 'postgres://postgres@postgres/postgres'),
|
||||
{% else %}
|
||||
'default': env.db("DATABASE_URL", default="postgres://{% if cookiecutter.windows == 'y' %}localhost{% endif %}/{{cookiecutter.repo_name}}"),
|
||||
{% endif %}
|
||||
}
|
||||
DATABASES['default']['ATOMIC_REQUESTS'] = True
|
||||
|
||||
|
|
19
{{cookiecutter.repo_name}}/debug.yml
Normal file
19
{{cookiecutter.repo_name}}/debug.yml
Normal file
|
@ -0,0 +1,19 @@
|
|||
postgres:
|
||||
extends:
|
||||
file: dev.yml
|
||||
service: postgres
|
||||
|
||||
debug:
|
||||
build: compose/pycharm/
|
||||
command: python -c "import signal; signal.pause()"
|
||||
ports:
|
||||
- "8000:8000"
|
||||
- "2222:22"
|
||||
volumes:
|
||||
- .:/app
|
||||
- /data/{{cookiecutter.repo_name}}/pycharm_helpers:/pycharm_helpers/
|
||||
environment:
|
||||
SFTP_USER: docker
|
||||
SFTP_PASS: docker
|
||||
links:
|
||||
- postgres
|
Loading…
Reference in New Issue
Block a user