Skip to content
This repository was archived by the owner on Oct 8, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
POSTGRES_DB=mememaker
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
DB_HOST=db
DB_PORT=5432

DEBUG=1
SECRET_KEY=foo
STATIC_PATH=/vol/web/static
MEDIA_PATH=/vol/web/media
65 changes: 65 additions & 0 deletions djangoproject/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# FROM python:3.8.5-buster

# LABEL key="MemesBD"

# ADD . /api
# WORKDIR /api
# # You will need this if you need PostgreSQL, otherwise just skip this
# # RUN apk update && apk add postgresql-dev gcc python3-dev musl-dev libffi-dev
# # RUN pip install uwsgi
# RUN pip install -r requirements.txt

# RUN sh initdb.sh
# # RUN python manage.py collectstatic

# ENV PORT=8000
# EXPOSE 8000
# # Runner script here
# # CMD ["/api/runner.sh"]
# # CMD ["gunicorn", "--bind", ":8000", "--workers", "3", "mememaker.wsgi:application"]
# CMD ["python3", "manage.py", "runserver", "0.0.0.0:8000"]


# # docker build -t mememaker -f Dockerfile .
# # docker run -it -p 80:8000 mememaker


FROM subangkar/drf-mememaker:latest

ENV PYTHONDONTWRITEBYTECODE 1 # Prevents Python from writing pyc files to disc
ENV PYTHONUNBUFFERED 1 # Prevents Python from buffering stdout and stderr

ENV PATH="/scripts:${PATH}"
ENV CONTAINER=1

ENV STATIC_PATH=/vol/web/static
ENV MEDIA_PATH=/vol/web/media


# RUN mkdir /app
ADD djangoproject /app
WORKDIR /app


