diff --git a/.gitignore b/.gitignore index 3adc5e1..8b944b0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,10 @@ -### PostgreSQL template +### Postgres template postgres ### Editors template .idea .vscode +blogs ### Django template *.log @@ -13,8 +14,9 @@ __pycache__/ local_settings.py db.sqlite3 db.sqlite3-journal -media +# media # By default you dont want this to be commited, but I run my server on Docker so bleh CACHE +/data # If your build process includes running collectstatic, then you probably don't need or want to include staticfiles/ # in your Git repository. Update and uncomment the following line accordingly. diff --git a/README.md b/README.md new file mode 100644 index 0000000..a5efa1b --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ +My little Django website + blog + +## Installation +Clone this repo and cd into it + +### Running +```bash +docker-compose up +``` + +### First time setup + +```bash +docker-compose exec website python3 /app/manage.py createsuperuser +``` + +ok bye! diff --git a/docker-compose.yml b/docker-compose.yml index 377f263..a7651d9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,21 +5,24 @@ services: image: postgres:alpine restart: unless-stopped volumes: - - ./postgres:/var/lib/postgresql/data + - ./postgres/data:/var/lib/postgresql/data environment: POSTGRES_USER: ${POSTGRES_USER} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} POSTGRES_DB: ${POSTGRES_DB} + website: build: website restart: unless-stopped volumes: - - ./media:/website/media - - ./logs:/data/logs + - ./data/media:/website/media environment: DJANGO_KEY: ${DJANGO_KEY} - DB_HOST: db - DB_USER: ${POSTGRES_USER} - DB_PASSWORD: ${POSTGRES_PASSWORD} - DB_NAME: ${POSTGRES_DB} + POSTGRES_USER: ${POSTGRES_USER} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} + POSTGRES_DB: ${POSTGRES_DB} + depends_on: + - db + ports: + - "6212:8000" diff --git a/website/Dockerfile b/website/Dockerfile index 048e114..dedf951 100644 --- a/website/Dockerfile +++ b/website/Dockerfile @@ -2,12 +2,17 @@ FROM alpine:latest EXPOSE 8000 -WORKDIR /website +RUN apk update && apk add build-base postgresql-client \ + python3 py3-pip python3-dev --no-cache + +RUN mkdir /app +WORKDIR /app COPY requirements.txt requirements.txt -COPY ./website ./website - -RUN apk update && apk add python3 py3-pip RUN pip install -r requirements.txt -CMD ["python3", "manage.py", "runserver", ""] +COPY website . +COPY run.sh run.sh +RUN chmod +x run.sh + +CMD ["./run.sh"] diff --git a/requirements.txt b/website/requirements.txt similarity index 92% rename from requirements.txt rename to website/requirements.txt index 8250f6f..028cd76 100644 --- a/requirements.txt +++ b/website/requirements.txt @@ -1,7 +1,8 @@ Gunicorn -psycopg2-binary -pillow django +psycopg2-binary +tzdata +pillow django-libsass django-compressor django-markdownify diff --git a/website/run.sh b/website/run.sh new file mode 100644 index 0000000..a03d5a4 --- /dev/null +++ b/website/run.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +# Wait for database to start +until pg_isready -d $POSTGRES_DB -h db -U $POSTGRES_USER +do + echo "Waiting for database to start... (5s)" + sleep 5 +done + +echo "Database is ready!" + +# Check if there are any changes to the database +#python3 manage.py showmigrations +if (python3 manage.py showmigrations | grep "\[ \]" > /dev/null); +then + echo "Database changes detected! Migrating..." + python3 manage.py makemigrations + python3 manage.py migrate +fi + +# Start server!!!! +echo "Starting server..." +gunicorn --bind :8000 website.wsgi:application + diff --git a/website/articles/__init__.py b/website/website/articles/__init__.py similarity index 100% rename from website/articles/__init__.py rename to website/website/articles/__init__.py diff --git a/website/articles/admin.py b/website/website/articles/admin.py similarity index 100% rename from website/articles/admin.py rename to website/website/articles/admin.py diff --git a/website/articles/apps.py b/website/website/articles/apps.py similarity index 100% rename from website/articles/apps.py rename to website/website/articles/apps.py diff --git a/website/articles/migrations/0001_initial.py b/website/website/articles/migrations/0001_initial.py similarity index 100% rename from website/articles/migrations/0001_initial.py rename to website/website/articles/migrations/0001_initial.py diff --git a/website/articles/migrations/0002_article_thumb.py b/website/website/articles/migrations/0002_article_thumb.py similarity index 100% rename from website/articles/migrations/0002_article_thumb.py rename to website/website/articles/migrations/0002_article_thumb.py diff --git a/website/articles/migrations/0003_alter_article_thumb.py b/website/website/articles/migrations/0003_alter_article_thumb.py similarity index 100% rename from website/articles/migrations/0003_alter_article_thumb.py rename to website/website/articles/migrations/0003_alter_article_thumb.py diff --git a/website/articles/migrations/0004_article_published.py b/website/website/articles/migrations/0004_article_published.py similarity index 100% rename from website/articles/migrations/0004_article_published.py rename to website/website/articles/migrations/0004_article_published.py diff --git a/website/articles/migrations/__init__.py b/website/website/articles/migrations/__init__.py similarity index 100% rename from website/articles/migrations/__init__.py rename to website/website/articles/migrations/__init__.py diff --git a/website/articles/models.py b/website/website/articles/models.py similarity index 100% rename from website/articles/models.py rename to website/website/articles/models.py diff --git a/website/articles/tests.py b/website/website/articles/tests.py similarity index 100% rename from website/articles/tests.py rename to website/website/articles/tests.py diff --git a/website/articles/urls.py b/website/website/articles/urls.py similarity index 100% rename from website/articles/urls.py rename to website/website/articles/urls.py diff --git a/website/articles/views.py b/website/website/articles/views.py similarity index 100% rename from website/articles/views.py rename to website/website/articles/views.py diff --git a/website/manage.py b/website/website/manage.py similarity index 100% rename from website/manage.py rename to website/website/manage.py diff --git a/website/website/media/default.jpg b/website/website/media/default.jpg new file mode 100644 index 0000000..ff67619 Binary files /dev/null and b/website/website/media/default.jpg differ diff --git a/website/static/images/kissing-men.png b/website/website/static/images/kissing-men.png similarity index 100% rename from website/static/images/kissing-men.png rename to website/website/static/images/kissing-men.png diff --git a/website/static/images/mood.png b/website/website/static/images/mood.png similarity index 100% rename from website/static/images/mood.png rename to website/website/static/images/mood.png diff --git a/website/static/images/ref.png b/website/website/static/images/ref.png similarity index 100% rename from website/static/images/ref.png rename to website/website/static/images/ref.png diff --git a/website/static/images/sneak.png b/website/website/static/images/sneak.png similarity index 100% rename from website/static/images/sneak.png rename to website/website/static/images/sneak.png diff --git a/website/static/images/taidum.png b/website/website/static/images/taidum.png similarity index 100% rename from website/static/images/taidum.png rename to website/website/static/images/taidum.png diff --git a/website/static/js/navigation.js b/website/website/static/js/navigation.js similarity index 100% rename from website/static/js/navigation.js rename to website/website/static/js/navigation.js diff --git a/website/static/js/scroll.js b/website/website/static/js/scroll.js similarity index 100% rename from website/static/js/scroll.js rename to website/website/static/js/scroll.js diff --git a/website/static/sass/styles.sass b/website/website/static/sass/styles.sass similarity index 100% rename from website/static/sass/styles.sass rename to website/website/static/sass/styles.sass diff --git a/website/static/sass/styles/art-block.sass b/website/website/static/sass/styles/art-block.sass similarity index 100% rename from website/static/sass/styles/art-block.sass rename to website/website/static/sass/styles/art-block.sass diff --git a/website/static/sass/styles/button-array.sass b/website/website/static/sass/styles/button-array.sass similarity index 100% rename from website/static/sass/styles/button-array.sass rename to website/website/static/sass/styles/button-array.sass diff --git a/website/static/sass/styles/footer.sass b/website/website/static/sass/styles/footer.sass similarity index 100% rename from website/static/sass/styles/footer.sass rename to website/website/static/sass/styles/footer.sass diff --git a/website/static/sass/styles/markdown.sass b/website/website/static/sass/styles/markdown.sass similarity index 100% rename from website/static/sass/styles/markdown.sass rename to website/website/static/sass/styles/markdown.sass diff --git a/website/static/sass/styles/navigation.sass b/website/website/static/sass/styles/navigation.sass similarity index 100% rename from website/static/sass/styles/navigation.sass rename to website/website/static/sass/styles/navigation.sass diff --git a/website/static/sass/styles/table.sass b/website/website/static/sass/styles/table.sass similarity index 100% rename from website/static/sass/styles/table.sass rename to website/website/static/sass/styles/table.sass diff --git a/website/templates/base.html b/website/website/templates/base.html similarity index 100% rename from website/templates/base.html rename to website/website/templates/base.html diff --git a/website/templates/footer.html b/website/website/templates/footer.html similarity index 100% rename from website/templates/footer.html rename to website/website/templates/footer.html diff --git a/website/templates/navigation.html b/website/website/templates/navigation.html similarity index 100% rename from website/templates/navigation.html rename to website/website/templates/navigation.html diff --git a/website/templates/views/article.html b/website/website/templates/views/article.html similarity index 100% rename from website/templates/views/article.html rename to website/website/templates/views/article.html diff --git a/website/templates/views/articles.html b/website/website/templates/views/articles.html similarity index 100% rename from website/templates/views/articles.html rename to website/website/templates/views/articles.html diff --git a/website/templates/views/index.html b/website/website/templates/views/index.html similarity index 100% rename from website/templates/views/index.html rename to website/website/templates/views/index.html diff --git a/website/templates/views/refsheet.html b/website/website/templates/views/refsheet.html similarity index 100% rename from website/templates/views/refsheet.html rename to website/website/templates/views/refsheet.html diff --git a/website/website/__init__.py b/website/website/website/__init__.py similarity index 100% rename from website/website/__init__.py rename to website/website/website/__init__.py diff --git a/website/website/asgi.py b/website/website/website/asgi.py similarity index 100% rename from website/website/asgi.py rename to website/website/website/asgi.py diff --git a/website/website/settings.py b/website/website/website/settings.py similarity index 94% rename from website/website/settings.py rename to website/website/website/settings.py index 33c37dc..06ee609 100644 --- a/website/website/settings.py +++ b/website/website/website/settings.py @@ -78,20 +78,13 @@ WSGI_APPLICATION = "website.wsgi.application" # Database # https://docs.djangoproject.com/en/4.2/ref/settings/#databases -# DATABASES = { -# "default": { -# "ENGINE": "django.db.backends.sqlite3", -# "NAME": BASE_DIR / "db.sqlite3", -# } -# } - DATABASES = { 'default': { - 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'ENGINE': "django.db.backends.postgresql", 'NAME': getenv('POSTGRES_DB'), 'USER': getenv('POSTGRES_USER'), 'PASSWORD': getenv('POSTGRES_PASSWORD'), - 'HOST': getenv('POSTGRES_HOST'), + 'HOST': 'db', 'PORT': 5432, } } diff --git a/website/website/urls.py b/website/website/website/urls.py similarity index 100% rename from website/website/urls.py rename to website/website/website/urls.py diff --git a/website/website/views.py b/website/website/website/views.py similarity index 100% rename from website/website/views.py rename to website/website/website/views.py diff --git a/website/website/wsgi.py b/website/website/website/wsgi.py similarity index 100% rename from website/website/wsgi.py rename to website/website/website/wsgi.py