entrypoint.sh 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. #!/usr/bin/env sh
  2. ## Config
  3. if [ ! -f "/srv/app/personalsite/settings.py" ]; then
  4. # generate config
  5. cat > /srv/app/personalsite/settings.py <<- EOF
  6. """
  7. Django settings for personalsite project.
  8. Generated by 'django-admin startproject' using Django 2.1.2.
  9. For more information on this file, see
  10. https://docs.djangoproject.com/en/2.1/topics/settings/
  11. For the full list of settings and their values, see
  12. https://docs.djangoproject.com/en/2.1/ref/settings/
  13. """
  14. import os
  15. # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
  16. BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  17. # Quick-start development settings - unsuitable for production
  18. # See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/
  19. # SECURITY WARNING: keep the secret key used in production secret!
  20. SECRET_KEY = '${SECRET_KEY:-8$oylik7o2-dbx+5a77=2a532w8lx&=ofiyv!1bs9a9)0t%6r2}'
  21. # SECURITY WARNING: don't run with debug turned on in production!
  22. DEBUG = ${APP_DEBUG:-False}
  23. ALLOWED_HOSTS = ["${WEB_SITE_URL:-example.com}", "localhost", "127.0.0.1", "0.0.0.0", "django"]
  24. # Application definition
  25. INSTALLED_APPS = [
  26. 'django.contrib.admin',
  27. 'django.contrib.auth',
  28. 'django.contrib.contenttypes',
  29. 'django.contrib.sessions',
  30. 'django.contrib.messages',
  31. 'django.contrib.staticfiles',
  32. 'core',
  33. 'project.apps.ProjectConfig',
  34. 'social.apps.SocialConfig',
  35. 'django_cleanup.apps.CleanupConfig',
  36. ]
  37. MIDDLEWARE = [
  38. 'django.middleware.security.SecurityMiddleware',
  39. 'django.contrib.sessions.middleware.SessionMiddleware',
  40. 'django.middleware.common.CommonMiddleware',
  41. 'django.middleware.csrf.CsrfViewMiddleware',
  42. 'django.contrib.auth.middleware.AuthenticationMiddleware',
  43. 'django.contrib.messages.middleware.MessageMiddleware',
  44. 'django.middleware.clickjacking.XFrameOptionsMiddleware',
  45. ]
  46. ROOT_URLCONF = 'personalsite.urls'
  47. TEMPLATES = [
  48. {
  49. 'BACKEND': 'django.template.backends.django.DjangoTemplates',
  50. 'DIRS': [],
  51. 'APP_DIRS': True,
  52. 'OPTIONS': {
  53. 'context_processors': [
  54. 'django.template.context_processors.debug',
  55. 'django.template.context_processors.request',
  56. 'django.contrib.auth.context_processors.auth',
  57. 'django.contrib.messages.context_processors.messages',
  58. 'social.processors.ctx_dict',
  59. ],
  60. },
  61. },
  62. ]
  63. WSGI_APPLICATION = 'personalsite.wsgi.application'
  64. # Database
  65. # https://docs.djangoproject.com/en/2.1/ref/settings/#databases
  66. DATABASES = {
  67. 'default': {
  68. 'ENGINE': 'django.db.backends.postgresql_psycopg2',
  69. 'NAME': '${NAME_DB:-site}',
  70. 'USER': '${USER_DB:-site}',
  71. 'PASSWORD': '${PASS_DB:-site}',
  72. 'HOST': '${HOST_DB:-127.0.0.1}',
  73. 'PORT': '${PORT_DB:-5432}',
  74. }
  75. }
  76. # Password validation
  77. # https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators
  78. AUTH_PASSWORD_VALIDATORS = [
  79. {
  80. 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
  81. },
  82. {
  83. 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
  84. },
  85. {
  86. 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
  87. },
  88. {
  89. 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
  90. },
  91. ]
  92. # Internationalization
  93. # https://docs.djangoproject.com/en/2.1/topics/i18n/
  94. LANGUAGE_CODE = 'es'
  95. TIME_ZONE = 'UTC'
  96. USE_I18N = True
  97. USE_L10N = True
  98. USE_TZ = True
  99. # Static files (CSS, JavaScript, Images)
  100. # https://docs.djangoproject.com/en/2.1/howto/static-files/
  101. STATIC_URL = '/static/'
  102. STATIC_ROOT = os.path.join(BASE_DIR, 'static')
  103. # Media files
  104. MEDIA_URL = '/media/'
  105. MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
  106. # Incoming Email
  107. EMAIL_FROM = '${EMAIL_FROM:-noreply@example.com}'
  108. EMAIL_TO = '${EMAIL_TO:-user@example.com}'
  109. # Email config
  110. EMAIL_HOST = '${EMAIL_HOST:-smtp.example.com}'
  111. EMAIL_HOST_USER = '${EMAIL_HOST_USER:-username}'
  112. EMAIL_HOST_PASSWORD = '${EMAIL_HOST_PASSWORD:-password}'
  113. EMAIL_PORT = '${EMAIL_HOST_PORT:-587}'
  114. EMAIL_USE_TLS = ${EMAIL_USE_TLS:-True}
  115. EOF
  116. fi
  117. mkdir -p /srv/app/core/static/core/css || true
  118. sassc -t compressed /srv/app/core/static/core/sass/estilos.sass /srv/app/core/static/core/css/estilos.min.css
  119. cd /srv/app || exit
  120. /usr/local/bin/python3 manage.py makemigrations --no-input
  121. /usr/local/bin/python3 manage.py migrate --no-input
  122. /usr/local/bin/python3 manage.py collectstatic --no-input
  123. gunicorn -b "0.0.0.0:${GUNICORN_PORT_NUMBER:-8080}" --timeout "${GUNICORN_TIMEOUT:-30}" --workers "${GUNICORN_NUM_WORKERS:-4}" personalsite.wsgi &
  124. exec nginx -g "daemon off;"