Skip to content
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

The 2nd Great Homebrew Project #464

Merged
merged 24 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
fd3b5c4
adding setup info
Aug 26, 2024
cefe7f0
The start of the great homebrew project
AdmiralGT Oct 7, 2024
384fbd4
Initial site breakdown
AdmiralGT Oct 7, 2024
b490f3a
Commonizing some elements and separating out some homebrew specific e…
AdmiralGT Oct 8, 2024
bcc033a
Rework models and tables to separate homebrew from clocktower scripts
AdmiralGT Oct 15, 2024
97881db
Reworking characters and character types
AdmiralGT Oct 16, 2024
558e562
Update migrations
AdmiralGT Oct 16, 2024
3d16620
Pausing while determine the best way to separate homebrew content
AdmiralGT Oct 16, 2024
8752a5d
Don't separate out the sites, just have them in the same site
AdmiralGT Oct 16, 2024
04c6f24
Uploading of homebrew and hybrid scripts now works correctly
AdmiralGT Oct 18, 2024
7665b6c
Remove unused loaders file
AdmiralGT Oct 18, 2024
57dcfca
I think hybrid/homebrew support is ready
AdmiralGT Oct 31, 2024
c9bb5e2
Add some additional tests
AdmiralGT Oct 31, 2024
d3eff6f
Merge commit 'c9bb5e2' into grt/homebrew2
AdmiralGT Oct 31, 2024
77bc6f7
Fix merge
AdmiralGT Oct 31, 2024
04bbe5e
Merge remote-tracking branch 'bjageman/readme-update-setup' into grt/…
AdmiralGT Oct 31, 2024
38c288f
Add dev instructions
AdmiralGT Nov 1, 2024
cffb495
Dependency updates
AdmiralGT Nov 1, 2024
d341998
Use ruff for linting
AdmiralGT Nov 1, 2024
a711a4f
Add instructions for ruff
AdmiralGT Nov 1, 2024
9fc2a73
Update lock file
AdmiralGT Nov 1, 2024
1b665cb
Remove unused file
AdmiralGT Nov 1, 2024
15150aa
Meet more schema restrictions
AdmiralGT Nov 1, 2024
02dd119
More schema restrictions
AdmiralGT Nov 1, 2024
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
32 changes: 32 additions & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Linter

on:
pull_request:

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Set up python
id: setup-python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install Poetry
uses: snok/install-poetry@v1
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v4
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root
- name: Install project
run: poetry install --no-interaction
- name: Run tests
run: |
poetry run ruff check
107 changes: 107 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Local Development

## Database

The site uses PostgreSQL as the backend database. The mimimum PostgreSQL version required in v13. The PostgreSQL database must have the `postgresql-contrib` debian installed. It is recommended that you use [docker compose](./dev/docker-compose.yml) to spin up the [attached Dockerfile](./dev/Dockerfile) as your PostgreSQL database.

In order to test the "Name" and "Author" search fields, you must apply the following migration to your database once it has been deployed.

```python
from django.contrib.postgres.operations import TrigramExtension
from django.db import migrations

class Migration(migrations.Migration):
operations = [
TrigramExtension()
]
```

## Python environment

This project uses `poetry` to manage python dependencies. Follow the [Poetry installation instructions](https://python-poetry.org/docs/#installation) to install poetry.

Note: Users have reported getting stuck in the install, running `export PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring` may fix this.

You can then install python environment using `poetry install`

### Creating the Config

By default, `manage.py` looks for the file `botc/local.py`. You must create a `botc/local.py` with the following content:

```python
from .settings import *

DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": "postgres",
"HOST": "localhost",
"USER": "postgres@db",
"PASSWORD": "postgres",
}
}

SECRET_KEY = "<random_string>"

STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")
BS_ICONS_CACHE = os.path.join(STATIC_ROOT, "icon_cache")
DEBUG = True

INTERNAL_IPS = [
"127.0.0.1",
"localhost",
]

```

Be sure to choose your own random string for the `SECRET_KEY`. [You can generate one here](https://randomkeygen.com/).

If you are not using the docker compose PostgreSQL database then you'll need to configure the `DATABASES` entry above with your own credentials.

## Running and Migration

Per the usual Django development instructions, you need to apply the migrations to the database before running, create the static files and admin account. Run

1. `poetry run python manage.py migrate`
1. `poetry run python manage.py collectstatic`
1. `poetry run python manage.py createsuperuser`

You can also populate the database with all the characters (this is useful for testing some function), but you will need to upload your own scripts (some script data may come at a later date)

`poetry run python manage.py loaddata dev/characters`

The site can be run using:

`poetry run python manage.py runserver`

The site will be accessible at `http://localhost:8000`. You can access the Django admin panel, logging in with the credentials you used to create the super user at `http://localhost:8000/admin`

## Live Debugging

If you use VSCode for as your IDE, you can use the following `settings.json` to launch the website in debug mode so that you can step through code

```json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"justMyCode": false,
"name": "Python: Django",
"type": "python",
"request": "launch",
"program": "manage.py",
"args": [
"runserver"
],
"django": true
}
]
}
```

## Linting

This project uses [Ruff](https://docs.astral.sh/ruff/#ruff) for linting. The GitHub workflow includes a lint using ruff, but before submitting any code for review, please ensure that ruff passes by running `poetry run ruff check`
4 changes: 2 additions & 2 deletions botc/production.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os

from .settings import *
from .settings import * # noqa

# Configure the domain name using the environment variable
# that Azure automatically creates for us.
Expand Down Expand Up @@ -55,7 +55,7 @@
AZURE_STATIC_CONTAINER = os.environ.get("AZURE_STATIC_CONTAINER", "static")
STATIC_URL = f"https://{AZURE_CUSTOM_DOMAIN}/{AZURE_STATIC_CONTAINER}/"

STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")
STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles") # noqa
BS_ICONS_CACHE = os.path.join(STATIC_ROOT, "icon_cache")

ACCOUNT_DEFAULT_HTTP_PROTOCOL = "https"
Expand Down
5 changes: 4 additions & 1 deletion botc/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@
from django.contrib import admin
from django.urls import include, path

urlpatterns = [path("admin/", admin.site.urls), path("", include("scripts.urls"))]
urlpatterns = [
path("admin/", admin.site.urls),
path("", include("scripts.urls")),
]
3 changes: 3 additions & 0 deletions dev/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM postgres:latest

RUN apt-get update && apt-get install -y postgresql-contrib
1 change: 1 addition & 0 deletions dev/characters.json

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions dev/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
services:
db.postgres:
build: .
restart: always
environment:
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres@db
ports:
- 5432:5432
Loading