Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobi-De committed Jul 30, 2024
2 parents 99b9aa1 + 45b3e14 commit bb6ab9c
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 70 deletions.
4 changes: 2 additions & 2 deletions {{ cookiecutter.project_name }}/.github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
uses: extractions/setup-just@v2

- name: Build
run: just buildwheel
run: just build-wheel

- uses: actions/upload-artifact@v4
with:
Expand Down Expand Up @@ -127,7 +127,7 @@ jobs:
merge-multiple: true

- name: Build binary
run: just buildbin
run: just build-bin

- name: Rename
working-directory: ${{ github.workspace }}
Expand Down
5 changes: 3 additions & 2 deletions {{ cookiecutter.project_name }}/deploy/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ ENV PYTHONUNBUFFERED=1 \
VENV_PATH="/opt/pysetup/.venv" \
S6_KILL_GRACETIME=0 \
S6_OVERLAY_VERSION=3.1.6.2 \
S6_CMD_WAIT_FOR_SERVICES_MAXTIME=0
S6_CMD_WAIT_FOR_SERVICES_MAXTIME=0 \
S6_SYNC_DISKS=1

ENV PATH="$VENV_PATH/bin:$PATH"

Expand Down Expand Up @@ -42,7 +43,7 @@ FROM python-base as production
COPY --from=builder-base /s6-install /
COPY --from=builder-base $VENV_PATH $VENV_PATH
COPY --from=builder-base /app/{{ cookiecutter.project_name }}/staticfiles /app/{{ cookiecutter.project_name }}/staticfiles
COPY deploy/etc /etc
COPY deploy/etc/s6-overlay /etc/s6-overlay
COPY {{ cookiecutter.project_name }} /app/{{ cookiecutter.project_name }}
COPY manage.py /app/manage.py

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/command/with-contenv execlineb

cd /app
foreground { python manage.py createsuperuser --noinput }
python {{ cookiecutter.project_name }}/__main__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/etc/s6-overlay/scripts/db-prepare.sh
/etc/s6-overlay/scripts/setup.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/command/with-contenv execlineb

cd /app
foreground { python manage.py setup_periodic_tasks }
python manage.py qcluster
python {{ cookiecutter.project_name }}/__main__.py qcluster

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/command/with-contenv sh

cd /app
python {{ cookiecutter.project_name }}/__main__.py setup
71 changes: 41 additions & 30 deletions {{ cookiecutter.project_name }}/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ _default:
just cmd pre-commit install --install-hooks
just migrate
just createsuperuser
just lint > /dev/null 2>&1
just lint > /dev/null 2>&1 || true

# Install dependencies
@install *ARGS:
Expand Down Expand Up @@ -127,34 +127,9 @@ docs-upgrade:
just cmd hatch-pip-compile dev --upgrade

# ----------------------------------------------------------------------
# UTILS
# LINTING / FORMATTING
# ----------------------------------------------------------------------

# Build a wheel distribution of the project using hatch
buildwheel:
#!/usr/bin/env sh
export DEBUG="False"
just dj tailwind build
just dj collectstatic --no-input --skip-checks
just dj compress
hatch build
# Build a binary distribution of the project using hatch / pyapp
buildbin:
#!/usr/bin/env sh
current_version=$(hatch version)
wheel_path="${PWD}/dist/{% endraw %}{{ cookiecutter.project_name }}{% raw %}-${current_version}-py3-none-any.whl"
[ -f "$wheel_path" ] || { echo "Wheel file does not exist. Please build the wheel first using the 'buildwheel' recipe."; exit 1; }
export PYAPP_UV_ENABLED="1"
export PYAPP_PYTHON_VERSION="3.12"
export PYAPP_FULL_ISOLATION="1"
export PYAPP_EXPOSE_METADATA="1"
export PYAPP_PROJECT_NAME="{% endraw %}{{ cookiecutter.project_name }}{% raw %}"
export PYAPP_PROJECT_VERSION="${current_version}"
export PYAPP_PROJECT_PATH="${wheel_path}"
export PYAPP_DISTRIBUTION_EMBED="1"
hatch build -t binary
# Run a command within the dev environnment
@cmd *ARGS:
hatch --env dev run {{ ARGS }}
Expand All @@ -171,14 +146,50 @@ buildbin:
@lint:
hatch --env dev run pre-commit run --all-files

# ----------------------------------------------------------------------
# BUILD UTILITIES
# ----------------------------------------------------------------------

