diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..7b8f814 --- /dev/null +++ b/.env.example @@ -0,0 +1,9 @@ +DEBUG=1 +SECRET_KEY=password123 +DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1 [::1] vf bloons.walter.lol +SQL_ENGINE=django.db.backends.postgresql +SQL_DATABASE=bloonsworld +SQL_USER=bloonsworld +SQL_PASSWORD=password123 +SQL_HOST=db +SQL_PORT=5432 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 0cfc27e..3aa8cdb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ legacy .idea -venv \ No newline at end of file +venv +.env +*.sqlite3 +*.db \ No newline at end of file diff --git a/.my_pgpass b/.my_pgpass deleted file mode 100644 index 7bea649..0000000 --- a/.my_pgpass +++ /dev/null @@ -1 +0,0 @@ -localhost:5432:bloonsworld:password123 \ No newline at end of file diff --git a/.pg_service.conf b/.pg_service.conf deleted file mode 100644 index 87d0a65..0000000 --- a/.pg_service.conf +++ /dev/null @@ -1,5 +0,0 @@ -[bloonsworld] -host=localhost -user=bloonsworld -dbname=bloonsworld -port=5432 \ No newline at end of file diff --git a/app/entrypoint.sh b/app/entrypoint.sh new file mode 100644 index 0000000..de69381 --- /dev/null +++ b/app/entrypoint.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +if [ "$DATABASE" = "postgres" ] +then + echo "Waiting for postgres..." + + while ! nc -z $SQL_HOST $SQL_PORT; do + sleep 0.1 + done + + echo "PostgreSQL started" +fi + +python manage.py flush --no-input +python manage.py migrate + +exec "$@" diff --git a/app/requirements.txt b/app/requirements.txt index 01f068a..db77eb6 100644 --- a/app/requirements.txt +++ b/app/requirements.txt @@ -1,8 +1,9 @@ -django==5.1.* -django-crispy-forms -crispy-bootstrap4 -django-extensions -tqdm -Pillow -django-resized -django-cleanup \ No newline at end of file +django==5.1.6 +django-crispy-forms==2.3 +crispy-bootstrap4==2024.10 +django-extensions==3.2.3 +tqdm==4.67.1 +Pillow==11.1.0 +django-resized==1.0.3 +django-cleanup==9.0.0 +psycopg2-binary==2.9.10 \ No newline at end of file diff --git a/app/settings/settings.py b/app/settings/settings.py index ec4db37..9760b66 100644 --- a/app/settings/settings.py +++ b/app/settings/settings.py @@ -23,16 +23,15 @@ BASE_DIR = Path(__file__).resolve().parent.parent # See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/ # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +DEBUG = bool(os.environ.get("DEBUG", default=1)) -if platform != "win32": - with open("/secret", "r") as f: - SECRET_KEY = f.read() -else: - # SECURITY WARNING: keep the secret key used in production secret! - SECRET_KEY = 'django-insecure-)e!wy4)=xinnd!d(iuw6*-tf^-)ptiwnttwf+9ql%*jy63wtd8' +def load_insecure_key(): + print("Warning: Insecure SECRET_KEY loaded") + return 'django-insecure-)e!wy4)=xinnd!d(iuw6*-tf^-)ptiwnttwf+9ql%*jy63wtd8' -ALLOWED_HOSTS = ["*"] +SECRET_KEY = os.environ.get("SECRET_KEY") or load_insecure_key() + +ALLOWED_HOSTS = os.environ.get("DJANGO_ALLOWED_HOSTS").split(" ") or "*" # Application definition @@ -94,23 +93,16 @@ WSGI_APPLICATION = 'settings.wsgi.application' # Database # https://docs.djangoproject.com/en/3.2/ref/settings/#databases -DATABASES = {} - -if DEBUG: - DATABASES["default"] = { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': BASE_DIR / 'db.sqlite3', +DATABASES = { + "default": { + "ENGINE": os.environ.get("SQL_ENGINE", "django.db.backends.sqlite3"), + "NAME": os.environ.get("SQL_DATABASE", BASE_DIR / "db.sqlite3"), + "USER": os.environ.get("SQL_USER", "user"), + "PASSWORD": os.environ.get("SQL_PASSWORD", "password"), + "HOST": os.environ.get("SQL_HOST", "localhost"), + "PORT": os.environ.get("SQL_PORT", "5432"), } -else: - DATABASES["default"] = { - "ENGINE": "django.db.backends.postgresql", - "OPTIONS": { - "service": "bloonsworld_db", - "passfile": ".my_pgpass", - # "isolation_level": IsolationLevel.SERIALIZABLE, - } - } - +} # Password validation # https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators diff --git a/docker-compose.yml b/docker-compose.yml index 03b27cc..6d7f533 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -21,7 +21,11 @@ services: restart: unless-stopped bloonsworld-db: - + image: postgres:17 + volumes: + - postgres_data:/var/lib/postgresql/data/ + environment: + - "POSTGRES_HOST_AUTH_METHOD=trust" networks: - bloonsworld restart: unless-stopped diff --git a/readme.md b/readme.md index 96786a9..f01a8a2 100644 --- a/readme.md +++ b/readme.md @@ -1,2 +1,17 @@ # Bloonsworld archive -yes finally. \ No newline at end of file +yes finally. + +## How do i play? +at https://bloons.walter.lol + +## How do i run it on my pc/server? +- install docker ([windows](https://docs.docker.com/desktop/setup/install/windows-install/), [linux](https://docs.docker.com/desktop/setup/install/linux/), [mac](https://docs.docker.com/desktop/setup/install/mac-install/)) +- do `git clone https://git.walter.lol/respect/bloonsworld` +- in the downloaded folder, do `docker-compose up -d` + + +## What do i do once im running it? +This will guide you through making an admin account +- `docker exec -it bloonsworld /bin/bash` +- `cd /app` +- `py manage.py createsuperuser`