From fa6550bcf5cc69bc2e00dc2dce287c2ec51506af Mon Sep 17 00:00:00 2001 From: Kevin Alberts Date: Tue, 23 Jan 2024 15:09:09 +0100 Subject: [PATCH] Changes and docker config --- .drone.yml | 17 ++++++++++++ Dockerfile | 27 +++++++++++++++++++ .../management/commands/ical_sync.py | 14 ++++++---- start.sh | 13 +++++++++ 4 files changed, 66 insertions(+), 5 deletions(-) create mode 100644 .drone.yml create mode 100644 Dockerfile create mode 100644 start.sh diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..0c2a4b1 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,17 @@ +--- +kind: pipeline +type: docker +name: default + +steps: +- name: build + image: plugins/docker + settings: + registry: git.kurocon.nl + username: + from_secret: docker_username + password: + from_secret: docker_password + repo: git.kurocon.nl/kurocon/davinci + tags: + - latest diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5878dbe --- /dev/null +++ b/Dockerfile @@ -0,0 +1,27 @@ +# Then build the actual amelie docker image +FROM python:latest + +# Set /usr/src/app as startup working directory +WORKDIR /usr/src/app + +# Install python requirements +COPY requirements.txt ./ +RUN pip install --no-cache-dir -r requirements.txt + +# Make dirs +RUN mkdir -p /static /config + +# Copy sources +COPY . . + +# Check if Django can run +RUN python3 manage.py check + +# Expose volumes +VOLUME ["/static", "/config"] + +# Expose the web port +EXPOSE 8000 + +# Start the website +CMD ["/usr/src/app/start.sh"] diff --git a/davinci/icalendar/management/commands/ical_sync.py b/davinci/icalendar/management/commands/ical_sync.py index b3bc44b..ce2b9c0 100644 --- a/davinci/icalendar/management/commands/ical_sync.py +++ b/davinci/icalendar/management/commands/ical_sync.py @@ -20,11 +20,15 @@ class Command(BaseCommand): if sync.last_sync is None or timezone.now() > (sync.last_sync + sync.sync_interval): logger.debug(f"Synchronizing {sync.name}...") - events = sync.get_events() - added, existing, unchanged, deleted = sync.target.upload_events(events, purge=sync.purge) + try: + events = sync.get_events() + added, existing, unchanged, deleted = sync.target.upload_events(events, purge=sync.purge) - sync.last_sync = timezone.now() - sync.save() - logger.debug(f"Sync for {sync.name} done! {added} events added, {existing} updated. {unchanged} unchanged, and {deleted} purged.") + sync.last_sync = timezone.now() + sync.save() + logger.debug(f"Sync for {sync.name} done! {added} events added, {existing} updated. {unchanged} unchanged, and {deleted} purged.") + except Exception as e: + print(f"Exception during execution of ical_sync for {sync.name}") + raise e logger.debug("iCal sync complete!") diff --git a/start.sh b/start.sh new file mode 100644 index 0000000..a83bc8a --- /dev/null +++ b/start.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +# Copy configuration to proper place +cp "/config/local.py" "/usr/src/app/davinci/local.py" + +# Make sure staticfiles are collected into the static volume +python3 manage.py collectstatic --noinput + +# Make sure database is migrated +python3 manage.py migrate + +# Start django server (ASGI) +daphne -b 0.0.0.0 -p 8080 davinci.asgi:application