Skip to content

Commit

Permalink
Merge pull request #17 from SpokaneTech/joeriddles/16-deploy-to-fly
Browse files Browse the repository at this point in the history
Add Fly.io config
  • Loading branch information
joeriddles authored Feb 1, 2024
2 parents d4b0e16 + 4e96423 commit 85f526f
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fly.toml
.git/
*.sqlite3
20 changes: 20 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
30 changes: 30 additions & 0 deletions fly.toml
Original file line number Diff line number Diff line change
@@ -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/'
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
14 changes: 8 additions & 6 deletions src/spokanetech/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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,
),
}


Expand Down

0 comments on commit 85f526f

Please sign in to comment.