# Bump project version and update changelog
bumpver version:
bumpver VERSION:
#!/usr/bin/env sh
just cmd bump-my-version bump {{ version }}
just cmd bump-my-version bump {{ VERSION }}
just cmd git-cliff --output CHANGELOG.md
version = "$(hatch version)"
if [ -z "$(git status --porcelain)" ]; then
echo "No changes to commit."
git push && git push --tags
exit 0
fi

version="$(hatch version)"
git add CHANGELOG.md
git commit -m "Generate changelog for version ${version}"
git tag -f "v${version}"
git push && git push --tags

# Build a wheel distribution of the project using hatch
build-wheel:
#!/usr/bin/env sh
export DEBUG="False"
just dj tailwind build
just dj collectstatic --no-input --skip-checks
just dj compress
hatch build
# Build a binary distribution of the project using hatch / pyapp
build-bin:
#!/usr/bin/env sh
current_version=$(hatch version)
wheel_path="${PWD}/dist/{% endraw %}{{ cookiecutter.project_name }}{% raw %}-${current_version}-py3-none-any.whl"
[ -f "$wheel_path" ] || { echo "Wheel file does not exist. Please build the wheel first using the 'buildwheel' recipe."; exit 1; }
export PYAPP_UV_ENABLED="1"
export PYAPP_PYTHON_VERSION="3.12"
export PYAPP_FULL_ISOLATION="1"
export PYAPP_EXPOSE_METADATA="1"
export PYAPP_PROJECT_NAME="{% endraw %}{{ cookiecutter.project_name }}{% raw %}"
export PYAPP_PROJECT_VERSION="${current_version}"
export PYAPP_PROJECT_PATH="${wheel_path}"
export PYAPP_DISTRIBUTION_EMBED="1"
hatch build -t binary
{% endraw %}
1 change: 1 addition & 0 deletions {{ cookiecutter.project_name }}/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ dependencies = [
"django-watchfiles",
"git-cliff",
"bump-my-version",
"hatch-pip-compile",
]
lock-filename = "requirements-dev.txt"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import multiprocessing
import platform

if platform.system() == "Darwin":
multiprocessing.set_start_method("fork", force=True)
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import os
import sys

from gunicorn.app import wsgiapp


def main() -> None:
from pathlib import Path
import os
import sys

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{ cookiecutter.project_name }}.settings")
current_path = Path(__file__).parent.parent.resolve()
sys.path.append(str(current_path))

run_func = None
if len(sys.argv) > 1:
Expand All @@ -17,6 +17,49 @@ def main() -> None:
run_gunicorn(sys.argv)


def run_setup(_):
"""Run some project setup tasks"""
from django.core.management import execute_from_command_line
from django.core.management.base import CommandError
from contextlib import suppress

execute_from_command_line(["manage", "migrate"])
execute_from_command_line(["manage", "setup_periodic_tasks"])

with suppress(CommandError):
execute_from_command_line(["manage", "createsuperuser", "--noinput", "--traceback"])


def run_gunicorn(argv: list) -> None:
"""
Run gunicorn the wsgi server.
https://docs.gunicorn.org/en/stable/settings.html
https://adamj.eu/tech/2021/12/29/set-up-a-gunicorn-configuration-file-and-test-it/
"""
import multiprocessing
from gunicorn.app import wsgiapp

workers = multiprocessing.cpu_count() * 2 + 1
gunicorn_args = [
"{{ cookiecutter.project_name }}.wsgi:application",
"--bind",
"127.0.0.1:8000",
# "unix:/run/{{ cookiecutter.project_name }}.gunicorn.sock", # uncomment this line and comment the line above to use a socket file
"--max-requests",
"1000",
"--max-requests-jitter",
"50",
"--workers",
str(workers),
"--access-logfile",
"-",
"--error-logfile",
"-",
]
argv.extend(gunicorn_args)
wsgiapp.run()


def run_qcluster(argv: list) -> None:
"""Run Django-q cluster."""
from django.core.management import execute_from_command_line
Expand All @@ -31,15 +74,7 @@ def run_manage(argv: list) -> None:
execute_from_command_line(argv[1:])


def run_gunicorn(argv: list) -> None:
"""Run the web server."""
argv.append("{{ cookiecutter.project_name }}.wsgi:application")
argv.append("--config")
argv.append("gunicorn.conf.py")
wsgiapp.run()


COMMANDS = {"qcluster": run_qcluster, "manage": run_manage}
COMMANDS = {"qcluster": run_qcluster, "manage": run_manage, "setup": run_setup}


if __name__ == "__main__":
Expand Down

This file was deleted.

0 comments on commit bb6ab9c

Please sign in to comment.