Skip to content

Dockerize, see: https://github.com/arrobalytics/django-ledger/issues/176 #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
ARG PYTHON_VERSION=3.11.6-slim-bookworm

# define an alias for the specfic python version used in this file.
FROM python:${PYTHON_VERSION} as python

FROM python as python-build-stage

# Install apt packages
RUN apt-get update && apt-get install --no-install-recommends -y \
# dependencies for building Python packages
build-essential

# Requirements are installed here to ensure they will be cached.
COPY ./requirements.txt /

# Create Python Dependency and Sub-Dependency Wheels
RUN pip wheel --wheel-dir /usr/src/app/wheels -r requirements.txt

FROM python as python-run-stage

ARG APP_HOME=/app

ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE 1

WORKDIR ${APP_HOME}

COPY --from=python-build-stage /usr/src/app/wheels /wheels/

# use wheels to install python dependencies
RUN pip install --no-cache-dir --no-index --find-links=/wheels/ /wheels/* \
&& rm -rf /wheels/

COPY ./entrypoint /entrypoint
RUN sed -i 's/\r$//g' /entrypoint && chmod +x /entrypoint

FROM python-run-stage AS backend

# copy application code to WORKDIR
COPY . ${APP_HOME}

ENTRYPOINT ["/entrypoint"]
13 changes: 0 additions & 13 deletions Pipfile

This file was deleted.

168 changes: 0 additions & 168 deletions Pipfile.lock

This file was deleted.

33 changes: 19 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,37 @@
# Instructions

Clone the django starter template & CD into it

```shell
git clone https://github.com/arrobalytics/django-ledger-starter.git && cd django-ledger-starter
```

If pipenv is not installed on your system you may install it
```shell
pip install pipenv
```
If docker and docker-compose are not installed on your system install them, for example on Debian/Ubuntu:

```shell
pipenv install && pipenv shell
sudo apt install docker.io docker-compose
```

Run migrations
```shell
python manage.py migrate
```
Start the services:

Create Django super user and follow the prompts
```shell
python manage.py createsuperuser
docker-compose up
```

Run te server
Then navigate to:

- http://localhost:8000/ledger for django-ledger (login as `root` with password `root`)

- http://localhost:8090/?pgsql=postgres&username=ledger&db=ledger&ns=public (password: `ledger`) to browse the DB with [Adminer](https://www.adminer.org).

You can open a shell into the django container with:

```shell
python manage.py runserver
docker-compose exec django bash
```

Navigate to http://127.0.0.1:8000/ledger
or even execute Django admin commands with:

```shell
docker-compose exec django python3 manage.py check
```
43 changes: 43 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---

version: '3.7'

services:
django:
build:
context: .
dockerfile: ./Dockerfile
image: django_ledger_django
container_name: django_ledger_django
restart: unless-stopped
ports:
- "8000:8000"
init: true
depends_on:
- postgres
environment:
- DATABASE_ENGINE=django.db.backends.postgresql
- DATABASE_HOST=postgres
- DATABASE_NAME=ledger
- DATABASE_USER=ledger
- DATABASE_PASSWORD=ledger
volumes:
- .:/app
postgres:
image: postgres:16.1-bookworm
container_name: django_ledger_postgres
restart: unless-stopped
environment:
- POSTGRES_DB=ledger
- POSTGRES_USER=ledger
- POSTGRES_PASSWORD=ledger
adminer:
image: adminer
container_name: weboll_local_adminer
restart: always
ports:
- 8090:8080
links:
- postgres
depends_on:
- postgres
19 changes: 15 additions & 4 deletions django_ledger_starter/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@
https://docs.djangoproject.com/en/4.2/ref/settings/
"""

import environ

from pathlib import Path

env = environ.Env()


# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

Expand Down Expand Up @@ -77,12 +82,18 @@
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
"default": {
"ENGINE": env("DATABASE_ENGINE"),
"NAME": env("DATABASE_NAME"),
"USER": env("DATABASE_USER"),
"PASSWORD": env("DATABASE_PASSWORD"),
"TEST": {"NAME": env("DATABASE_NAME")},
}
}

if "DATABASE_HOST" in env:
DATABASES["default"]["HOST"] = env("DATABASE_HOST")
if "DATABASE_PORT" in env:
DATABASES["default"]["PORT"] = env("DATABASE_PORT")

# Password validation
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators
Expand Down
16 changes: 16 additions & 0 deletions entrypoint
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

set -o errexit
set -o pipefail
set -o nounset

python3 manage.py migrate --noinput
python3 manage.py shell << END
from django.contrib.auth import get_user_model
UserModel = get_user_model()
if UserModel.objects.filter(is_superuser=True).count() == 0:
UserModel.objects.create_superuser('root', '[email protected]', 'root')
END

>&2 true
python3 manage.py runserver 0:8000
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
Django~=4.2.7
django-ledger>=0.5.5.2
django-ledger>=0.5.5.2
django-environ>=0.11.2
psycopg[binary]>=3.1.14