diff --git a/.gitea/workflows/new-deploy.yml b/.gitea/workflows/new-deploy.yml index b7cc076..1755bd2 100644 --- a/.gitea/workflows/new-deploy.yml +++ b/.gitea/workflows/new-deploy.yml @@ -8,7 +8,7 @@ on: - 'develop' jobs: - build-push-image: + build-run-image: runs-on: ubuntu-latest steps: - name: SSH into RPi and deploy Dragonroost. @@ -26,4 +26,4 @@ jobs: sudo git clone https://github.com/leethobbit/dragonroost.git cd dragonroost/ echo "Rebuilding and restarting Docker services." - sudo docker compose -f docker-compose.local.yml down -d && docker compose -f docker-compose.local.yml up -d + sudo docker compose -f docker-compose.local.yml up --build -d diff --git a/.github/dependabot.yml b/.github/dependabot.yml index e516039..9a6dc87 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -47,13 +47,6 @@ updates: schedule: interval: 'daily' - - package-ecosystem: 'docker' - # Look for a `Dockerfile` in the `compose/production/aws` directory - directory: 'compose/production/aws/' - # Every weekday - schedule: - interval: 'daily' - - package-ecosystem: 'docker' # Look for a `Dockerfile` in the `compose/production/django` directory directory: 'compose/production/django/' diff --git a/Taskfile.yml b/Taskfile.yml new file mode 100644 index 0000000..f2cddf9 --- /dev/null +++ b/Taskfile.yml @@ -0,0 +1,27 @@ +version: '3' + +# These commands were created for Windows. +# In particular, the docker-compose usage might need to be changed to docker compose (without the dash) on other OSes. +tasks: + run-dev: + desc: Builds and runs the development environment. + cmds: + - docker-compose -f docker-compose.local.yml --build -d + + add-starting-data: + desc: Add species and locations data. + cmds: + - docker-compose -f docker-compose.local.yml run --rm django python manage.py add_initial_data + + add-animals: + desc: Add animals (Defaults to creating 50 entries if no amount is specified.) + vars: + COUNT: '{{.COUNT| default 50}}' + cmds: + - docker-compose -f docker-compose.local.yml run --rm django python manage.py add_animals --count {{.COUNT}} + + db-migrate: + desc: Run migration in the docker prod app. + cmds: + - docker-compose -f docker-compose.local.yml run --rm django python manage.py makemigrations + - docker-compose -f docker-compose.local.yml run --rm django python manage.py migrate diff --git a/compose/production/aws/Dockerfile b/compose/production/aws/Dockerfile deleted file mode 100644 index aa093f9..0000000 --- a/compose/production/aws/Dockerfile +++ /dev/null @@ -1,13 +0,0 @@ -FROM docker.io/amazon/aws-cli:2.19.1 - -# Clear entrypoint from the base image, otherwise it's always calling the aws CLI -ENTRYPOINT [] -CMD ["/bin/bash"] - -COPY ./compose/production/aws/maintenance /usr/local/bin/maintenance -COPY ./compose/production/postgres/maintenance/_sourced /usr/local/bin/maintenance/_sourced - -RUN chmod +x /usr/local/bin/maintenance/* - -RUN mv /usr/local/bin/maintenance/* /usr/local/bin \ - && rmdir /usr/local/bin/maintenance diff --git a/compose/production/aws/maintenance/download b/compose/production/aws/maintenance/download deleted file mode 100644 index 12871a7..0000000 --- a/compose/production/aws/maintenance/download +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/sh - -### Download a file from your Amazon S3 bucket to the postgres /backups folder -### -### Usage: -### $ docker compose -f docker-compose.production.yml run --rm awscli <1> - -set -o errexit -set -o pipefail -set -o nounset - -working_dir="$(dirname ${0})" -source "${working_dir}/_sourced/constants.sh" -source "${working_dir}/_sourced/messages.sh" - -export AWS_ACCESS_KEY_ID="${DJANGO_AWS_ACCESS_KEY_ID}" -export AWS_SECRET_ACCESS_KEY="${DJANGO_AWS_SECRET_ACCESS_KEY}" -export AWS_STORAGE_BUCKET_NAME="${DJANGO_AWS_STORAGE_BUCKET_NAME}" - - -aws s3 cp s3://${AWS_STORAGE_BUCKET_NAME}${BACKUP_DIR_PATH}/${1} ${BACKUP_DIR_PATH}/${1} - -message_success "Finished downloading ${1}." diff --git a/compose/production/aws/maintenance/upload b/compose/production/aws/maintenance/upload deleted file mode 100644 index 2f57782..0000000 --- a/compose/production/aws/maintenance/upload +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/sh - -### Upload the /backups folder to Amazon S3 -### -### Usage: -### $ docker compose -f docker-compose.production.yml run --rm awscli upload - -set -o errexit -set -o pipefail -set -o nounset - -working_dir="$(dirname ${0})" -source "${working_dir}/_sourced/constants.sh" -source "${working_dir}/_sourced/messages.sh" - -export AWS_ACCESS_KEY_ID="${DJANGO_AWS_ACCESS_KEY_ID}" -export AWS_SECRET_ACCESS_KEY="${DJANGO_AWS_SECRET_ACCESS_KEY}" -export AWS_STORAGE_BUCKET_NAME="${DJANGO_AWS_STORAGE_BUCKET_NAME}" - - -message_info "Upload the backups directory to S3 bucket {$AWS_STORAGE_BUCKET_NAME}" - -aws s3 cp ${BACKUP_DIR_PATH} s3://${AWS_STORAGE_BUCKET_NAME}${BACKUP_DIR_PATH} --recursive - -message_info "Cleaning the directory ${BACKUP_DIR_PATH}" - -rm -rf ${BACKUP_DIR_PATH}/* - -message_success "Finished uploading and cleaning." diff --git a/compose/production/django/start b/compose/production/django/start index 97216fa..92f9abb 100644 --- a/compose/production/django/start +++ b/compose/production/django/start @@ -7,4 +7,4 @@ set -o nounset python /app/manage.py collectstatic --noinput -exec /usr/local/bin/gunicorn config.wsgi --bind 0.0.0.0:5000 --chdir=/app +exec /usr/local/bin/gunicorn config.wsgi --bind 0.0.0.0:8100 --chdir=/app diff --git a/compose/production/traefik/traefik.yml b/compose/production/traefik/traefik.yml index e3911f1..3a6dd08 100644 --- a/compose/production/traefik/traefik.yml +++ b/compose/production/traefik/traefik.yml @@ -28,7 +28,7 @@ certificatesResolvers: http: routers: web-secure-router: - rule: 'Host(`example.com`) || Host(`www.example.com`)' + rule: 'Host(`ddrev.org`)' entryPoints: - web-secure middlewares: @@ -49,7 +49,7 @@ http: django: loadBalancer: servers: - - url: http://django:5000 + - url: http://django:8100 providers: # https://doc.traefik.io/traefik/master/providers/file/ diff --git a/config/settings/production.py b/config/settings/production.py index e996922..b84fd61 100644 --- a/config/settings/production.py +++ b/config/settings/production.py @@ -61,46 +61,16 @@ default=True, ) - -# https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#settings -AWS_ACCESS_KEY_ID = env("DJANGO_AWS_ACCESS_KEY_ID") -# https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#settings -AWS_SECRET_ACCESS_KEY = env("DJANGO_AWS_SECRET_ACCESS_KEY") -# https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#settings -AWS_STORAGE_BUCKET_NAME = env("DJANGO_AWS_STORAGE_BUCKET_NAME") -# https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#settings -AWS_QUERYSTRING_AUTH = False -# DO NOT change these unless you know what you're doing. -_AWS_EXPIRY = 60 * 60 * 24 * 7 -# https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#settings -AWS_S3_OBJECT_PARAMETERS = { - "CacheControl": f"max-age={_AWS_EXPIRY}, s-maxage={_AWS_EXPIRY}, must-revalidate", -} -# https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#settings -AWS_S3_MAX_MEMORY_SIZE = env.int( - "DJANGO_AWS_S3_MAX_MEMORY_SIZE", - default=100_000_000, # 100MB -) -# https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#settings -AWS_S3_REGION_NAME = env("DJANGO_AWS_S3_REGION_NAME", default=None) -# https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#cloudfront -AWS_S3_CUSTOM_DOMAIN = env("DJANGO_AWS_S3_CUSTOM_DOMAIN", default=None) -aws_s3_domain = AWS_S3_CUSTOM_DOMAIN or f"{AWS_STORAGE_BUCKET_NAME}.s3.amazonaws.com" # STATIC & MEDIA # ------------------------ STORAGES = { "default": { - "BACKEND": "storages.backends.s3.S3Storage", - "OPTIONS": { - "location": "media", - "file_overwrite": False, - }, + "BACKEND": "django.core.files.storage.FileSystemStorage", }, "staticfiles": { "BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage", }, } -MEDIA_URL = f"https://{aws_s3_domain}/media/" # EMAIL # ------------------------------------------------------------------------------ diff --git a/docker-compose.production.yml b/docker-compose.production.yml index e5a830a..de12abc 100644 --- a/docker-compose.production.yml +++ b/docker-compose.production.yml @@ -2,6 +2,7 @@ volumes: production_postgres_data: {} production_postgres_data_backups: {} production_traefik: {} + production_django_media: {} @@ -12,6 +13,8 @@ services: dockerfile: ./compose/production/django/Dockerfile image: dragonroost_production_django + volumes: + - production_django_media:/app/dragonroost/media depends_on: - postgres - redis @@ -48,11 +51,12 @@ services: image: docker.io/redis:6 - awscli: + nginx: build: context: . - dockerfile: ./compose/production/aws/Dockerfile - env_file: - - ./.envs/.production/.django + dockerfile: ./compose/production/nginx/Dockerfile + image: dragonroost_production_nginx + depends_on: + - django volumes: - - production_postgres_data_backups:/backups:z + - production_django_media:/usr/share/nginx/media:ro diff --git a/dragonroost/animals/management/commands/add_animals.py b/dragonroost/animals/management/commands/add_animals.py index e1bd95a..3c89da6 100644 --- a/dragonroost/animals/management/commands/add_animals.py +++ b/dragonroost/animals/management/commands/add_animals.py @@ -16,11 +16,12 @@ fake = Faker() -MEDIA_ROOT = settings.MEDIA_ROOT +APPS_DIR = settings.APPS_DIR +IMG_ROOT = str(APPS_DIR / "static") def random_image(): - dir_path = Path(MEDIA_ROOT) / "images/" + dir_path = Path(IMG_ROOT) / "images" / "sample_animal_photos/" files = [ content for content in listdir(dir_path) if Path(dir_path / content).is_file() ] diff --git a/dragonroost/animals/migrations/0006_alter_animal_options.py b/dragonroost/animals/migrations/0006_alter_animal_options.py new file mode 100644 index 0000000..da05ec9 --- /dev/null +++ b/dragonroost/animals/migrations/0006_alter_animal_options.py @@ -0,0 +1,17 @@ +# Generated by Django 5.0.9 on 2024-12-06 16:54 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('animals', '0005_alter_animal_breed'), + ] + + operations = [ + migrations.AlterModelOptions( + name='animal', + options={'ordering': ['-intake_date']}, + ), + ] diff --git a/dragonroost/contrib/sites/migrations/0003_set_site_domain_and_name.py b/dragonroost/contrib/sites/migrations/0003_set_site_domain_and_name.py index 2167757..f3e5140 100644 --- a/dragonroost/contrib/sites/migrations/0003_set_site_domain_and_name.py +++ b/dragonroost/contrib/sites/migrations/0003_set_site_domain_and_name.py @@ -40,7 +40,7 @@ def update_site_forward(apps, schema_editor): _update_or_create_site_with_sequence( Site, schema_editor.connection, - "example.com", + "ddrev.org", "Dragonroost NG", ) diff --git a/dragonroost/static/images/sample_animal_photos/bearded_dragon.jpg b/dragonroost/static/images/sample_animal_photos/bearded_dragon.jpg new file mode 100644 index 0000000..240e74b Binary files /dev/null and b/dragonroost/static/images/sample_animal_photos/bearded_dragon.jpg differ diff --git a/dragonroost/static/images/sample_animal_photos/chameleon.jpg b/dragonroost/static/images/sample_animal_photos/chameleon.jpg new file mode 100644 index 0000000..ff88a36 Binary files /dev/null and b/dragonroost/static/images/sample_animal_photos/chameleon.jpg differ diff --git a/dragonroost/static/images/sample_animal_photos/cheetah.jpg b/dragonroost/static/images/sample_animal_photos/cheetah.jpg new file mode 100644 index 0000000..c33d5d0 Binary files /dev/null and b/dragonroost/static/images/sample_animal_photos/cheetah.jpg differ diff --git a/dragonroost/static/images/sample_animal_photos/iguana.jpg b/dragonroost/static/images/sample_animal_photos/iguana.jpg new file mode 100644 index 0000000..a41cdf7 Binary files /dev/null and b/dragonroost/static/images/sample_animal_photos/iguana.jpg differ diff --git a/dragonroost/static/images/sample_animal_photos/iguana2.jpg b/dragonroost/static/images/sample_animal_photos/iguana2.jpg new file mode 100644 index 0000000..7fa66e2 Binary files /dev/null and b/dragonroost/static/images/sample_animal_photos/iguana2.jpg differ diff --git a/dragonroost/static/images/sample_animal_photos/parrot1.jpg b/dragonroost/static/images/sample_animal_photos/parrot1.jpg new file mode 100644 index 0000000..fca312a Binary files /dev/null and b/dragonroost/static/images/sample_animal_photos/parrot1.jpg differ diff --git a/dragonroost/static/images/sample_animal_photos/parrot2.jpg b/dragonroost/static/images/sample_animal_photos/parrot2.jpg new file mode 100644 index 0000000..9623625 Binary files /dev/null and b/dragonroost/static/images/sample_animal_photos/parrot2.jpg differ diff --git a/dragonroost/static/images/sample_animal_photos/parrot3.jpg b/dragonroost/static/images/sample_animal_photos/parrot3.jpg new file mode 100644 index 0000000..d43feb1 Binary files /dev/null and b/dragonroost/static/images/sample_animal_photos/parrot3.jpg differ diff --git a/dragonroost/static/images/sample_animal_photos/parrot4.jpg b/dragonroost/static/images/sample_animal_photos/parrot4.jpg new file mode 100644 index 0000000..d1b539b Binary files /dev/null and b/dragonroost/static/images/sample_animal_photos/parrot4.jpg differ diff --git a/dragonroost/static/images/sample_animal_photos/toucan.jpg b/dragonroost/static/images/sample_animal_photos/toucan.jpg new file mode 100644 index 0000000..bedfd67 Binary files /dev/null and b/dragonroost/static/images/sample_animal_photos/toucan.jpg differ diff --git a/requirements/production.txt b/requirements/production.txt index 3df3a30..3025f1c 100644 --- a/requirements/production.txt +++ b/requirements/production.txt @@ -7,5 +7,4 @@ psycopg[c]==3.2.2 # https://github.com/psycopg/psycopg # Django # ------------------------------------------------------------------------------ -django-storages[s3]==1.14.4 # https://github.com/jschneier/django-storages django-anymail[mailgun]==12.0 # https://github.com/anymail/django-anymail