Containerize

This commit is contained in:
R. Miles McCain 2020-04-14 10:55:01 -04:00
parent 783ba5aced
commit db6dee5d69
No known key found for this signature in database
GPG Key ID: 91CB47BDDF2671A5
6 changed files with 61 additions and 3 deletions

24
Dockerfile Normal file
View File

@ -0,0 +1,24 @@
FROM python:3
WORKDIR /usr/src/shynet
RUN pip install pipenv
COPY Pipfile.lock ./
COPY Pipfile ./
RUN pipenv install --system --deploy
COPY shynet .
RUN python manage.py collectstatic --noinput
ARG GF_UID="500"
ARG GF_GID="500"
# add group & user
RUN groupadd -r -g $GF_GID appgroup && \
useradd appuser -r -u $GF_UID -g appgroup
USER appuser
EXPOSE 8080
CMD [ "./webserver.sh" ]

View File

@ -10,6 +10,7 @@ black = "*"
django = "*"
django-allauth = "*"
geoip2 = "*"
whitenoise = "*"
celery = "*"
django-ipware = "*"
pyyaml = "*"
@ -17,6 +18,7 @@ ua-parser = "*"
user-agents = "*"
emoji-country-flag = "*"
rules = "*"
gunicorn = "*"
[requires]
python_version = "3.6"

18
Pipfile.lock generated
View File

@ -1,7 +1,7 @@
{
"_meta": {
"hash": {
"sha256": "14b7afb8af8c07320e7c765ae013966a5e95dd708a23f056981378beca52846d"
"sha256": "c1d7cd1455c79f65e139ba93673e58446c8094311b329be28d44d23fd5510462"
},
"pipfile-spec": 6,
"requires": {
@ -104,6 +104,14 @@
"index": "pypi",
"version": "==3.0.0"
},
"gunicorn": {
"hashes": [
"sha256:1904bb2b8a43658807108d59c3f3d56c2b6121a701161de0ddf9ad140073c626",
"sha256:cd4a810dd51bf497552cf3f863b575dabd73d6ad6a91075b65936b151cbf4f9c"
],
"index": "pypi",
"version": "==20.0.4"
},
"idna": {
"hashes": [
"sha256:7588d1c14ae4c77d74036e8c22ff447b26d0fde8f007354fd48a7814db15b7cb",
@ -228,6 +236,14 @@
],
"version": "==1.3.0"
},
"whitenoise": {
"hashes": [
"sha256:0f9137f74bd95fa54329ace88d8dc695fbe895369a632e35f7a136e003e41d73",
"sha256:62556265ec1011bd87113fb81b7516f52688887b7a010ee899ff1fd18fd22700"
],
"index": "pypi",
"version": "==5.0.1"
},
"zipp": {
"hashes": [
"sha256:aa36550ff0c0b7ef7fa639055d797116ee891440eac1a56f378e2d3179e0320b",

5
shynet/celeryworker.sh Executable file
View File

@ -0,0 +1,5 @@
#!/bin/bash
# Start queue worker processes
echo Launching Shynet queue worker...
exec celery -A shynet worker -E --loglevel=INFO --concurrency=3

View File

@ -54,6 +54,7 @@ INSTALLED_APPS = [
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"whitenoise.middleware.WhiteNoiseMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
@ -124,6 +125,9 @@ USE_TZ = True
# https://docs.djangoproject.com/en/2.2/howto/static-files/
STATIC_URL = "/static/"
STATIC_ROOT = "compiledstatic/"
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
# Auth
@ -150,8 +154,7 @@ SITE_ID = 1
# Celery
if DEBUG:
CELERY_TASK_ALWAYS_EAGER = True
CELERY_TASK_ALWAYS_EAGER = True
CELERY_BROKER_URL = os.getenv("CELERY_BROKER_URL")
CELERY_REDIS_SOCKET_TIMEOUT = 15

8
shynet/webserver.sh Executable file
View File

@ -0,0 +1,8 @@
#!/bin/bash
# Start Gunicorn processes
echo Launching Shynet web server...
exec gunicorn shynet.wsgi:application \
--bind 0.0.0.0:8080 \
--workers 3 \
--timeout 100