COPY scripts /scripts
RUN chmod +x /scripts/*


COPY .env /app/
COPY djangoproject /app/


RUN mkdir -p $MEDIA_PATH $STATIC_PATH

RUN adduser --disabled-password user

RUN chown -R user:user /vol && \
chmod -R 755 /vol/web

#USER user


RUN find . -path "*/migrations/*.py" -not -name "__init__.py" -delete && \
find . -path "*/migrations/*.pyc" -delete

CMD ["entrypoint.sh"]
1 change: 0 additions & 1 deletion djangoproject/coreapp/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@
urlpatterns = [
path('', include(router.urls)),
path('', include(post_router.urls)),
# path('auth/', include('rest_framework.urls', namespace='rest_framework')),
]
29 changes: 23 additions & 6 deletions djangoproject/mememaker/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '3jjb4s6f!6x@l+g%oga7&k9i^ipj45x@!5*t2_bnd(-7afckw('
SECRET_KEY = os.environ.get('SECRET_KEY', '3jjb4s6f!6x@l+g%oga7&k9i^ipj45x@!5*t2_bnd(-7afckw(')

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
DEBUG = bool(int(os.environ.get('DEBUG', 1)))

ALLOWED_HOSTS = ['*']

Expand Down Expand Up @@ -97,13 +97,25 @@
# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases

DATABASES = {
'default': {
DATABASE_CONFIGS = {
'sqlite': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
},
'postgres': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': os.environ.get('POSTGRES_DB', 'postgres'),
'USER': os.environ.get('POSTGRES_USER', 'postgres'),
'PASSWORD': os.environ.get('POSTGRES_PASSWORD', 'postgres'),
'HOST': os.environ.get('DB_HOST', 'db'),
'PORT': os.environ.get('DB_PORT', '5432'),
}
}

DATABASES = {
'default': DATABASE_CONFIGS['postgres'] if bool(int(os.environ.get('CONTAINER', 0))) else DATABASE_CONFIGS['sqlite']
}

# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators

Expand Down Expand Up @@ -159,12 +171,17 @@
CORS_ORIGIN_REGEX_WHITELIST = [
'http://localhost:8080',
]
STATIC_URL = '/static/'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
# MEDIA_ROOT = '/vol/web/media' if bool(int(os.environ.get('CONTAINER', 0))) else os.path.join(BASE_DIR, 'media')
MEDIA_ROOT = os.environ.get('MEDIA_PATH', os.path.join(BASE_DIR, 'media'))
SITE_ID = 4

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/

STATIC_URL = '/static/'
# STATIC_ROOT = '/vol/web/static' if bool(int(os.environ.get('CONTAINER', 0))) else os.path.join(BASE_DIR, 'static')
STATIC_ROOT = os.environ.get('STATIC_PATH', os.path.join(BASE_DIR, 'static'))
# STATICFILES_DIRS = (
# STATIC_ROOT,
# ) if bool(int(os.environ.get('CONTAINER', 0))) else ()
6 changes: 3 additions & 3 deletions djangoproject/mememaker/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@
url(r'^rest-auth/facebook-connect/$', FacebookConnect.as_view(), name='rest-auth-facebook-connect'),
url(r'^rest-auth/google/$', GoogleLogin.as_view(), name='rest-auth-google-login'),
url(r'^rest-auth/google-connect/$', GoogleConnect.as_view(), name='rest-auth-google-connect'),
# path('api-auth/', include('rest_framework.urls', namespace='rest_framework')),
path('auth/', include('rest_framework.urls', namespace='rest_framework')),

url(r'^swagger(?P<format>\.json|\.yaml)$', schema_view.without_ui(cache_timeout=0), name='schema-json'),
url(r'^swagger/$', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
url(r'^redoc/$', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
]

if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
2 changes: 1 addition & 1 deletion djangoproject/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ django-extra-fields==2.0.5
django-rest-auth==0.9.5
django-sass-processor==0.8
django-sslserver==0.22
django-tagconstants==0.1
djangorestframework==3.11.0
drf-nested-routers==0.91
drf-url-filters==0.5.1
Expand All @@ -28,6 +27,7 @@ MarkupSafe==1.1.1
oauthlib==3.1.0
packaging==20.4
Pillow==7.1.2
psycopg2==2.8.5
pyparsing==2.4.7
python3-openid==3.1.0
pytz==2020.1
Expand Down
22 changes: 22 additions & 0 deletions djangoproject/uwsgi.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[uwsgi]


static-map = /static/=/vol/web/static
static-map = /media/=/vol/web/media

# socket = :8000 # use socket if ngnix is on same machine as server , otherwise use http
http = :8000 # use socket if ngnix is on same machine as server , otherwise use http
module=mememaker.wsgi:application
env=DJANGO_SETTINGS_MODULE=mememaker.settings

enable-threads
wsgi-file mememaker/wsgi.py
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 10
# the socket (use the full path to be safe
# chmod-socket = 664
# clear environment on exit
vacuum = true
60 changes: 60 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
version: '3.7'

volumes:
postgres_data:
static_data:
# frontend_data:

services:
db:
image: postgres
restart: always
volumes:
- postgres_data:/var/lib/postgresql/data/
env_file:
- .env

web:
build:
context: .
dockerfile: djangoproject/Dockerfile
cache_from:
- subangkar/mememaker:initial
image: subangkar/mememaker:initial
volumes:
- static_data:/vol/web
ports:
- 8000:8000 # change also in uwsig ini and ngnix conf upstream
env_file:
- .env
depends_on:
- db
links:
- db:db


# nginx:
# build:
# context: .
# dockerfile: nginx/prod/Dockerfile
# ports:
# - 80:80 # change in ngnix conf
# volumes:
# - static_data:/vol/static
# # - frontend_data:/vol/frontend/static
# # env_file:
# # - nginx/prod/.env.dev
# depends_on:
# - web

# vue:
# build:
# context: .
# dockerfile: frontend/Dockerfile
# env_file:
# - frontend/.env.dev
# volumes:
# - frontend_data:/app
# depends_on:
# - web
# - nginx
16 changes: 16 additions & 0 deletions nginx/prod/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM nginx:latest

RUN rm /etc/nginx/conf.d/default.conf

COPY ./nginx/prod/default.conf /etc/nginx/conf.d/default.conf

COPY ./nginx/prod/uwsgi_params /etc/nginx/uwsgi_params

COPY ./nginx/prod/nginx.conf /etc/nginx/nginx.conf


USER root

RUN mkdir -p /vol/static
RUN chmod 755 /vol/static

45 changes: 45 additions & 0 deletions nginx/prod/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
server {
listen 80;
listen [::]:80;
server_name dev.mememaker.org;

#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;

location / {
root /usr/share/nginx/html;
index index.html index.htm;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
Loading