Skip to content

Commit

Permalink
Add Taskfile, remove AWS components, more deployment work
Browse files Browse the repository at this point in the history
  • Loading branch information
leethobbit committed Dec 6, 2024
1 parent d1b2afd commit c578e8b
Show file tree
Hide file tree
Showing 24 changed files with 63 additions and 117 deletions.
4 changes: 2 additions & 2 deletions .gitea/workflows/new-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
7 changes: 0 additions & 7 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/'
Expand Down
27 changes: 27 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -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
13 changes: 0 additions & 13 deletions compose/production/aws/Dockerfile

This file was deleted.

23 changes: 0 additions & 23 deletions compose/production/aws/maintenance/download

This file was deleted.

29 changes: 0 additions & 29 deletions compose/production/aws/maintenance/upload

This file was deleted.

2 changes: 1 addition & 1 deletion compose/production/django/start
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions compose/production/traefik/traefik.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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/
Expand Down
32 changes: 1 addition & 31 deletions config/settings/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
# ------------------------------------------------------------------------------
Expand Down
14 changes: 9 additions & 5 deletions docker-compose.production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ volumes:
production_postgres_data: {}
production_postgres_data_backups: {}
production_traefik: {}
production_django_media: {}



Expand All @@ -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
Expand Down Expand Up @@ -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
5 changes: 3 additions & 2 deletions dragonroost/animals/management/commands/add_animals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
]
Expand Down
17 changes: 17 additions & 0 deletions dragonroost/animals/migrations/0006_alter_animal_options.py
Original file line number Diff line number Diff line change
@@ -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']},
),
]
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion requirements/production.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c578e8b

Please sign in to comment.