Prepare for deploy
This commit is contained in:
parent
0632a4ced8
commit
a1e7e4f30e
9 changed files with 69 additions and 6 deletions
2
.dockerignore
Normal file
2
.dockerignore
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
*.db
|
||||||
|
*.sqlite3
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -272,3 +272,4 @@ dmypy.json
|
||||||
# End of https://www.toptal.com/developers/gitignore/api/osx,pycharm,python
|
# End of https://www.toptal.com/developers/gitignore/api/osx,pycharm,python
|
||||||
|
|
||||||
.idea
|
.idea
|
||||||
|
db/
|
||||||
|
|
19
Dockerfile
Normal file
19
Dockerfile
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
FROM python:3.8.5-slim
|
||||||
|
|
||||||
|
RUN mkdir /app && mkdir /db
|
||||||
|
WORKDIR /app
|
||||||
|
COPY requirements.txt ./
|
||||||
|
RUN pip install -r requirements.txt
|
||||||
|
COPY manage.py ./
|
||||||
|
COPY articles ./articles/
|
||||||
|
COPY blog ./blog/
|
||||||
|
COPY docker ./docker/
|
||||||
|
|
||||||
|
ENV SECRET_KEY "changeme"
|
||||||
|
ENV DEBUG "false"
|
||||||
|
ENV HOST ""
|
||||||
|
ENV DB_BASE_DIR "/db"
|
||||||
|
|
||||||
|
HEALTHCHECK --start-period=30s CMD curl -f http://localhost:8000
|
||||||
|
|
||||||
|
CMD ["/app/docker/run.sh"]
|
|
@ -31,6 +31,10 @@ a {
|
||||||
transition: text-decoration .12s ease;
|
transition: text-decoration .12s ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*.article-list a {*/
|
||||||
|
/* text-decoration: underline var(--accent) 1px;*/
|
||||||
|
/*}*/
|
||||||
|
|
||||||
a:hover, a:focus {
|
a:hover, a:focus {
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ https://docs.djangoproject.com/en/3.1/topics/settings/
|
||||||
For the full list of settings and their values, see
|
For the full list of settings and their values, see
|
||||||
https://docs.djangoproject.com/en/3.1/ref/settings/
|
https://docs.djangoproject.com/en/3.1/ref/settings/
|
||||||
"""
|
"""
|
||||||
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||||
|
@ -20,12 +20,20 @@ BASE_DIR = Path(__file__).resolve(strict=True).parent.parent
|
||||||
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
|
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
|
||||||
|
|
||||||
# SECURITY WARNING: keep the secret key used in production secret!
|
# SECURITY WARNING: keep the secret key used in production secret!
|
||||||
SECRET_KEY = "s#!83!8e$3s89m)r$1ghsgxbndf8=#^qt(_*o%xbq0j2t8#db5"
|
SECRET_KEY = os.getenv(
|
||||||
|
"SECRET_KEY", "s#!83!8e$3s89m)r$1ghsgxbndf8=#^qt(_*o%xbq0j2t8#db5"
|
||||||
|
)
|
||||||
|
|
||||||
# SECURITY WARNING: don't run with debug turned on in production!
|
# SECURITY WARNING: don't run with debug turned on in production!
|
||||||
DEBUG = True
|
DEBUG = os.getenv("DEBUG", "true").lower() == "true"
|
||||||
|
|
||||||
ALLOWED_HOSTS = []
|
ALLOWED_HOSTS = [
|
||||||
|
"localhost",
|
||||||
|
"127.0.0.1",
|
||||||
|
]
|
||||||
|
HOST = os.getenv("HOST")
|
||||||
|
if HOST:
|
||||||
|
ALLOWED_HOSTS.append(HOST)
|
||||||
|
|
||||||
|
|
||||||
# Application definition
|
# Application definition
|
||||||
|
@ -74,10 +82,17 @@ WSGI_APPLICATION = "blog.wsgi.application"
|
||||||
# Database
|
# Database
|
||||||
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
|
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
|
||||||
|
|
||||||
|
DB_BASE_DIR = os.getenv("DB_BASE_DIR", BASE_DIR)
|
||||||
|
if not DB_BASE_DIR:
|
||||||
|
# Protect against empty strings
|
||||||
|
DB_BASE_DIR = BASE_DIR
|
||||||
|
else:
|
||||||
|
DB_BASE_DIR = Path(DB_BASE_DIR).resolve(strict=True)
|
||||||
|
|
||||||
DATABASES = {
|
DATABASES = {
|
||||||
"default": {
|
"default": {
|
||||||
"ENGINE": "django.db.backends.sqlite3",
|
"ENGINE": "django.db.backends.sqlite3",
|
||||||
"NAME": BASE_DIR / "db.sqlite3",
|
"NAME": DB_BASE_DIR / "db.sqlite3",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,6 +128,7 @@ USE_TZ = True
|
||||||
# https://docs.djangoproject.com/en/3.1/howto/static-files/
|
# https://docs.djangoproject.com/en/3.1/howto/static-files/
|
||||||
|
|
||||||
STATIC_URL = "/static/"
|
STATIC_URL = "/static/"
|
||||||
|
STATIC_ROOT = BASE_DIR / "static"
|
||||||
|
|
||||||
AUTH_USER_MODEL = "articles.User"
|
AUTH_USER_MODEL = "articles.User"
|
||||||
|
|
||||||
|
|
15
docker-compose.yml
Normal file
15
docker-compose.yml
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
version: '2.4'
|
||||||
|
services:
|
||||||
|
django:
|
||||||
|
image: crocmagnon/blog
|
||||||
|
build: .
|
||||||
|
ports:
|
||||||
|
- 8000:8000
|
||||||
|
env_file:
|
||||||
|
- .env
|
||||||
|
volumes:
|
||||||
|
- ./db:/db
|
||||||
|
# - /srv/blog/db:/db
|
||||||
|
- ./static:/app/static
|
||||||
|
# - /srv/blog/static:/app/static
|
||||||
|
restart: on-failure
|
5
docker/run.sh
Executable file
5
docker/run.sh
Executable file
|
@ -0,0 +1,5 @@
|
||||||
|
#!/bin/sh
|
||||||
|
yes yes | python manage.py migrate && \
|
||||||
|
#yes yes | pipenv run python manage.py createcachetable && \
|
||||||
|
python manage.py collectstatic --noinput && \
|
||||||
|
gunicorn blog.wsgi -b 0.0.0.0:8000 --log-file -
|
1
requirements-dev.txt
Normal file
1
requirements-dev.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
pre-commit==2.6.0
|
|
@ -1,3 +1,3 @@
|
||||||
django==3.1
|
django==3.1
|
||||||
pre-commit==2.6.0
|
|
||||||
markdown==3.2.2
|
markdown==3.2.2
|
||||||
|
gunicorn==20.0.4
|
||||||
|
|
Reference in a new issue