Skip to content

Commit 7841538

Browse files
authored
Migrate from heroku to fly.io (#67)
1 parent e39f4d9 commit 7841538

File tree

10 files changed

+93
-37
lines changed

10 files changed

+93
-37
lines changed

.dockerignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fly.toml
2+
.git/
3+
*.sqlite3

Dockerfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
ARG PYTHON_VERSION=3.10-slim-buster
2+
3+
FROM python:${PYTHON_VERSION}
4+
5+
ENV PYTHONDONTWRITEBYTECODE 1
6+
ENV PYTHONUNBUFFERED 1
7+
8+
RUN mkdir -p /code
9+
10+
WORKDIR /code
11+
12+
COPY requirements.txt /tmp/requirements.txt
13+
14+
RUN set -ex && \
15+
pip install --upgrade pip && \
16+
pip install -r /tmp/requirements.txt && \
17+
rm -rf /root/.cache/
18+
19+
COPY . /code/
20+
21+
RUN python manage.py collectstatic --noinput
22+
23+
EXPOSE 8000
24+
25+
CMD ["gunicorn", "--bind", ":8000", "--workers", "2", "demo.wsgi"]

Procfile

Lines changed: 0 additions & 2 deletions
This file was deleted.

README.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,3 @@ python manage.py runserver
4444
```
4545

4646
* If everything runs smoothly without any errors you should see the API live at http://127.0.0.1:8000/. Feel free to create an issue if run into problems while setting up the project.
47-
48-
49-
## Deployment
50-
51-
Currently the demo-api is hosted on Heroku with an auto deployment enabled i.e whenver any branch is merged into the main branch. A new deployment is triggered at [demo.scanapi.dev](https://demo.scanapi.dev/api/v1/).
52-
53-
You can check the status/activity log of the current deployment as well as the past ones [here](https://github.com/scanapi/demo-api/deployments).

demo/settings/common.py

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
https://docs.djangoproject.com/en/3.1/ref/settings/
1111
"""
1212

13-
from pathlib import Path
13+
import dj_database_url
1414
import os
1515

16+
from pathlib import Path
17+
1618
# # Build paths inside the project like this: BASE_DIR / 'subdir'.
1719
BASE_DIR = Path(__file__).resolve().parent.parent
1820

@@ -51,6 +53,7 @@
5153
"django.contrib.auth.middleware.AuthenticationMiddleware",
5254
"django.contrib.messages.middleware.MessageMiddleware",
5355
"django.middleware.clickjacking.XFrameOptionsMiddleware",
56+
"whitenoise.middleware.WhiteNoiseMiddleware",
5457
]
5558

5659
ROOT_URLCONF = "demo.urls"
@@ -73,18 +76,13 @@
7376

7477
WSGI_APPLICATION = "demo.wsgi.application"
7578

76-
77-
# Database
78-
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
79-
79+
# https://davi.sh/blog/2022/10/django-with-flyio/
8080
DATABASES = {
81-
"default": {
82-
"ENGINE": "django.db.backends.sqlite3",
83-
"NAME": BASE_DIR / "db.sqlite3",
84-
}
81+
"default": dj_database_url.config(
82+
default="sqlite:///" + os.path.join(BASE_DIR, "db.sqlite3")
83+
)
8584
}
8685

87-
8886
# Password validation
8987
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators
9088

@@ -128,14 +126,10 @@
128126
"PAGE_SIZE": 10,
129127
}
130128

131-
# Static files (CSS, JavaScript, Images)
132-
# https://docs.djangoproject.com/en/1.9/howto/static-files/
133-
STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")
134-
STATIC_URL = "/static/"
135-
136-
# Extra places for collectstatic to find static files.
137-
STATICFILES_DIRS = (os.path.join(BASE_DIR, "static"),)
129+
STATIC_URL = "static/"
130+
STATIC_ROOT = BASE_DIR.parent.parent / "static"
138131

132+
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
139133

140134
# allauth settings
141135
ACCOUNT_EMAIL_VERIFICATION = "none"

demo/settings/production.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import django_heroku
21
from demo.settings.common import *
32

43
# Quick-start development settings - unsuitable for production
@@ -10,6 +9,4 @@
109
# SECURITY WARNING: don't run with debug turned on in production!
1110
DEBUG = False
1211

13-
ALLOWED_HOSTS = ["demo.scanapi.dev"]
14-
15-
django_heroku.settings(locals())
12+
ALLOWED_HOSTS = ["demo.scanapi.dev", "demo-api.fly.dev"]

demo/static/.keepme

Lines changed: 0 additions & 1 deletion
This file was deleted.

fly.toml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# fly.toml file generated for demo-api on 2023-02-22T07:57:35+01:00
2+
3+
app = "demo-api"
4+
kill_signal = "SIGINT"
5+
kill_timeout = 5
6+
processes = []
7+
8+
[deploy]
9+
release_command = "python manage.py migrate"
10+
11+
[env]
12+
ENVIRONMENT = "production"
13+
PORT = "8000"
14+
15+
[experimental]
16+
auto_rollback = true
17+
18+
[[services]]
19+
http_checks = []
20+
internal_port = 8000
21+
processes = ["app"]
22+
protocol = "tcp"
23+
script_checks = []
24+
[services.concurrency]
25+
hard_limit = 25
26+
soft_limit = 20
27+
type = "connections"
28+
29+
[[services.ports]]
30+
force_https = true
31+
handlers = ["http"]
32+
port = 80
33+
34+
[[services.ports]]
35+
handlers = ["tls", "http"]
36+
port = 443
37+
38+
[[services.tcp_checks]]
39+
grace_period = "1s"
40+
interval = "15s"
41+
restart_limit = 0
42+
timeout = "2s"
43+
44+
[[statics]]
45+
guest_path = "/app/public"
46+
url_prefix = "/static/"

requirements.txt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
Django==3.2.18
2-
PyYAML==5.4.1
3-
Pygments==2.9.0
1+
dj-database-url==1.2.0
42
django-allauth==0.44.0
5-
django-heroku==0.3.1
63
django-rest-auth==0.9.5
4+
Django==3.2.18
75
djangorestframework==3.12.4
86
gunicorn==20.0.4
9-
uritemplate==3.0.1
7+
psycopg2-binary==2.9.5
8+
Pygments==2.9.0
9+
PyYAML==5.4.1
1010
setuptools>=65.5.1 # not directly required, pinned by Snyk to avoid a vulnerability
11+
uritemplate==3.0.1
12+
whitenoise==6.3.0

staticfiles/.keepme

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)