From f5032fc28657c7ef7b7705237080f54edf0ea471 Mon Sep 17 00:00:00 2001 From: Matheus Fernandes Date: Wed, 6 Dec 2017 17:23:10 -0200 Subject: [PATCH] Initial discourse integration Signed-off-by: Matheus Fernandes --- colab/management/commands/initdb.py | 2 +- docker-compose.yml | 101 ++++++++++++++++-- misc/etc/colab/plugins.d/discourse.py | 21 ++++ misc/etc/colab/widgets.d/discourse_widgets.py | 10 ++ start-colab.sh | 5 + 5 files changed, 132 insertions(+), 7 deletions(-) create mode 100644 misc/etc/colab/plugins.d/discourse.py create mode 100644 misc/etc/colab/widgets.d/discourse_widgets.py diff --git a/colab/management/commands/initdb.py b/colab/management/commands/initdb.py index 347b249e..7791cbd6 100644 --- a/colab/management/commands/initdb.py +++ b/colab/management/commands/initdb.py @@ -13,8 +13,8 @@ class Command(BaseCommand): help = ('Create admin and set site domain') def handle(self, *args, **kwargs): - self.create_admin() self.set_site_domain() + self.create_admin() def set_site_domain(self): site = Site.objects.get_current() diff --git a/docker-compose.yml b/docker-compose.yml index 338ff374..cf0ecf23 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,6 +8,7 @@ services: - colab_assets:/var/labhacker/colab/public:z - audiencias:/var/labhacker/audiencias:z - wikilegis:/var/labhacker/wikilegis:z + - discourse:/var/www/discourse:z ports: - "8000:80" links: @@ -16,17 +17,16 @@ services: NAME_RESOLVER: '127.0.0.11' db: - image: postgres + image: postgres:9.6 environment: POSTGRES_USER: root POSTGRES_PASSWORD: root POSTGRES_DB: root PGDATA : /var/lib/postgresql/data/ volumes: - - colab_data:/var/lib/postgresql/data/ + - pg_data:/var/lib/postgresql/data/ colab: - # build: . image: labhackercd/edemocracia-colab command: ./start-colab.sh environment: @@ -61,8 +61,12 @@ services: SITE_BACKGROUND_IMAGE: '' ENABLE_AUDIENCIAS: 'true' ENABLE_WIKILEGIS: 'true' + ENABLE_DISCOURSE: 'true' AUDIENCIAS_API_KEY: secret_key WIKILEGIS_API_KEY: api_key + DISCOURSE_API_KEY: api_key + DISCOURSE_API_USERNAME: system + DISCOURSE_SSO_SECRET: sso_secret volumes: - colab_assets:/var/labhacker/colab/public:z links: @@ -111,7 +115,12 @@ services: ADMIN_PASSWORD: 123 ADMIN_EMAIL: email@admin.com ADMIN_USERNAME: admin - DATABASE_URL: postgres://root:root@db:5432/audiencias + DATABASE_ENGINE: postgresql_psycopg2 + DATABASE_NAME: audiencias + DATABASE_PASSWORD: root + DATABASE_USER: root + DATABASE_HOST: db + DATABASE_PORT: 5432 DEBUG: 'False' REDIS_SERVER: redis WEBSERVICE_URL: https://infoleg.camara.leg.br/ws-pauta/evento/interativo @@ -155,7 +164,12 @@ services: ADMIN_PASSWORD: 123 ADMIN_EMAIL: email@admin.com ADMIN_USERNAME: admin - DATABASE_URL: postgres://root:root@db:5432/audiencias + DATABASE_ENGINE: postgresql_psycopg2 + DATABASE_NAME: audiencias + DATABASE_PASSWORD: root + DATABASE_USER: root + DATABASE_HOST: db + DATABASE_PORT: 5432 DEBUG: 'False' REDIS_SERVER: redis WEBSERVICE_URL: https://infoleg.camara.leg.br/ws-pauta/evento/interativo @@ -212,11 +226,86 @@ services: depends_on: - db + discourse: + image: labhackercd/discourse-docker + command: ./start-web.sh + volumes: + - discourse:/var/www/discourse + expose: + - "8080" + depends_on: + - db + - redis + - sidekiq + environment: + RAILS_ENV: 'production' + DISCOURSE_DB_HOST: db + DISCOURSE_DB_PORT: '5432' + DISCOURSE_DB_NAME: 'root' + DISCOURSE_DB_USERNAME: 'root' + DISCOURSE_DB_PASSWORD: 'root' + DISCOURSE_HOSTNAME: 'localhost' + DISCOURSE_SMTP_ADDRESS: smtp.gmail.com + DISCOURSE_SMTP_PORT: 587 + DISCOURSE_SMTP_USER_NAME: 'matheuzin@gmail.com' + DISCOURSE_SMTP_PASSWORD: '19930113' + DISCOURSE_DEVELOPER_EMAILS: 'matheus.souza.fernandes@gmail.com' + DISCOURSE_REDIS_HOST: 'redis' + DISCOURSE_REDIS_PORT: 6379 + DISCOURSE_RELATIVE_URL_ROOT: '/expressao' + DISCOURSE_CONTACT_EMAIL: 'matheuzin@gmail.com' + DISCOURSE_CONTACT_URL: 'localhost' + DISCOURSE_NOTIFICATION_EMAIL: 'noreply@dicourse.org' + DISCOURSE_LOGO_URL: '\/images\/d-logo-sketch.png' + DISCOURSE_SMALL_LOGO_URL: '\/images\/d-logo-sketch-small.png' + DISCOURSE_FAVICON_URL: '\/images\/default-favicon.ico' + DISCOURSE_APPLE_TOUCH_ICON_URL: '\/images\/default-apple-touch-icon.png' + DISCOURSE_SSO_URL: 'http:\/\/127.0.0.1:8000' + DISCOURSE_SSO_SECRET: 'sso_secret' + DISCOURSE_FORCE_HOSTNAME: '' + + sidekiq: + image: labhackercd/discourse-docker + command: './start-sidekiq.sh' + depends_on: + - db + - redis + volumes: + - discourse:/var/www/discourse + environment: + RAILS_ENV: 'production' + DISCOURSE_DB_HOST: db + DISCOURSE_DB_PORT: '5432' + DISCOURSE_DB_NAME: 'root' + DISCOURSE_DB_USERNAME: 'root' + DISCOURSE_DB_PASSWORD: 'root' + DISCOURSE_HOSTNAME: 'localhost' + DISCOURSE_SMTP_ADDRESS: smtp.gmail.com + DISCOURSE_SMTP_PORT: 587 + DISCOURSE_SMTP_USER_NAME: 'matheuzin@gmail.com' + DISCOURSE_SMTP_PASSWORD: '19930113' + DISCOURSE_DEVELOPER_EMAILS: 'matheus.souza.fernandes@gmail.com' + DISCOURSE_REDIS_HOST: 'redis' + DISCOURSE_REDIS_PORT: 6379 + DISCOURSE_RELATIVE_URL_ROOT: '/expressao' + DISCOURSE_CONTACT_EMAIL: 'matheuzin@gmail.com' + DISCOURSE_CONTACT_URL: 'localhost' + DISCOURSE_NOTIFICATION_EMAIL: 'noreply@dicourse.org' + DISCOURSE_LOGO_URL: '\/images\/d-logo-sketch.png' + DISCOURSE_SMALL_LOGO_URL: '\/images\/d-logo-sketch-small.png' + DISCOURSE_FAVICON_URL: '\/images\/default-favicon.ico' + DISCOURSE_APPLE_TOUCH_ICON_URL: '\/images\/default-apple-touch-icon.png' + DISCOURSE_SSO_URL: 'http:\/\/127.0.0.1:8000' + DISCOURSE_SSO_SECRET: 'sso_secret' + DISCOURSE_FORCE_HOSTNAME: '' + volumes: - colab_data: + pg_data: driver: local colab_assets: driver: local + discourse: + driver: local audiencias: driver: local wikilegis: diff --git a/misc/etc/colab/plugins.d/discourse.py b/misc/etc/colab/plugins.d/discourse.py new file mode 100644 index 00000000..bfa26ebf --- /dev/null +++ b/misc/etc/colab/plugins.d/discourse.py @@ -0,0 +1,21 @@ +from decouple import config + +name = 'colab_discourse' +verbose_name = 'Colab Discourse Plugin Plugin' + +upstream = 'http://discourse:8080/expressao/' +api_key = config('DISCOURSE_API_KEY') +api_username = config('DISCOURSE_API_USERNAME') +sso_secret = config('DISCOURSE_SSO_SECRET') + +urls = { + 'include': 'colab_discourse.urls', + 'prefix': '^expressao/', + 'login': '/expressao/accounts/login/', +} + +settings_variables = { + 'COLAB_STATICS': [ + '/usr/lib/python2.7/site-packages/colab_discourse/static' + ] +} diff --git a/misc/etc/colab/widgets.d/discourse_widgets.py b/misc/etc/colab/widgets.d/discourse_widgets.py new file mode 100644 index 00000000..67fbcf39 --- /dev/null +++ b/misc/etc/colab/widgets.d/discourse_widgets.py @@ -0,0 +1,10 @@ +from colab.widgets.widget_manager import WidgetManager +from colab_discourse.widgets.home_section import DiscourseHomeSectionWidget +from colab_discourse.widgets.navigation_links import ( + DiscourseNavigationLinksWidget +) + + +WidgetManager.register_widget('home_section', DiscourseHomeSectionWidget()) +WidgetManager.register_widget('navigation_links', + DiscourseNavigationLinksWidget()) diff --git a/start-colab.sh b/start-colab.sh index 18cf3d7f..879d308f 100755 --- a/start-colab.sh +++ b/start-colab.sh @@ -20,6 +20,7 @@ activate_plugin() { [[ -z "${ENABLE_AUDIENCIAS}" ]] && ENABLE_AUDIENCIAS=2 || ENABLE_AUDIENCIAS="${ENABLE_AUDIENCIAS}" [[ -z "${ENABLE_WIKILEGIS}" ]] && ENABLE_WIKILEGIS=2 || ENABLE_WIKILEGIS="${ENABLE_WIKILEGIS}" +[[ -z "${ENABLE_DISCOURSE}" ]] && ENABLE_DISCOURSE=2 || ENABLE_DISCOURSE="${ENABLE_DISCOURSE}" if [[ "$ENABLE_WIKILEGIS" = true ]]; then activate_plugin wikilegis @@ -29,6 +30,10 @@ if [[ "$ENABLE_AUDIENCIAS" = true ]]; then activate_plugin audiencias fi +if [[ "$ENABLE_DISCOURSE" = true ]]; then + activate_plugin discourse +fi + crond while true; do