Commit 80c9e24b by Maxime

First commit

parents
Pipeline #93 failed with stage
in 0 seconds
[run]
branch = True
/venv/
*.pyc
.project
.pydevproject
local_settings.py
/static
.settings/
.idea/
.coverage
htmlcov/
\ No newline at end of file
build:
script:
- ./set_env.bash
- ./build_docker_images.bash
FROM grahamdumpleton/mod-wsgi-docker:python-3.4
WORKDIR /app
COPY requirements.txt /app
RUN mod_wsgi-docker-build
COPY manage.py /app
COPY {{ project_name }} /app/{{ project_name }}/
COPY .coveragerc /app
RUN python manage.py collectstatic --noinput
EXPOSE 80
ENTRYPOINT [ "mod_wsgi-docker-start" ]
CMD [ "--url-alias", "/static", "static", "{{ project_name }}/wsgi.py" ]
\ No newline at end of file
{{ project_name }}
==================
\ No newline at end of file
#!/bin/bash
API_IMAGE="{{ project_name | lower }}"
API_CONTAINER="{{ project_name | lower }}"
API_TEST_CONTAINER="{{ project_name | lower }}-test"
function log_info {
echo -e "\e[44m$1\e[49m"
}
function log_error {
echo -e "\e[101m$1\e[49m"
}
function stop_on_error {
if [[ $1 -ne 0 ]]; then
log_error "$2"
exit 1
fi
}
function stop_container {
NB_CONTAINER=`docker ps -f name=$1 | wc -l`
if [[ $NB_CONTAINER -gt 1 ]]; then
log_info "Stop $1"
docker stop $1
stop_on_error $? "Docker stop failed"
fi
}
function remove_container {
stop_container $1
NB_CONTAINER=`docker ps -af name=$1 | wc -l`
if [[ $NB_CONTAINER -gt 1 ]]; then
log_info "Remove $1"
docker rm $1
stop_on_error $? "Docker rm failed"
fi
}
log_info "Build images"
docker build -t $API_IMAGE .
stop_on_error $? "Docker build failed"
remove_container "$API_TEST_CONTAINER"
log_info "Run tests"
docker run -d --name $API_TEST_CONTAINER $API_IMAGE
docker exec $API_TEST_CONTAINER coverage run manage.py test --noinput
stop_on_error $? "Tests failed"
docker exec $API_TEST_CONTAINER coverage report --skip-covered
remove_container "$API_TEST_CONTAINER"
remove_container "$API_CONTAINER"
log_info "Run image"
docker run -d -p 8000:80 --name $API_CONTAINER $API_IMAGE
stop_on_error $? "Docker run failed"
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'some-secret'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
# SECURITY WARNING: don't run cors_with origin_allow_all turned on in production!
CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_CREDENTIALS = True
# Use PyMySQL as engine, since it supports python 3
try:
import pymysql
pymysql.install_as_MySQLdb()
except ImportError:
pass
# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'DB_ENGINE',
'NAME': 'DB_NAME',
'USER': 'DB_USER',
'PASSWORD': 'DB_PASSWD',
'HOST': 'DB_HOST',
'PORT': 'DB_PORT'
}
}
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/
STATIC_ROOT = 'static/'
STATIC_URL = '/static/'
"""
Django settings for ludikafee_api project.
Generated by 'django-admin startproject' using Django 1.8.5.
For more information on this file, see
https://docs.djangoproject.com/en/1.8/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.8/ref/settings/
"""
try:
from logs_viewer.local_settings import *
except ImportError as e:
pass
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
'corsheaders.middleware.CorsMiddleware',
)
ROOT_URLCONF = 'logs_viewer.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'logs_viewer.wsgi.application'
# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
TEST_RUNNER = 'django.test.runner.DiscoverRunner'
REST_FRAMEWORK = {
# Use Django's standard `django.contrib.auth` permissions,
# or allow read-only access for unauthenticated users.
# 'DEFAULT_PERMISSION_CLASSES': [
# 'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
# ],
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.BasicAuthentication',
'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
],
'UNICODE_JSON': True,
'PAGE_SIZE': 10,
'NON_FIELD_ERRORS_KEY': 'global',
'TEST_REQUEST_DEFAULT_FORMAT': 'json'
}
JWT_AUTH = {
'JWT_ALLOW_REFRESH': True
}
JWT_AUTH_HEADER_PREFIX = 'JWT '
"""esteren_manager_api URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/1.9/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
]
"""
WSGI config for esteren_manager_api project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.9/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project_name.settings")
application = get_wsgi_application()
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "logs_viewer.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
#!/bin/bash
sed "s|some-secret|$SECRET_KEY|" {{ project_name }}/local_settings_example.py | \
sed "s|DB_ENGINE|$DB_ENGINE|" | \
sed "s|DB_NAME|$DB_NAME|" | \
sed "s|DB_HOST|$DB_HOST|" | \
sed "s|DB_PASSWD|$DB_PASSWD|" | \
sed "s|DB_USER|$DB_USER|" | \
sed "s|DB_PORT|$DB_PORT|" >> {{ project_name }}/local_settings.py
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment