Skip to content

Commit

Permalink
Merge pull request #24 from scieloorg/fix-docker-and-settings
Browse files Browse the repository at this point in the history
Fix docker and settings
  • Loading branch information
rafaelpezzuto authored Oct 8, 2021
2 parents 184dc5f + 293060a commit 8a00f0a
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 142 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ RUN pip install -U pip && \
RUN chmod +x /app/docker-entrypoint.sh
RUN chmod +x /app/docker-start-worker.sh

RUN chown -R nobody:nobody /app
USER nobody

EXPOSE 8000

ENTRYPOINT ["/app/docker-entrypoint.sh"]
45 changes: 25 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,25 +132,30 @@ docker-compose up

Variable | Example value | Description
---------|---------------|------------
MINIO_HOST | `172.17.0.2:9000` | MinIO host address
MINIO_ACCESS_KEY | `minioadmin` | MinIO username
MINIO_SECRET_KEY | `minioadmin` | MinIO password
MINIO_TIMEOUT | `10000` | MinIO connection timeout
MINIO_SECURE | `false` | MinIO SSL flag (`true` or `false`)
MINIO_SCIELO_COLLECTION | `spf_brazil` | MinIO collection name
MINIO_SPF_DIR | `packages` | MinIO storage main directory
PID_DATABASE_DSN | `postgresql+psycopg2://postgres:[email protected]:5432/pidmanager` | PID manager (PostgreSQL) string connection
DATABASE_CONNECT_URL | `mongodb`://172.17.0.3:27017/opac | OPAC/Kernel database (MongoDB) string connection
DJANGO_DEBUG | `1` | Django flag to see DEBUG messages)
DJANGO_SECRET_KEY | `my_django_secret_key` |
CELERY_BROKER_URL | `pyamqp://user:pass@host:port` | RabbitMQ address
DATABASE_CONNECT_URL | `mongodb://user:pass@host:port/opac` | OPAC/Kernel database (MongoDB) string connection
DJANGO_ADMIN_TRANSLATE | `1` | Django flag to run `django-admin compile_messages`
DJANGO_ALLOWED_HOSTS | `localhost;127.0.0.1;[::1]` |
POSTGRES_DB | `spf` | SciELO Publishing Framework database name
POSTGRES_USER | `postgres` | SciELO Publishing Framework database user
POSTGRES_PASSWORD | `password` | SciELO Publishing Framework database user password
POSTGRES_HOST | `172.17.0.4` | SciELO Publishing Framework database hostname
POSTGRES_PORT | `5432` | SciELO Publishing Framework database host port
DJANGO_COLLECTSTATIC | `1` |Django flag to run `manage.py collecstatic`
DJANGO_CREATE_SUPERUSER | `1` | Django flag to run `manage.py createsuperuser`
DJANGO_DEBUG | `1` | Django flag to see DEBUG messages
DJANGO_MANAGE_LOAD_GROUP | `1` | Django flag to run `manage.py loaddata group`
DJANGO_MANAGE_LOAD_USER | `1` | Django flag to run `manage.py loaddata user`
DJANGO_MANAGE_MIGRATE | `1` | Django flag to run `managep.py migrate`
DJANGO_MANAGE_LOAD | `1` | Django flag to run `manage.py loaddata group`
DJANGO_ADMIN_TRANSLATE | `1` | Django flag to run `django-admin compile_messages`
CELERY_BROKER_URL | `pyamqp://172.17.0.5:5672` | RabbitMQ address
CELERY_RESULT_BACKEND | `django-db` | Celery flag to use Django Database for persisting messages
DJANGO_SECRET_KEY | | Django secret key
DJANGO_SUPERUSER_EMAIL | | superuser email
DJANGO_SUPERUSER_PASSWORD | | superuser password
DJANGO_SUPERUSER_USERNAME | | superuser username
MINIO_ACCESS_KEY | | MinIO username
MINIO_HOST | `host:port` | MinIO host address
MINIO_SCIELO_COLLECTION | | MinIO collection name
MINIO_SECRET_KEY | | MinIO password
MINIO_SECURE | | MinIO SSL flag (`true` or `false`)
MINIO_SPF_DIR | | MinIO storage main directory
MINIO_TIMEOUT | | MinIO connection timeout
PID_DATABASE_DSN | `postgresql+psycopg2://postgres:password@host:port/database` | PID manager (PostgreSQL) string connection
POSTGRES_DB | `database name` | SciELO Publishing Framework database name
POSTGRES_HOST | `localhost` | SciELO Publishing Framework database hostname
POSTGRES_PASSWORD | | SciELO Publishing Framework database user password
POSTGRES_PORT | | SciELO Publishing Framework database host port
POSTGRES_USER | | SciELO Publishing Framework database user
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ services:
build:
context: .
container_name: 'spf_worker_1'
user: nobody
command: sh docker-start-worker.sh
env_file:
- ./prod.env
Expand All @@ -24,9 +25,8 @@ services:
web:
build: .
container_name: 'spf_web_1'
user: nobody
command: python spf/manage.py runserver 0.0.0.0:8000
volumes:
- ./data:/data
ports:
- 8000:8000
depends_on:
Expand Down
21 changes: 20 additions & 1 deletion docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,36 @@

if [ "$DJANGO_MANAGE_MIGRATE" = "1" ]; then
echo "migrating data ..."
python spf/manage.py makemigrations
python spf/manage.py migrate --noinput
fi

if [ "$DJANGO_MANAGE_LOAD" = "1" ]; then
if [ "$DJANGO_MANAGE_LOAD_GROUP" = "1" ]; then
echo "loading groups ..."
python spf/manage.py loaddata group
fi

if [ "$DJANGO_MANAGE_LOAD_USER" = "1" ]; then
echo "loading users ..."
python spf/manage.py loaddata user
fi

if [ "$DJANGO_CREATE_SUPERUSER" = "1" ]; then
echo "creating superuser ..."
python spf/manage.py createsuperuser \
--noinput \
--username $DJANGO_SUPERUSER_USERNAME \
--email $DJANGO_SUPERUSER_EMAIL
fi

if [ "$DJANGO_ADMIN_TRANSLATE" = "1" ]; then
echo "translanting messages ..."
django-admin compilemessages
fi

if [ "$DJANGO_COLLECTSTATIC" = "1" ]; then
echo "collecting static files ..."
python spf/manage.py collectstatic --noinput
fi

exec "$@"
40 changes: 23 additions & 17 deletions prod.env
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
MINIO_HOST=minio.scielo.br
MINIO_ACCESS_KEY=
MINIO_SECRET_KEY=
MINIO_TIMEOUT=10000
MINIO_SECURE=true
MINIO_SCIELO_COLLECTION=spf_brazil
MINIO_SPF_DIR=packages
CELERY_BROKER_URL=
DATABASE_CONNECT_URL=
DJANGO_DEBUG=0
DJANGO_SECRET_KEY=
DJANGO_ADMIN_TRANSLATE=1
DJANGO_ALLOWED_HOSTS=localhost;0.0.0.0;[::1]
DJANGO_MANAGE_MIGRATE=0
DJANGO_MANAGE_LOAD=0
DJANGO_ADMIN_TRANSLATE=0
POSTGRES_DB=spf
POSTGRES_USER=
DJANGO_COLLECTSTATIC=1
DJANGO_CREATE_SUPERUSER=1
DJANGO_DEBUG=1
DJANGO_MANAGE_LOAD_GROUP=1
DJANGO_MANAGE_LOAD_USER=1
DJANGO_MANAGE_MIGRATE=1
DJANGO_SECRET_KEY=
DJANGO_SUPERUSER_EMAIL=
DJANGO_SUPERUSER_PASSWORD=
DJANGO_SUPERUSER_USERNAME=
MINIO_ACCESS_KEY=
MINIO_HOST=
MINIO_SCIELO_COLLECTION=
MINIO_SECRET_KEY=
MINIO_SECURE=
MINIO_SPF_DIR=
MINIO_TIMEOUT=
POSTGRES_DB=
POSTGRES_HOST=
POSTGRES_PASSWORD=
POSTGRES_HOST=scielo-postgres-1
POSTGRES_PORT=5432
CELERY_BROKER_URL=pyamqp://spf_broker:5672
POSTGRES_PORT=
POSTGRES_USER=
1 change: 0 additions & 1 deletion spf/core/fixtures/validation.json

This file was deleted.

1 change: 0 additions & 1 deletion spf/core/fixtures/validation_schema.json

This file was deleted.

59 changes: 0 additions & 59 deletions spf/core/migrations/0001_initial.py

This file was deleted.

2 changes: 2 additions & 0 deletions spf/core/templates/user/groups_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ <h1 class="h4 pt-5">{% trans 'User groups' %}</h1>
{% endif %}
</div>

{% if user_obj %}
<nav aria-label="User management navigation">
<ul class="pagination justify-content-center">
{% if user_obj.has_previous %}
Expand All @@ -82,5 +83,6 @@ <h1 class="h4 pt-5">{% trans 'User groups' %}</h1>
{% endif %}
</ul>
</nav>
{% endif %}

{% endblock %}
49 changes: 8 additions & 41 deletions spf/spf/settings.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,16 @@
"""
Django settings for spf project.
Generated by 'django-admin startproject' using Django 3.2.5.
For more information on this file, see
https://docs.djangoproject.com/en/3.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.2/ref/settings/
"""
import os
from pathlib import Path
from django.utils.translation import ugettext_lazy as _

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
BASE_DIR = Path(__file__).resolve().parent.parent

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY')

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

ALLOWED_HOSTS = os.environ.get('DJANGO_ALLOWED_HOSTS').split(';')


# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
Expand Down Expand Up @@ -73,10 +53,6 @@

WSGI_APPLICATION = 'spf.wsgi.application'


# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
Expand All @@ -88,10 +64,6 @@
},
}


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

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
Expand All @@ -107,11 +79,7 @@
},
]


# Internationalization
# https://docs.djangoproject.com/en/3.2/topics/i18n/

LANGUAGE_CODE = 'en'
LANGUAGE_CODE = 'pt-br'

LANGUAGES = (
('en', _('English')),
Expand All @@ -128,23 +96,22 @@

USE_TZ = True


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

STATIC_URL = '/static/'

# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

LOGIN_REDIRECT_URL = '/'

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

MEDIA_URL = '/media/'

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

MEDIA_INGRESS_TEMP = os.path.join(BASE_DIR, 'media', 'ingress', 'temp')

CELERY_BROKER_URL = os.environ.get('CELERY_BROKER_URL', 'pyamqp://broker:5672'),

CELERY_RESULT_BACKEND = 'django-db'

0 comments on commit 8a00f0a

Please sign in to comment.