Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker container-start fix and local setup script #462

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
32 changes: 2 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,10 @@ To install Docker for Mac [click here](https://docs.docker.com/docker-for-mac/in
git clone --recursive https://github.com/Cloud-CV/Fabrik.git && cd Fabrik
```

3. Rename settings/dev.sample.py as settings/dev.py and change credentials in settings/dev.py
3. Run the following script to configure settings to `localhost`

```
cp settings/dev.sample.py settings/dev.py
```

* Change the hostname to ``` localhost ``` in settings/dev.py line 15. It should now look like this:

```
'HOST': os.environ.get("POSTGRES_HOST", 'localhost'),
sh ./settings/local_setup.sh
```

4. Install redis server
Expand All @@ -110,28 +104,6 @@ To install Docker for Mac [click here](https://docs.docker.com/docker-for-mac/in
sudo apt-get install redis-server
```

* Change the hostname to ``` localhost ``` in settings/common.py line 115.

```
"CONFIG": {
# replace redis hostname to localhost if running on local system
"hosts": [("localhost", 6379)],
"prefix": u'fabrik:',
},
```

* Replace celery result backend in settings/common.py line 122 with localhost.

```
CELERY_RESULT_BACKEND = 'redis://localhost:6379/0'
```

* Change celery broker URL and result backend hostname to ``` localhost ``` in ide/celery_app.py, line 8.

```
app = Celery('app', broker='redis://localhost:6379/0', backend='redis://localhost:6379/0', include=['ide.tasks'])
```

5. If you already have Caffe, Keras and TensorFlow installed on your computer, skip this step.
* For Linux users
* Install Caffe, Keras and Tensorflow
Expand Down
1 change: 1 addition & 0 deletions docker/dev/django/container-start.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh
cd /code && \
python manage.py makemigrations caffe_app && \
python manage.py migrate --noinput && \
python manage.py runserver 0.0.0.0:8000
19 changes: 19 additions & 0 deletions ide/celery_app.local.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from __future__ import absolute_import
import os
from celery import Celery
from django.conf import settings

# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings')
app = Celery('app', broker='redis://localhost:6379/0',
backend='redis://localhost:6379/0', include=['ide.tasks'])

# Using a string here means the worker will not have to
# pickle the object when using Windows.
app.config_from_object('settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)


@app.task(bind=True)
def debug_task(self):
print('Request: {0!r}'.format(self.request))
122 changes: 122 additions & 0 deletions settings/common.local.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'ide/static'),
)

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 's9&vp1jq1yzr!1c_temg#v_)j-a)i5+@vbsekmi6pbjl4l1&u@'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ['*']


# Application definition

INSTALLED_APPS = [
'channels',
'caffe_app.apps.CaffeAppConfig',
'keras_app.apps.KerasAppConfig',
'tensorflow_app.apps.TensorflowAppConfig',
'backendAPI.apps.BackendapiConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.github',
'allauth.socialaccount.providers.google'
]

MIDDLEWARE_CLASSES = [
'django.middleware.security.SecurityMiddleware',
'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',
]

ROOT_URLCONF = 'ide.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'ide/templates')],
'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 = 'ide.wsgi.application'

SITE_ID = 1

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

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


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

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

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


AUTHENTICATION_BACKENDS = (
"django.contrib.auth.backends.ModelBackend",
"allauth.account.auth_backends.AuthenticationBackend",
)

LOGIN_REDIRECT_URL = '/'
ACCOUNT_LOGOUT_ON_GET = True


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


CHANNEL_LAYERS = {
"default": {
"BACKEND": "asgi_redis.RedisChannelLayer",
"CONFIG": {
# replace redis hostname to localhost if running on local system
"hosts": [("localhost", 6379)],
"prefix": u'fabrik:',
},
"ROUTING": "ide.routing.channel_routing",
},
}

CELERY_RESULT_BACKEND = 'redis://localhost:6379/0'
18 changes: 18 additions & 0 deletions settings/dev.local.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from .common import * # noqa: ignore=F405
import os

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

DEBUG = True

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': os.environ.get("POSTGRES_NAME", 'postgres'),
'USER': os.environ.get("POSTGRES_USER", 'admin'),
'PASSWORD': os.environ.get("POSTGRES_PASSWORD", 'fabrik'),
'HOST': os.environ.get("POSTGRES_HOST", 'localhost'),
'PORT': os.environ.get("POSTGRES_PORT", 5432),
}
}
4 changes: 4 additions & 0 deletions settings/local_setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
cp ./settings/common.local.py ./settings/common.py
cp ./settings/dev.local.py ./settings/dev.py
cp ./ide/celery_app.local.py ./ide/celery_app.py