Edit Docker files

- Moving folders around
- Setting up docker-compose for Django
This commit is contained in:
Seamus Johnston 2022-08-17 13:26:05 -05:00
parent 4856e28290
commit 3c725ce1ac
No known key found for this signature in database
GPG key ID: 2F21225985069105
2 changed files with 16 additions and 11 deletions

View file

@ -2,8 +2,10 @@ version: "3.0"
services: services:
app: app:
build: . build: .
depends_on:
- db
volumes: volumes:
- ./app:/app - .:/app
links: links:
- db - db
working_dir: /app working_dir: /app
@ -13,19 +15,22 @@ services:
condition: on-failure condition: on-failure
max_attempts: 5 max_attempts: 5
environment: environment:
# Ensure stdout and stderr are sent straight to the terminal without buffering # Send stdout and stderr straight to the terminal without buffering
- PYTHONUNBUFFERED=yup - PYTHONUNBUFFERED=yup
# In case we'd like to know
- RUNNING_IN_DOCKER=yup
# How to connect to Postgre container # How to connect to Postgre container
- DATABASE_URL=postgres://user:feedabee@db/app - DATABASE_URL=postgres://user:feedabee@db/app
# Run in development mode on our local # Tell Django where to find its configuration
- DJANGO_SETTINGS_MODULE=app.settings.dev - DJANGO_SETTINGS_MODULE=registrar.config.settings
# Set a local key for Django
- DJANGO_SECRET_KEY=feedabee
# Run Django in debug mode on local
- DJANGO_DEBUG=True
stdin_open: true stdin_open: true
tty: true tty: true
ports: ports:
- "8000:8000" - "8080:8000"
command: "python" # command: "python"
command: "python manage.py runserver 0.0.0.0:8000"
db: db:
image: postgres:latest image: postgres:latest

View file

@ -11,7 +11,7 @@ container are also owned by the same user on the host system.
import sys import sys
import os import os
import pwd import pwd
import subprocess # nosec import subprocess
HOST_UID = os.stat("/app").st_uid HOST_UID = os.stat("/app").st_uid
HOST_USER = "james" HOST_USER = "james"
@ -41,7 +41,7 @@ if __name__ == "__main__":
username += "0" username += "0"
home_dir = "/home/%s" % username home_dir = "/home/%s" % username
subprocess.check_call( subprocess.check_call(
[ # nosec [
"useradd", "useradd",
"-d", "-d",
home_dir, home_dir,
@ -53,4 +53,4 @@ if __name__ == "__main__":
) )
os.environ["HOME"] = "/home/%s" % pwd.getpwuid(HOST_UID).pw_name os.environ["HOME"] = "/home/%s" % pwd.getpwuid(HOST_UID).pw_name
os.setuid(HOST_UID) os.setuid(HOST_UID)
os.execvp(sys.argv[1], sys.argv[1:]) # nosec os.execvp(sys.argv[1], sys.argv[1:])