-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 83a6745
Showing
34 changed files
with
801 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# http://editorconfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_style = space | ||
indent_size = 2 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.py] | ||
indent_size = 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: Build and Deploy Docker Image | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
IMAGE_NAME: ${{ github.repository }} | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Login to Docker Hub | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.TOKEN_GITHUB }} | ||
|
||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
push: true | ||
tags: ${{ env.REGISTRY }}/${{ github.repository }}:latest | ||
|
||
- name: Send POST request to webhook | ||
run: | | ||
curl --fail --retry 3 --max-time 10 -X POST "${{ secrets.DOCKER_WEBHOOK }}" || exit 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
# Django # | ||
*.log | ||
*.pot | ||
*.pyc | ||
__pycache__ | ||
*.sqlite3 | ||
media | ||
staticfiles | ||
|
||
# Backup files # | ||
*.bak | ||
|
||
# Python # | ||
*.py[cod] | ||
*$py.class | ||
|
||
# Distribution / packaging | ||
.Python build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
.pytest_cache/ | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
.hypothesis/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# celery | ||
celerybeat-schedule.* | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
|
||
# sftp configuration file | ||
sftp-config.json | ||
|
||
# Package control specific files Package | ||
Control.last-run | ||
Control.ca-list | ||
Control.ca-bundle | ||
Control.system-ca-bundle | ||
GitHub.sublime-settings | ||
|
||
# Visual Studio Code # | ||
.vscode/* | ||
!.vscode/settings.json | ||
!.vscode/tasks.json | ||
!.vscode/launch.json | ||
!.vscode/extensions.json | ||
.history | ||
|
||
# Macos yuck | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
default_language_version: | ||
python: python3.11 | ||
|
||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.6.0 | ||
hooks: | ||
- id: trailing-whitespace | ||
- id: end-of-file-fixer | ||
- id: check-yaml | ||
- id: check-toml | ||
- id: check-added-large-files | ||
- id: check-case-conflict | ||
- id: check-merge-conflict | ||
- repo: https://github.com/adamchainz/django-upgrade | ||
rev: "1.16.0" # replace with latest tag on GitHub | ||
hooks: | ||
- id: django-upgrade | ||
args: [--target-version, "4.2"] # Replace with Django version | ||
- repo: https://github.com/astral-sh/ruff-pre-commit | ||
# Ruff version. | ||
rev: v0.4.3 | ||
hooks: | ||
- id: ruff | ||
args: [--fix, --exit-non-zero-on-fix] | ||
- repo: https://github.com/thibaudcolas/curlylint | ||
rev: v0.13.1 | ||
hooks: | ||
- id: curlylint | ||
exclude: 'templates/snippets/timetable_search\.html' | ||
- repo: https://github.com/rtts/djhtml | ||
rev: 3.0.6 | ||
hooks: | ||
- id: djhtml | ||
args: | ||
- --tabwidth=2 | ||
- repo: https://github.com/pre-commit/mirrors-prettier | ||
rev: v4.0.0-alpha.8 | ||
hooks: | ||
- id: prettier | ||
types_or: | ||
- css | ||
- xml | ||
additional_dependencies: | ||
- [email protected] | ||
- "@prettier/[email protected]" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
*.min.css | ||
*.min.js | ||
*.svg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"python.testing.pytestArgs": ["."], | ||
"python.testing.unittestEnabled": false, | ||
"python.testing.pytestEnabled": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
FROM python:3.12-slim-bookworm | ||
|
||
RUN apt-get update \ | ||
&& apt-get upgrade -y \ | ||
&& apt-get install -y build-essential curl libpq-dev --no-install-recommends \ | ||
&& rm -rf /var/lib/apt/lists/* /usr/share/doc /usr/share/man \ | ||
&& apt-get clean | ||
|
||
# Keeps Python from generating .pyc files in the container | ||
ENV PYTHONDONTWRITEBYTECODE 1 | ||
|
||
# Turns off buffering for easier container logging | ||
ENV PYTHONUNBUFFERED 1 | ||
|
||
# Install pip requirements | ||
RUN python -m pip install --upgrade pip | ||
COPY requirements.txt /app/requirements.txt | ||
RUN python -m pip install -r /app/requirements.txt | ||
|
||
WORKDIR /app | ||
COPY . /app | ||
RUN mkdir /app/staticfiles | ||
|
||
# Switching to a non-root user | ||
RUN useradd appuser && chown -R appuser /app | ||
USER appuser | ||
|
||
# Expose port 8000 for Gunicorn | ||
EXPOSE 8000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# My Django X | ||
|
||
Inspired by Will Vincent's [DjangoX project](https://github.com/wsvincent/djangox). | ||
|
||
## Features | ||
|
||
- Django 5.0.latest & Python 3.12.latest | ||
- Basic first app called `website` | ||
- Basic template with Bootstrap | ||
- Dockerfile and docker-compose file | ||
- Github Actions workflow to build the Docker file | ||
- Lots of other config inspired by [Adam Johnson's Boost Your Django DX book](https://adamchainz.gumroad.com/l/byddx) | ||
|
||
## Installation | ||
|
||
1. Git clone this repository: `git clone ...` | ||
2. Change directory into the repo: `cd mydjangox` | ||
3. Create a virtual environment: e.g. `uv venv` | ||
4. Activate the virtual environment: `source .venv/bin/activate` | ||
5. Compile the requirements: e.g. `uv pip compile --upgrade requirements.in -o requirements.txt` | ||
6. Install requirements: e.g. `uv pip sync requirements.txt` | ||
7. Run the Django migrations: `python manage.py migrate` | ||
8. Create a superuser: `python manage.py createsuperuser` | ||
9. Start the server: `python manage.py runserver` | ||
10. Navigate to: <http://127.0.0.1:8000> | ||
|
||
## More Configuration | ||
|
||
- Rename `env.template` to `.env` and configure the following settings: | ||
|
||
| Env Name | Env Value | | ||
| ------------------- | -------------------------------------------------------------------------------------------------- | | ||
| SECRET_KEY | The Django secret key to add to the `settings.py` file. | | ||
| DEBUG | Ensure this is set to `False` in production. | | ||
| ALLOWED_HOSTS | List of allowed hosts, e.g. `example.com,www.example.com`. | | ||
| EMAIL_HOST | Name or IP address of the SMTP server. | | ||
| EMAIL_PORT | The port of the SMTP server. | | ||
| EMAIL_HOST_USER | The username to authenticate with the SMTP server. | | ||
| EMAIL_HOST_PASSWORD | The password for the SMTP server username. | | ||
| EMAIL_USE_TLS | Either `True` or `False` to use TLS. | | ||
| DEFAULT_FROM_EMAIL | The email address to send emails from . | | ||
| DB_ENGINE | The database engine to use. | | ||
| DB_NAME | The database name to connect to. If using SQLite, this will be the filename without the extension. | | ||
| DB_HOST | Name or IP address of the database server. | | ||
| DB_PORT | The port of the database server. | | ||
| DB_USER | The username to authenticate with the database server. | | ||
| DB_PASSWORD | The password for the database server username. | | ||
| WHITENOISE_STATIC | Boolean value that turns on Whitenoise for serving static content. | | ||
| ADMIN_URL | The path to the Admin site so it can be hidden from easily being guessed. | | ||
|
||
## Github Action | ||
|
||
- Configure the following repository secrets: | ||
|
||
- `TOKEN_GITHUB`: This should be a personal access token with read and write permissions for the repo. | ||
- `DOCKER_WEBHOOK`: This is a webhook that will be called after the image has been created. Useful for kicking off an automation to restart and re-pull the image. If you don't want to use this, delete the `Send POST request to webhook` action from the workflow in the `docker-image.yml` file. | ||
|
||
- Push to Github `main` branch to kick off the workflow. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""config package.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
"""ASGI config for config project. | ||
It exposes the ASGI callable as a module-level variable named ``application``. | ||
For more information on this file, see | ||
https://docs.djangoproject.com/en/5.0/howto/deployment/asgi/ | ||
""" | ||
|
||
import os | ||
|
||
from django.core.asgi import get_asgi_application | ||
|
||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings") | ||
|
||
application = get_asgi_application() |
Oops, something went wrong.