Skip to content

Commit 3fa7ed5

Browse files
author
Quentin Dawans
committed
wip
1 parent 030536c commit 3fa7ed5

File tree

6 files changed

+127
-17
lines changed

6 files changed

+127
-17
lines changed

.platform.app.yaml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# This file describes an application. You can have multiple applications
2+
# in the same project.
3+
#
4+
# See https://docs.platform.sh/user_guide/reference/platform-app-yaml.html
5+
6+
# The name of this app. Must be unique within a project.
7+
name: 'website'
8+
9+
# The runtime the application uses.
10+
type: 'python:3.7'
11+
12+
# The relationships of the application with services or other applications.
13+
#
14+
# The left-hand side is the name of the relationship as it will be exposed
15+
# to the application in the PLATFORM_RELATIONSHIPS variable. The right-hand
16+
# side is in the form `<service name>:<endpoint name>`.
17+
relationships:
18+
database: "postgresql:postgresql"
19+
redis: "redis:redis"
20+
21+
# The configuration of app when it is exposed to the web.
22+
web:
23+
# Whether your app should speak to the webserver via TCP or Unix socket
24+
# https://docs.platform.sh/configuration/app-containers.html#upstream
25+
upstream:
26+
socket_family: unix
27+
# Commands are run once after deployment to start the application process.
28+
commands:
29+
start: "gunicorn -w 4 -b unix:$SOCKET myapp.wsgi:application"
30+
locations:
31+
"/":
32+
passthru: true
33+
"/static":
34+
root: "static"
35+
expires: 1h
36+
allow: true
37+
38+
# The size of the persistent disk of the application (in MB).
39+
disk: 512
40+
41+
# The hooks executed at various points in the lifecycle of the application.
42+
hooks:
43+
# The build hook runs before the application is deployed, and is useful for
44+
# assembling the codebase.
45+
build: |
46+
pip install -r requirements/production.txt
47+
python manage.py collectstatic
48+
49+
deploy: |
50+
python manage.py migrate
51+
52+
workers:
53+
celery:
54+
commands:
55+
start: |
56+
celery -A config worker --beat -l info --scheduler django

.platform/routes.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# The routes of the project.
2+
#
3+
# Each route describes how an incoming URL is going to be processed by Platform.sh.
4+
#
5+
# See https://docs.platform.sh/user_guide/reference/routes-yaml.html
6+
7+
"https://{default}/":
8+
type: upstream
9+
upstream: "website:http"
10+
11+
"https://www.{default}/":
12+
type: redirect
13+
to: "https://{default}/"

.platform/services.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
# The services of the project.
3+
#
4+
# Each service listed will be deployed in its own container as part of your
5+
# Platform.sh project.
6+
#
7+
# See https://docs.platform.sh/user_guide/reference/services-yaml.html
8+
9+
postgresql:
10+
type: postgresql:10
11+
disk: 1024
12+
13+
redis:
14+
type: redis:5.0

config/settings/_base.py

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
import dj_database_url
66
from celery.schedules import crontab
7+
from platformshconfig import Config
78

9+
config = Config()
810

911
ALLOWED_HOSTS = []
1012

@@ -28,21 +30,40 @@
2830

2931
BASE_DIR = pathlib.Path(__file__).parent.parent.parent
3032

31-
CACHES = {
32-
'default': {
33-
'BACKEND': 'django_redis.cache.RedisCache',
34-
'LOCATION': os.getenv('REDIS_URL', 'redis://'),
35-
'OPTIONS': {
36-
'CLIENT_CLASS': 'django_redis.client.DefaultClient',
33+
34+
if config.is_valid_platform():
35+
redis_credentials = config.credentials('redis')
36+
37+
CACHES = {
38+
'default': {
39+
'BACKEND': 'django_redis.cache.RedisCache',
40+
'LOCATION': f"redis://{redis_credentials['host']}:{redis_credentials['port']}",
41+
'OPTIONS': {
42+
'CLIENT_CLASS': 'django_redis.client.DefaultClient',
43+
}
44+
}
45+
}
46+
else:
47+
CACHES = {
48+
'default': {
49+
'BACKEND': 'django_redis.cache.RedisCache',
50+
'LOCATION': os.getenv('REDIS_URL', 'redis://'),
51+
'OPTIONS': {
52+
'CLIENT_CLASS': 'django_redis.client.DefaultClient',
53+
}
3754
}
3855
}
39-
}
4056

4157
CSRF_USE_SESSIONS = True
4258

43-
DATABASES = {
44-
'default': dj_database_url.config(default='postgres://postgres:@127.0.0.1:5432/postgres'), # noqa
45-
}
59+
if config.is_valid_platform():
60+
DATABASES = {
61+
'default': dj_database_url.config(default=config.formatted_credentials('postgresql', 'postgresql_dsn')), # noqa
62+
}
63+
else:
64+
DATABASES = {
65+
'default': dj_database_url.config(default='postgres://postgres:@127.0.0.1:5432/postgres'), # noqa
66+
}
4667

4768
DEBUG = False
4869

@@ -191,9 +212,13 @@
191212
# CELERY
192213
#################
193214

194-
BROKER_URL = os.getenv('REDIS_URL', 'redis://')
195-
196-
CELERY_RESULT_BACKEND = os.getenv('REDIS_URL', BROKER_URL)
215+
if config.is_valid_platform():
216+
redis_credentials = config.credentials('redis')
217+
BROKER_URL = f"redis://{redis_credentials['host']}:{redis_credentials['port']}"
218+
CELERY_RESULT_BACKEND = f"redis://{redis_credentials['host']}:{redis_credentials['port']}"
219+
else:
220+
BROKER_URL = os.getenv('REDIS_URL', 'redis://')
221+
CELERY_RESULT_BACKEND = os.getenv('REDIS_URL', BROKER_URL)
197222

198223
CELERYBEAT_SCHEDULE = {
199224
'capture-snapshot-of-slack-users': {

config/settings/production.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616

1717
DEBUG = False
1818

19-
RAVEN_CONFIG = {
20-
'dsn': f'https://94925f1b36294c9eb5e71aa8b7251cb8:{os.environ.get("RAVEN_PASSWORD", "")}@sentry.io/269271', # noqa
21-
'release': raven.fetch_git_sha(str(BASE_DIR)), # noqa
22-
}
19+
if "SENTRY_DSN" in os.environ:
20+
RAVEN_CONFIG = {
21+
'dsn': os.environ["SENTRY_DSN"], # noqa
22+
'release': raven.fetch_git_sha(str(BASE_DIR)), # noqa
23+
}
2324

2425
SESSION_COOKIE_SECURE = True
2526

requirements/production.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
-r base.txt
22

33
gunicorn==19.9.0
4+
platformshconfig

0 commit comments

Comments
 (0)