diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..b7c39d7c --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +fly.toml +.git/ +*.sqlite3 diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 00000000..7a01a745 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,20 @@ +name: Fly Deploy +on: + workflow_dispatch: + push: + branches: + - 'main' + +env: + FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} + +jobs: + deploy: + name: Deploy app + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: superfly/flyctl-actions/setup-flyctl@master + + - name: Deploy to fly.io + run: flyctl deploy --remote-only diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..bf3caa40 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +ARG PYTHON_VERSION=3.11-slim-bullseye + +FROM python:${PYTHON_VERSION} + +ENV PYTHONDONTWRITEBYTECODE 1 +ENV PYTHONUNBUFFERED 1 + +RUN mkdir -p /code + +WORKDIR /code + +COPY requirements.txt /tmp/requirements.txt +RUN set -ex && \ + pip install --upgrade pip && \ + pip install -r /tmp/requirements.txt && \ + rm -rf /root/.cache/ +COPY . /code + +EXPOSE 8000 + +CMD ["gunicorn", "--chdir", "./src", "--bind", ":8000", "--workers", "2", "spokanetech.wsgi"] diff --git a/fly.toml b/fly.toml new file mode 100644 index 00000000..d40f3348 --- /dev/null +++ b/fly.toml @@ -0,0 +1,30 @@ +# fly.toml app configuration file generated for spokanetech-py on 2024-01-31T20:22:30-08:00 +# +# See https://fly.io/docs/reference/configuration/ for information about how to use this file. +# + +app = 'spokanetech-py' +primary_region = 'sea' +console_command = '/code/manage.py shell' + +[build] + +[env] + PORT = '8000' + +[http_service] + internal_port = 8000 + force_https = true + auto_stop_machines = true + auto_start_machines = true + min_machines_running = 0 + processes = ['app'] + +[[vm]] + cpu_kind = 'shared' + cpus = 1 + memory_mb = 1024 + +[[statics]] + guest_path = '/code/static' + url_prefix = '/static/' diff --git a/requirements.txt b/requirements.txt index 9b152461..1b47c31c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,6 @@ asgiref==3.7.2 +dj-database-url==2.1.0 Django==5.0.1 +gunicorn==21.2.0 +psycopg[binary]==3.1.17 sqlparse==0.4.4 diff --git a/src/spokanetech/settings.py b/src/spokanetech/settings.py index 7d23d278..52ef50f0 100644 --- a/src/spokanetech/settings.py +++ b/src/spokanetech/settings.py @@ -10,9 +10,10 @@ https://docs.djangoproject.com/en/5.0/ref/settings/ """ import os - from pathlib import Path +import dj_database_url + # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent @@ -38,7 +39,7 @@ ) from e DEBUG = False - ALLOWED_HOSTS = ["spokanetech.org"] + ALLOWED_HOSTS = ["spokanetech.org", "spokanetech-py.fly.dev"] # SSL Options # TODO: These will have to change depending on how infra-platform handles SSL termination @@ -97,10 +98,11 @@ # https://docs.djangoproject.com/en/5.0/ref/settings/#databases DATABASES = { - "default": { - "ENGINE": "django.db.backends.sqlite3", - "NAME": BASE_DIR / "db.sqlite3", - } + "default": dj_database_url.config( + default=f"sqlite:////{BASE_DIR}/db.sqlite3", + conn_max_age=600, + conn_health_checks=True, + ), }