zulip / docker-zulip

Container configurations, images, and examples for Zulip.
https://zulip.com/
Apache License 2.0
559 stars 236 forks source link

Exited with code 1 during zulip launch #61

Closed reyman closed 8 years ago

reyman commented 8 years ago

Hi, I have some problem with settings of docker compose in dev version. I'm waiting release to retry.

But i have also some problem with 1.3.9 and postgres role :

zulip_1     | ..(Re)creating database structure ...
zulip_1     | Setting up the database, schema and user ...
database_1  | ERROR:  permission denied to create role
database_1  | STATEMENT:  CREATE USER zulip;
zulip_1     | ERROR:  permission denied to create role
zulip_1     | ALTER ROLE
database_1  | ERROR:  database "zulip" already exists
database_1  | STATEMENT:  CREATE DATABASE zulip OWNER=zulip;
zulip_1     | ERROR:  database "zulip" already exists
database_1  | ERROR:  schema "zulip" already exists
database_1  | STATEMENT:  CREATE SCHEMA zulip AUTHORIZATION zulip;
zulip_1     | ERROR:  schema "zulip" already exists
zulip_1     | Creating tsearch_extras extension ...
database_1  | FATAL:  password authentication failed for user "postgres"
database_1  | DETAIL:  User "postgres" has no password assigned.
database_1  |   Connection matched pg_hba.conf line 94: "host all all 0.0.0.0/0 md5"
zulip_1     | psql: FATAL:  password authentication failed for user "postgres"

And later

zulip_1     | Initializing Zulip Voyager database ...
database_1  | ERROR:  duplicate key value violates unique constraint "zerver_realm_domain_key"
database_1  | DETAIL:  Key (domain)=(zulip.com) already exists.
database_1  | STATEMENT:  INSERT INTO "zerver_realm" ("domain", "name", "restricted_to_domain", "invite_required", "invite_by_admins_only", "mandatory_topics", "show_digest_email", "nam
e_changes_disabled", "date_created", "notifications_stream_id", "deactivated") VALUES ('zulip.com', NULL, true, false, false, false, true, false, '2016-03-06T12:59:11.309132+00:00'::tim
estamptz, NULL, false) RETURNING "zerver_realm"."id"
zulip_1     | Traceback (most recent call last):
zulip_1     |   File "/home/zulip/deployments/current/manage.py", line 24, in <module>
zulip_1     |     execute_from_command_line(sys.argv)
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/core/management/__init__.py", line 338, in execute_from_command_line                                                [0/614]
zulip_1     |     utility.execute()
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/core/management/__init__.py", line 330, in execute
zulip_1     |     self.fetch_command(subcommand).run_from_argv(self.argv)
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/core/management/base.py", line 393, in run_from_argv
zulip_1     |     self.execute(*args, **cmd_options)
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/core/management/base.py", line 444, in execute
zulip_1     |     output = self.handle(*args, **options)
zulip_1     |   File "/home/zulip/deployments/2015-11-18-18-57-23/zerver/management/commands/initialize_voyager_db.py", line 39, in handle
zulip_1     |     Realm.objects.create(domain="zulip.com")
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/db/models/manager.py", line 127, in manager_method
zulip_1     |     return getattr(self.get_queryset(), name)(*args, **kwargs)
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/db/models/query.py", line 348, in create
zulip_1     |     obj.save(force_insert=True, using=self.db)
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/db/models/base.py", line 710, in save
zulip_1     |     force_update=force_update, update_fields=update_fields)
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/db/models/base.py", line 738, in save_base
zulip_1     |     updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/db/models/base.py", line 822, in _save_table
zulip_1     |     result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/db/models/base.py", line 861, in _do_insert
zulip_1     |     using=using, raw=raw)
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/db/models/manager.py", line 127, in manager_method
zulip_1     |     return getattr(self.get_queryset(), name)(*args, **kwargs)
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/db/models/query.py", line 922, in _insert
zulip_1     |     return query.get_compiler(using=using).execute_sql(return_id)
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/db/models/sql/compiler.py", line 986, in execute_sql
zulip_1     |     cursor.execute(sql, params)
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/db/backends/utils.py", line 64, in execute
zulip_1     |     return self.cursor.execute(sql, params)
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/db/utils.py", line 97, in __exit__
zulip_1     |     six.reraise(dj_exc_type, dj_exc_value, traceback)
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/db/backends/utils.py", line 64, in execute
zulip_1     |     return self.cursor.execute(sql, params)
zulip_1     |   File "/home/zulip/deployments/2015-11-18-18-57-23/zerver/lib/db.py", line 23, in execute
zulip_1     |     return wrapper_execute(self, super(TimeTrackingCursor, self).execute, query, vars)
zulip_1     |   File "/home/zulip/deployments/2015-11-18-18-57-23/zerver/lib/db.py", line 11, in wrapper_execute
zulip_1     |     return action(sql, params)
zulip_1     | django.db.utils.IntegrityError: duplicate key value violates unique constraint "zerver_realm_domain_key"
zulip_1     | DETAIL:  Key (domain)=(zulip.com) already exists.
zulip_1     | 
zulip_1     | Zulip first start init failed in "initialize_voyager_db" with exit code 0.
zulip_zulip_1 exited with code 0

The gist : https://gist.github.com/reyman/4d5a8910a3c7c6217025

I need to remove old volume ? If zulip user and db exist, why not reuse it ?

galexrt commented 8 years ago

Until version 1.3.9-* the environment variables have to be in format like ZULIP_SETTINGS_*. The format SETTING_* is used in 1.3.10+ but due to a PR at the zulip project that is still pending merge, I couldn't release 1.3.10 yet.

What docker image version are you using?

reyman commented 8 years ago

I have problem with dev version to find the good value for docker-compose.yml, so i return to 1.3.9, with ZULIP_SETTINGS_*

galexrt commented 8 years ago

The dev version isn't supposed to be working ;)

I'm currently working on releasing the 1.3.10 version soon.

reyman commented 8 years ago

Great, so i try to reinstall when 1.3.10 is out :) It's more a question about documentation but we can use any existing image of postgres image for link with zulip ?

galexrt commented 8 years ago

@reyman Could you please test again with image dev-1.3.10? If you encounter any bugs please report them here.

The image is currently building, in about 20 minutes the image should be built and you can test it.

reyman commented 8 years ago

Ok, i have this error on docker-compose up :

database_1  | Initializing datadir...
zulip_1     | /sbin/entrypoint.sh: line 61: =/etc/zulip/settings.py: No such file or directory
zulip_zulip_1 exited with code 1
galexrt commented 8 years ago

@reyman I pushed a fix for that error. In about 20 minutes you can repull and try again. Thanks for testing it!

reyman commented 8 years ago

I try to repull the image dev-1.3.10, but it say to me that image "is up to date"; Building is finished ?

galexrt commented 8 years ago

@reyman The Image build process on quay.io is stuck. Can you try with the docker hub image? https://hub.docker.com/r/galexrt/zulip/

reyman commented 8 years ago

@Galexrt another error at launch :

zulip_1     | === Begin Initial Configuration Phase ===
zulip_1     | Preparing and linking the uploads folder ...
zulip_1     | Prepared and linked the uploads directory.
zulip_1     | Executing nginx configuration ...
zulip_1     | Nginx configuration succeeded.
zulip_1     | Exectuing certificates configuration...
zulip_1     | Certificates configuration succeeded.
zulip_1     | Setting Zulip secrets ...
zulip_1     | Secrets already generated.
zulip_1     | Secret found for "rabbitmq_password".
zulip_1     | Secret found for "email_password".
zulip_1     | Zulip secrets configuration succeeded.
zulip_1     | Setting database configuration ...
zulip_1     | Setting key "DATABASES", type "array" in file "/home/zulip/deployments/current/zproject/settings.py".
zulip_1     | sed: can't read /usr/local/bin/process_fts_updates: No such file or directory
zulip_zulip_1 exited with code 2
galexrt commented 8 years ago

@reyman Sorry, for the late response, I looked into the problem and I just pushed the fix. The image should be built in about 45 minutes.

Thanks for testing! :)

Please report back if it's working or there are other issues.

reyman commented 8 years ago

Hum, i have another error :

zulip_1     | Empty var for key "EXTERNAL_HOST".
zulip_1     | Empty var for key "EMAIL_HOST".
zulip_1     | Empty var for key "AUTH_LDAP_BIND_DN".
zulip_1     | Empty var for key "NOREPLY_EMAIL_ADDRESS".
zulip_1     | Empty var for key "AUTH_LDAP_SERVER_URI".
zulip_1     | Empty var for key "ZULIP_ADMINISTRATOR".
zulip_1     | Empty var for key "REDIS_HOST".
zulip_1     | Empty var for key "AUTH_LDAP_BIND_PASSWORD".
zulip_1     | Empty var for key "RABBITMQ_HOST".
zulip_1     | Empty var for key "EMAIL_HOST_USER".
zulip_1     | Empty var for key "DEFAULT_FROM_EMAIL".
zulip_1     | Empty var for key "MEMCACHED_LOCATION".
zulip_1     | Empty var for key "AUTH_LDAP_APPEND_DOMAIN".
zulip_1     | Empty var for key "ADMIN_DOMAIN".
database_1  | Initializing certdir...
database_1  | Initializing logdir...
database_1  | Initializing rundir...
database_1  | Setting resolv ACLs...
zulip_1     | Error: You must set EXTERNAL_HOST in /etc/zulip/settings.py.
zulip_zulip_1 exited with code 1

My settings are set in docker-compose.yml :

SETTING_MEMCACHED_LOCATION: "memcached:11211"
SETTING_RABBITMQ_HOST: "rabbitmq"
SETTING_REDIS_HOST: "redis"
SETTING_EXTERNAL_HOST: "team.comnmodel.org"
SETTING_ZULIP_ADMINISTRATOR: "rey@gmail.com"
SETTING_ADMIN_DOMAIN: "comnmodel.org"
SETTING_NOREPLY_EMAIL_ADDRESS: "noreply@comnmodel.org"
SETTING_DEFAULT_FROM_EMAIL: "Zulip <noreply@comnmodel.org>"
SETTING_EMAIL_HOST: "smtp.gmail.com"
SETTING_EMAIL_HOST_USER: "rey@gmail.com"
galexrt commented 8 years ago

@reyman I fixed this bug now. Image should be built in about 30 minutes.

Thanks for testing!

reyman commented 8 years ago

Another


zulip_1     | === Begin Initial Configuration Phase ===
zulip_1     | Preparing and linking the uploads folder ...
zulip_1     | Prepared and linked the uploads directory.
zulip_1     | Executing nginx configuration ...
zulip_1     | Nginx configuration succeeded.
zulip_1     | Exectuing certificates configuration...
zulip_1     | Certificates configuration succeeded.
zulip_1     | Setting Zulip secrets ...
zulip_1     | Secrets already generated.
zulip_1     | Secret found for "rabbitmq_password".
zulip_1     | Secret found for "email_password".
zulip_1     | Zulip secrets configuration succeeded.
zulip_1     | Setting database configuration ...
zulip_1     | Setting key "DATABASES", type "array" in file "/home/zulip/deployments/current/zproject/settings.py".
zulip_1     | Database configuration succeeded.
zulip_1     | Setting caches configuration ...
zulip_1     | Setting key "MEMCACHED_LOCATION", type "string" in file "/etc/zulip/settings.py".
zulip_1     | Caches configuration succeeded.
zulip_1     | Activating authentication backends ...
database_1  | Initializing logdir...
zulip_1     | Setting key "AUTHENTICATION_BACKENDS", type "array" in file "/etc/zulip/settings.py".
zulip_1     | Adding authentication backend "ZulipLDAPAuthBackend".
zulip_1     | Authentication backend activation succeeded.
zulip_1     | Setting LDAP settings if set ...
zulip_1     | Setting key "AUTH_LDAP_USER_SEARCH", type "array" in file "/etc/zulip/settings.py".
zulip_1     | LDAP settings set.
zulip_1     | Executing Zulip configuration ...
zulip_1     | No FILE given for setConfigurationValue.
database_1  | Initializing rundir...
database_1  | Setting resolv ACLs...
zulip_zulip_1 exited with code 1
galexrt commented 8 years ago

@reyman I pushed another fix. As always image should be built in about 25-30 minutes.

reyman commented 8 years ago

Another, problem of file permission it seems :

zulip_1     | FILE=/etc/zulip/settings.py: ERROR: cannot open `FILE=/etc/zulip/settings.py' (No such file or directory)
zulip_zulip_1 exited with code 1
galexrt commented 8 years ago

@reyman Could you please post more output of the last error you got.

reyman commented 8 years ago

@Galexrt yes

Attaching to zulip_redis_1, zulip_memcached_1, zulip_rabbitmq_1, zulip_database_1, zulip_zulip_1
redis_1     | Starting redis-server...
redis_1     |                 _._                                                  
redis_1     |            _.-``__ ''-._                                             
redis_1     |       _.-``    `.  `_.  ''-._           Redis 2.8.4 (00000000/0) 64 bit
redis_1     |   .-`` .-```.  ```\/    _.,_ ''-._                                   
redis_1     |  (    '      ,       .-`  | `,    )     Running in stand alone mode
redis_1     |  |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
redis_1     |  |    `-._   `._    /     _.-'    |     PID: 1
redis_1     |   `-._    `-._  `-./  _.-'    _.-'                                   
redis_1     |  |`-._`-._    `-.__.-'    _.-'_.-'|                                  
redis_1     |  |    `-._`-._        _.-'_.-'    |           http://redis.io        
redis_1     |   `-._    `-._`-.__.-'_.-'    _.-'                                   
redis_1     |  |`-._`-._    `-.__.-'    _.-'_.-'|                                  
redis_1     |  |    `-._`-._        _.-'_.-'    |                                  
redis_1     |   `-._    `-._`-.__.-'_.-'    _.-'                                   
redis_1     |       `-._    `-.__.-'    _.-'                                       
redis_1     |           `-._        _.-'                                           
redis_1     |               `-.__.-'                                               
redis_1     | 
redis_1     | [1] 09 Mar 14:05:15.744 # Server started, Redis version 2.8.4
redis_1     | [1] 09 Mar 14:05:15.744 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overco
mmit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
redis_1     | [1] 09 Mar 14:05:15.744 * DB loaded from disk: 0.000 seconds
redis_1     | [1] 09 Mar 14:05:15.744 * The server is now ready to accept connections on port 6379
redis_1     | [1] 09 Mar 14:05:15.744 * The server is now ready to accept connections at /var/run/redis/redis.sock
database_1  | Initializing datadir...
database_1  | Initializing datadir...
zulip_1     | === Begin Initial Configuration Phase ===
zulip_1     | Preparing and linking the uploads folder ...
zulip_1     | Prepared and linked the uploads directory.
zulip_1     | Executing nginx configuration ...
zulip_1     | Nginx configuration succeeded.
zulip_1     | Exectuing certificates configuration...
zulip_1     | Certificates configuration succeeded.
zulip_1     | Setting Zulip secrets ...
zulip_1     | Secrets already generated.
zulip_1     | Secret found for "rabbitmq_password".
zulip_1     | Secret found for "email_password".
zulip_1     | Zulip secrets configuration succeeded.
zulip_1     | Setting database configuration ...
zulip_1     | Setting key "DATABASES", type "array" in file "/home/zulip/deployments/current/zproject/settings.py".
zulip_1     | Database configuration succeeded.
zulip_1     | Setting caches configuration ...
zulip_1     | Setting key "MEMCACHED_LOCATION", type "string" in file "/etc/zulip/settings.py".
zulip_1     | Caches configuration succeeded.
zulip_1     | Activating authentication backends ...
zulip_1     | Setting key "AUTHENTICATION_BACKENDS", type "array" in file "/etc/zulip/settings.py".
zulip_1     | Adding authentication backend "ZulipLDAPAuthBackend".
zulip_1     | Authentication backend activation succeeded.
zulip_1     | Setting LDAP settings if set ...
zulip_1     | Setting key "AUTH_LDAP_USER_SEARCH", type "array" in file "/etc/zulip/settings.py".
zulip_1     | LDAP settings set.
zulip_1     | Executing Zulip configuration ...
zulip_1     | Setting key "EXTERNAL_HOST", type "string" in file "/home/zulip/deployments/current/zproject/settings.py".
zulip_1     | Setting key "EMAIL_HOST", type "string" in file "/home/zulip/deployments/current/zproject/settings.py".
zulip_1     | Setting key "AUTH_LDAP_BIND_DN", type "string" in file "/home/zulip/deployments/current/zproject/settings.py".
zulip_1     | Setting key "NOREPLY_EMAIL_ADDRESS", type "string" in file "/home/zulip/deployments/current/zproject/settings.py".
zulip_1     | Setting key "AUTH_LDAP_SERVER_URI", type "string" in file "/home/zulip/deployments/current/zproject/settings.py".
zulip_1     | Setting key "ZULIP_ADMINISTRATOR", type "string" in file "/home/zulip/deployments/current/zproject/settings.py".
zulip_1     | Setting key "REDIS_HOST", type "string" in file "/home/zulip/deployments/current/zproject/settings.py".
zulip_1     | Setting key "AUTH_LDAP_BIND_PASSWORD", type "string" in file "/home/zulip/deployments/current/zproject/settings.py".
zulip_1     | Setting key "RABBITMQ_HOST", type "string" in file "/home/zulip/deployments/current/zproject/settings.py".
zulip_1     | Setting key "EMAIL_HOST_USER", type "string" in file "/home/zulip/deployments/current/zproject/settings.py".
zulip_1     | Setting key "DEFAULT_FROM_EMAIL", type "string" in file "/home/zulip/deployments/current/zproject/settings.py".
zulip_1     | Setting key "MEMCACHED_LOCATION", type "string" in file "/home/zulip/deployments/current/zproject/settings.py".
zulip_1     | Setting key "AUTH_LDAP_APPEND_DOMAIN", type "string" in file "/home/zulip/deployments/current/zproject/settings.py".
zulip_1     | FILE=/etc/zulip/settings.py: ERROR: cannot open `FILE=/etc/zulip/settings.py' (No such file or directory)
zulip_zulip_1 exited with code 1
galexrt commented 8 years ago

Can you add the environment variable DEBUG=true to your docker-compose.yml, so it hopefully shows me more output.

galexrt commented 8 years ago

@reyman This should finally fix the problem. Could you please test it again now? Image should be built in about 25 minutes.

galexrt commented 8 years ago

@reyman I fixed some some other bugs with the latest commit. Image is built in about 45 minutes.

reyman commented 8 years ago

@Galexrt another error :

zulip_1     | Running migrations:
zulip_1     |   Rendering model states... DONE
zulip_1     |   Applying zerver.0006_zerver_userprofile_email_upper_idx... OK
zulip_1     |   Applying zerver.0007_userprofile_is_bot_active_indexes... OK
zulip_1     |   Applying zerver.0008_preregistrationuser_upper_email_idx... OK
zulip_1     | Creating Zulip cache and third_party_api_results tables ...
zulip_1     | Cache table 'third_party_api_results' already exists.
zulip_1     | Initializing Zulip Voyager database ...
database_1  | ERROR:  duplicate key value violates unique constraint "zerver_realm_domain_key"
database_1  | DETAIL:  Key (domain)=(zulip.com) already exists.
database_1  | STATEMENT:  INSERT INTO "zerver_realm" ("domain", "name", "restricted_to_domain", "invite_required", "invite_by_admins_only", "mandatory_topics", "sho
w_digest_email", "name_changes_disabled", "date_created", "notifications_stream_id", "deactivated") VALUES ('zulip.com', NULL, true, false, false, false, true, fals
e, '2016-03-09T14:57:42.000417+00:00'::timestamptz, NULL, false) RETURNING "zerver_realm"."id"
zulip_1     | Traceback (most recent call last):
zulip_1     |   File "/home/zulip/deployments/current/manage.py", line 24, in <module>
zulip_1     |     execute_from_command_line(sys.argv)
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
zulip_1     |     utility.execute()
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/core/management/__init__.py", line 330, in execute
zulip_1     |     self.fetch_command(subcommand).run_from_argv(self.argv)
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/core/management/base.py", line 393, in run_from_argv
zulip_1     |     self.execute(*args, **cmd_options)
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/core/management/base.py", line 444, in execute
zulip_1     |     output = self.handle(*args, **options)
zulip_1     |   File "/home/zulip/deployments/2016-03-09-14-24-05/zerver/management/commands/initialize_voyager_db.py", line 39, in handle
zulip_1     |     Realm.objects.create(domain="zulip.com")
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/db/models/manager.py", line 127, in manager_method
zulip_1     |     return getattr(self.get_queryset(), name)(*args, **kwargs)
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/db/models/query.py", line 348, in create
zulip_1     |     obj.save(force_insert=True, using=self.db)
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/db/models/base.py", line 710, in save
zulip_1     |     force_update=force_update, update_fields=update_fields)
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/db/models/base.py", line 738, in save_base
zulip_1     |     updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/db/models/base.py", line 822, in _save_table
zulip_1     |     result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/db/models/base.py", line 861, in _do_insert
zulip_1     |     using=using, raw=raw)
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/db/models/manager.py", line 127, in manager_method
zulip_1     |     return getattr(self.get_queryset(), name)(*args, **kwargs)
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/db/models/query.py", line 922, in _insert
zulip_1     |     return query.get_compiler(using=using).execute_sql(return_id)
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/db/models/sql/compiler.py", line 986, in execute_sql
zulip_1     |     cursor.execute(sql, params)
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/db/backends/utils.py", line 64, in execute
zulip_1     |     return self.cursor.execute(sql, params)
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/db/utils.py", line 97, in __exit__
zulip_1     |     six.reraise(dj_exc_type, dj_exc_value, traceback)
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/db/backends/utils.py", line 64, in execute
zulip_1     |     return self.cursor.execute(sql, params)
zulip_1     |   File "/home/zulip/deployments/2016-03-09-14-24-05/zerver/lib/db.py", line 23, in execute
zulip_1     |     return wrapper_execute(self, super(TimeTrackingCursor, self).execute, query, vars)
zulip_1     |   File "/home/zulip/deployments/2016-03-09-14-24-05/zerver/lib/db.py", line 11, in wrapper_execute
zulip_1     |     return action(sql, params)
zulip_1     | django.db.utils.IntegrityError: duplicate key value violates unique constraint "zerver_realm_domain_key"
zulip_1     | DETAIL:  Key (domain)=(zulip.com) already exists.
zulip_1     | 
zulip_1     | Zulip first start init failed in "initialize_voyager_db" exit code 0. Exiting.
zulip_zulip_1 exited with code 0
galexrt commented 8 years ago

@reyman Could you please provide the full logs of the new error as a gist?

galexrt commented 8 years ago

@reyman I finally found the source of all these errors. Zulip is now based on latest Zulip master and not on a specific version tag. This should fix most errors you had.

galexrt commented 8 years ago

@reyman I finally found the source of all these errors. Zulip is now based on latest Zulip master and not on a specific version tag. This should fix most errors you had.

reyman commented 8 years ago

@Galexrt Great :) I continue to pull from sudo docker pull galexrt/zulip:dev-1.3.10 ?

galexrt commented 8 years ago

@reyman It seems that I now fixed the errors and bugs. Please repull the latest image and test again.

Thanks for providing help in testing it!

galexrt commented 8 years ago

Yes, you can continue to pull from dev-1.3.10. Until I can finally release a stable v1.3.10. Thanks for testing!

reyman commented 8 years ago

@Galexrt There is some problem with existing value in table it seems :


zulip_1     | + echo 'Initializing Zulip Voyager database ...'
zulip_1     | + su zulip -c '/home/zulip/deployments/current/manage.py initialize_voyager_db'
zulip_1     | Initializing Zulip Voyager database ...
database_1  | ERROR:  duplicate key value violates unique constraint "zerver_realm_domain_key"
database_1  | DETAIL:  Key (domain)=(zulip.com) already exists.
database_1  | STATEMENT:  INSERT INTO "zerver_realm" ("domain", "name", "restricted_to_domain", "invite_required", "invite_by_admins_only", "mandatory_topics",
 "show_digest_email", "name_changes_disabled", "date_created", "notifications_stream_id", "deactivated") VALUES ('zulip.com', NULL, true, false, false, false, 
true, false, '2016-03-10T16:32:32.941785+00:00'::timestamptz, NULL, false) RETURNING "zerver_realm"."id"
zulip_1     | Traceback (most recent call last):
zulip_1     |   File "/home/zulip/deployments/current/manage.py", line 24, in <module>
zulip_1     |     execute_from_command_line(sys.argv)
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
zulip_1     |     utility.execute()
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/core/management/__init__.py", line 330, in execute
zulip_1     |     self.fetch_command(subcommand).run_from_argv(self.argv)
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/core/management/base.py", line 393, in run_from_argv
zulip_1     |     self.execute(*args, **cmd_options)
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/core/management/base.py", line 444, in execute
zulip_1     |     output = self.handle(*args, **options)
zulip_1     |   File "/home/zulip/deployments/2016-03-09-16-29-00/zerver/management/commands/initialize_voyager_db.py", line 39, in handle
zulip_1     |     Realm.objects.create(domain="zulip.com")
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/db/models/manager.py", line 127, in manager_method
zulip_1     |     return getattr(self.get_queryset(), name)(*args, **kwargs)
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/db/models/query.py", line 348, in create
zulip_1     |     obj.save(force_insert=True, using=self.db)
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/db/models/base.py", line 710, in save
zulip_1     |     force_update=force_update, update_fields=update_fields)
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/db/models/base.py", line 738, in save_base
zulip_1     |     updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/db/models/base.py", line 822, in _save_table
zulip_1     |     result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/db/models/base.py", line 861, in _do_insert
zulip_1     |     using=using, raw=raw)
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/db/models/manager.py", line 127, in manager_method
zulip_1     |     return getattr(self.get_queryset(), name)(*args, **kwargs)
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/db/models/query.py", line 348, in create
zulip_1     |     obj.save(force_insert=True, using=self.db)
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/db/models/base.py", line 710, in save
zulip_1     |     force_update=force_update, update_fields=update_fields)
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/db/models/base.py", line 738, in save_base
zulip_1     |     updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/db/models/base.py", line 822, in _save_table
zulip_1     |     result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/db/models/base.py", line 861, in _do_insert
zulip_1     |     using=using, raw=raw)
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/db/models/manager.py", line 127, in manager_method
zulip_1     |     return getattr(self.get_queryset(), name)(*args, **kwargs)
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/db/models/query.py", line 922, in _insert
zulip_1     |     return query.get_compiler(using=using).execute_sql(return_id)
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/db/models/sql/compiler.py", line 986, in execute_sql
zulip_1     |     cursor.execute(sql, params)
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/db/backends/utils.py", line 64, in execute
zulip_1     |     return self.cursor.execute(sql, params)
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/db/utils.py", line 97, in __exit__
zulip_1     |     six.reraise(dj_exc_type, dj_exc_value, traceback)
zulip_1     |   File "/usr/lib/python2.7/dist-packages/django/db/backends/utils.py", line 64, in execute
zulip_1     |     return self.cursor.execute(sql, params)
zulip_1     |   File "/home/zulip/deployments/2016-03-09-16-29-00/zerver/lib/db.py", line 23, in execute
zulip_1     |     return wrapper_execute(self, super(TimeTrackingCursor, self).execute, query, vars)
zulip_1     |   File "/home/zulip/deployments/2016-03-09-16-29-00/zerver/lib/db.py", line 11, in wrapper_execute
zulip_1     |     return action(sql, params)
zulip_1     | django.db.utils.IntegrityError: duplicate key value violates unique constraint "zerver_realm_domain_key"
zulip_1     | DETAIL:  Key (domain)=(zulip.com) already exists.
zulip_1     | 
zulip_1     | + RETURN_CODE=1
zulip_1     | + [[ 1 != 0 ]]
zulip_1     | + echo 'Zulip first start init failed in "initialize_voyager_db" exit code 1. Exiting.'
zulip_1     | + exit 1
zulip_1     | Zulip first start init failed in "initialize_voyager_db" exit code 1. Exiting.
galexrt commented 8 years ago

@reyman Could you please enter the container using docker exec and post content of the /etc/zulip/settings.py and /home/zulip/deployments/current/zproject/settings.py without sensitive data?

reyman commented 8 years ago

Hum i cannot test before tonigh or tomorow (no ssh in train 😀) but the container failed to start so im not sûre i can make à docker exec on it.

Le jeu. 10 mars 2016 17:47, Alexander Trost notifications@github.com a écrit :

@reyman https://github.com/reyman Could you please enter the container using docker exec and post content of the /etc/zulip/settings.py and /home/zulip/deployments/current/zproject/settings.py without sensitive data?

— Reply to this email directly or view it on GitHub https://github.com/Galexrt/docker-zulip/issues/61#issuecomment-194946608 .

galexrt commented 8 years ago

@reyman No problem. But you can use docker cp to get the files out of the container ;) Thanks for the help!

reyman commented 8 years ago

Sorry for the delay

settings from /etc/zulip/settings.py


# Settings for Zulip Voyager

### MANDATORY SETTINGS
#
# These settings MUST be set in production. In a development environment,
# sensible default values will be used.

# The user-accessible Zulip hostname for this installation, e.g.
# zulip.example.com
EXTERNAL_HOST = 'zulip.example.com'

# The email address for the person or team who maintain the Zulip
# Voyager installation. Will also get support emails. (e.g. zulip-admin@example.com)
ZULIP_ADMINISTRATOR = 'zulip-admin@example.com'

# The domain for your organization, e.g. example.com
ADMIN_DOMAIN = 'example.com'

# Enable at least one of the following authentication backends.
AUTHENTICATION_BACKENDS = (
#                           'zproject.backends.EmailAuthBackend', # Email and password; see SMTP setup below
#                           'zproject.backends.ZulipRemoteUserBackend', # Local SSO
#                           'zproject.backends.GoogleMobileOauth2Backend', # Google Apps, setup below
#                           'zproject.backends.ZulipLDAPAuthBackend', # LDAP, setup below
    )

# Google Oauth requires a bit of configuration; you will need to go to
# do the following:
#
# (1) Visit https://console.developers.google.com, setup an
# Oauth2 client ID that allows redirects to
# e.g. https://zulip.example.com/accounts/login/google/done/.
#
# (2) Then click into the APIs and Auth section (in the sidebar on the
# left side of the page), APIs, then under "Social APIs" click on
# "Google+ API" and click the button to enable the API.
#
# (3) put your client secret as "google_oauth2_client_secret" in
# zulip-secrets.conf, and your client ID right here:
# GOOGLE_OAUTH2_CLIENT_ID=<your client ID from Google>
# If you are using the ZulipRemoteUserBackend authentication backend,
# set this to your domain (e.g. if REMOTE_USER is "username" and the
# corresponding email address is "username@example.com", set
# SSO_APPEND_DOMAIN = "example.com")
SSO_APPEND_DOMAIN = None

# Configure the outgoing SMTP server below. For testing, you can skip
# sending emails entirely by commenting out EMAIL_HOST, but you will
# want to configure this to support email address confirmation emails,
# missed message emails, onboarding follow-up emails, etc. To
# configure SMTP, you will need to complete the following steps:
#
# (1) Fill out the outgoing email sending configuration below.
#
# (2) Put the SMTP password for EMAIL_HOST_USER in
# /etc/zulip/zulip-secrets.conf as email_password.
#
# (3) If you are using a gmail account to send outgoing email, you
# will likely need to read this Google support answer and configure
# that account as "less secure":
# https://support.google.com/mail/answer/14257.
#
# A common problem is hosting providers that block outgoing SMTP traffic.
#
# With the exception of reading EMAIL_HOST_PASSWORD from
# email_password in the Zulip secrets file, Zulip uses Django's
# standard EmailBackend, so if you're having issues, you may want to
# search for documentation on using your email provider with Django.
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = ''
EMAIL_PORT = 587
EMAIL_USE_TLS = True
# The email From address to be used for automatically generated emails
DEFAULT_FROM_EMAIL = "Zulip <zulip@example.com>"
# The noreply address to be used as Reply-To for certain generated emails.
# Messages sent to this address should not be delivered anywhere.
NOREPLY_EMAIL_ADDRESS = "noreply@example.com"
# A list of strings representing the host/domain names that this
# Django site can serve. You should reset it to be a list of
# domains/IP addresses for your site. This is a security measure to
# prevent an attacker from poisoning caches and triggering password
# reset emails with links to malicious hosts by submitting requests
# with a fake HTTP Host header. You must include 'localhost' here.
ALLOWED_HOSTS = ['*']

### OPTIONAL SETTINGS

# Controls whether session cookies expire when the browser closes
SESSION_EXPIRE_AT_BROWSER_CLOSE = False

# Session cookie expiry in seconds after the last page load
SESSION_COOKIE_AGE = 60 * 60 * 24 * 7 * 2 # 2 weeks

# Controls whether or not there is a feedback button in the UI.
ENABLE_FEEDBACK = False

# By default, the feedback button will submit feedback to the Zulip
# developers.  If you set FEEDBACK_EMAIL to be an email address
# (e.g. ZULIP_ADMINISTRATOR), feedback sent by your users will instead
# be sent to that email address.
FEEDBACK_EMAIL = ZULIP_ADMINISTRATOR

# Controls whether or not error reports are sent to Zulip.  Error
# reports are used to improve the quality of the product and do not
# include message contents; please contact Zulip support with any
# questions.
ERROR_REPORTING = True

# Controls whether or not Zulip will provide inline image preview when
# a link to an image is referenced in a message.
INLINE_IMAGE_PREVIEW = True
# By default, files uploaded by users and user avatars are stored
# directly on the Zulip server.  If file storage in Amazon S3 is
# desired, you can configure that as follows:
#
# (1) Set s3_key and s3_secret_key in /etc/zulip/zulip-secrets.conf to
# be the S3 access and secret keys that you want to use, and setting
# the S3_AUTH_UPLOADS_BUCKET and S3_AVATAR_BUCKET to be the S3 buckets
# you've created to store file uploads and user avatars, respectively.
# Then restart Zulip (scripts/restart-zulip).
#
# (2) Edit /etc/nginx/sites-available/zulip-enterprise to comment out
# the nginx configuration for /user_uploads and /user_avatars (see
# https://github.com/zulip/zulip/issues/291 for discussion of a better
# solution that won't be automatically reverted by the Zulip upgrade
# script), and then restart nginx.
LOCAL_UPLOADS_DIR = "/home/zulip/uploads"
#S3_AUTH_UPLOADS_BUCKET = ""
#S3_AVATAR_BUCKET = ""

# Maximum allowed size of uploaded files, in megabytes.  DO NOT SET
# ABOVE 80MB.  The file upload implementation doesn't support chunked
# uploads, so browsers will crash if you try uploading larger files.
MAX_FILE_UPLOAD_SIZE = 25

# Controls whether name changes are completely disabled for this installation
# This is useful in settings where you're syncing names from an integrated LDAP/Active Directory
NAME_CHANGES_DISABLED = False

# Controls whether users who have not uploaded an avatar will receive an avatar
# from gravatar.com.
ENABLE_GRAVATAR = True

# To override the default avatar image if ENABLE_GRAVATAR is False, place your
# custom default avatar image at /home/zulip/local-static/default-avatar.png
# and uncomment the following line.
#DEFAULT_AVATAR_URI = '/local-static/default-avatar.png'
# To access an external postgres database you should define the host name in
# REMOTE_POSTGRES_HOST, you can define the password in the secrets file in the
# property postgres_password, and the SSL connection mode in REMOTE_POSTGRES_SSLMODE
# Different options are:
#   disable: I don't care about security, and I don't want to pay the overhead of encryption.
#   allow: I don't care about security, but I will pay the overhead of encryption if the server insists on it.
#   prefer: I don't care about encryption, but I wish to pay the overhead of encryption if the server supports it.
#   require: I want my data to be encrypted, and I accept the overhead. I trust that the network will make sure I always connect to the server I want.
#   verify-ca: I want my data encrypted, and I accept the overhead. I want to be sure that I connect to a server that I trust.
#   verify-full: I want my data encrypted, and I accept the overhead. I want to be sure that I connect to a server I trust, and that it's the one I specify.
#REMOTE_POSTGRES_HOST = 'dbserver.example.com'
#REMOTE_POSTGRES_SSLMODE = 'require'

### TWITTER INTEGRATION

# Zulip supports showing inline Tweet previews when a tweet is linked
# to in a message.  To support this, Zulip must have access to the
# Twitter API via OAuth.  To obtain the various access tokens needed
# below, you must register a new application under your Twitter
# account by doing the following:
#
# 1. Log in to http://dev.twitter.com.
# 2. In the menu under your username, click My Applications. From this page, create a new application.
# 3. Click on the application you created and click "create my access token".
# 4. Fill in the values for twitter_consumer_key, twitter_consumer_secret, twitter_access_token_key,
#    and twitter_access_token_secret in /etc/zulip/zulip-secrets.conf.

### EMAIL GATEWAY INTEGRATION

# The Email gateway integration supports sending messages into Zulip
# by sending an email.  This is useful for receiving notifications
# from third-party services that only send outgoing notifications via
# email.  Once this integration is configured, each stream will have
# an email address documented on the stream settings page an emails
# sent to that address will be delivered into the stream.
#
# There are two ways to configure email mirroring in Zulip:
#  1. Local delivery: A MTA runs locally and passes mail directly to Zulip
#  2. Polling: Checks an IMAP inbox every minute for new messages.
#
# The local delivery configuration is preferred for production because
# it supports nicer looking email addresses and has no cron delay,
# while the polling mechanism is better for testing/developing this
# feature because it doesn't require a public-facing IP/DNS setup.
#
# The main email mirror setting is the email address pattern, where
# you specify the email address format you'd like the integration to
# use.  It should be one of the following:
#   %s@zulip.example.com (for local delivery)
#   username+%s@example.com (for polling if EMAIL_GATEWAY_LOGIN=username@example.com)
EMAIL_GATEWAY_PATTERN = ""
#
# If you are using local delivery, EMAIL_GATEWAY_PATTERN is all you need
# to change in this file.  You will also need to enable the Zulip postfix
# configuration to support local delivery by adding
#   , zulip::postfix_localmail
# to puppet_classes in /etc/zulip/zulip.conf and then running
# `scripts/zulip-puppet-apply -f` to do the installation.
#
# If you are using polling, you will need to setup an IMAP email
# account dedicated to Zulip email gateway messages.  The model is
# that users will send emails to that account via an address of the
# form username+%s@example.com (which is what you will set as
# EMAIL_GATEWAY_PATTERN); your email provider should deliver those
# emails to the username@example.com inbox.  Then you run in a cron
# job `./manage.py email-mirror` (see puppet/zulip/files/cron.d/email-mirror),
# which will check that inbox and batch-process any new messages.
#
# You will need to configure authentication for the email mirror
# command to access the IMAP mailbox below and in zulip-secrets.conf.
#
# The IMAP login; username here and password as email_gateway_login in
# zulip-secrets.conf.
EMAIL_GATEWAY_LOGIN = ""
# The IMAP server & port to connect to
EMAIL_GATEWAY_IMAP_SERVER = ""
EMAIL_GATEWAY_IMAP_PORT = 993
# The IMAP folder name to check for emails. All emails sent to EMAIL_GATEWAY_PATTERN above
# must be delivered to this folder
EMAIL_GATEWAY_IMAP_FOLDER = "INBOX"

### LDAP integration configuration
# Zulip supports retrieving information about users via LDAP, and
# optionally using LDAP as an authentication mechanism.
#
# In either configuration, you will need to do the following:
#
# * Fill in the LDAP configuration options below so that Zulip can
# connect to your LDAP server
#
# * Setup the mapping between email addresses (used as login names in
# Zulip) and LDAP usernames.  There are two supported ways to setup
# the username mapping:
#
#   (A) If users' email addresses are in LDAP, set
#       LDAP_APPEND_DOMAIN = None
#       AUTH_LDAP_USER_SEARCH to lookup users by email address
#
#   (B) If LDAP only has usernames but email addresses are of the form
#       username@example.com, you should set:
#       LDAP_APPEND_DOMAIN = example.com and
#       AUTH_LDAP_USER_SEARCH to lookup users by username
#
# You can quickly test whether your configuration works by running:
#   ./manage.py query_ldap username@example.com
# From the root of your Zulip installation; if your configuration is working
# that will output the full name for your user.
#
# -------------------------------------------------------------
#
# If you are using LDAP for authentication, you will need to enable
# the zproject.backends.ZulipLDAPAuthBackend auth backend in
# AUTHENTICATION_BACKENDS above.  After doing so, you should be able
# to login to Zulip by entering your email address and LDAP password
# on the Zulip login form.
#
# If you are using LDAP to populate names in Zulip, once you finish
# configuring this integration, you will need to run:
#   ./manage.py sync_ldap_user_data
# To sync names for existing users; you may want to run this in a cron
# job to pick up name changes made on your LDAP server.
import ldap
from django_auth_ldap.config import LDAPSearch, GroupOfNamesType

# URI of your LDAP server. If set, LDAP is used to prepopulate a user's name in
# Zulip. Example: "ldaps://ldap.example.com"
AUTH_LDAP_SERVER_URI = ""

# This DN will be used to bind to your server. If unset, anonymous
# binds are performed.  If set, you need to specify the password as
# 'auth_ldap_bind_password' in zulip-secrets.conf.
AUTH_LDAP_BIND_DN = ""

# Specify the search base and the property to filter on that corresponds to the
# username.
AUTH_LDAP_USER_SEARCH = LDAPSearch("ou=users,dc=example,dc=com",
    ldap.SCOPE_SUBTREE, "(uid=%(user)s)")

# If the value of a user's "uid" (or similar) property is not their email
# address, specify the domain to append here.
LDAP_APPEND_DOMAIN = None

# This map defines how to populate attributes of a Zulip user from LDAP.
AUTH_LDAP_USER_ATTR_MAP = {
# Populate the Django user's name from the LDAP directory.
    "full_name": "cn",
}
CAMO_URI = ''

# RabbitMQ configuration
#
# By default, Zulip connects to rabbitmq running locally on the machine,
# but Zulip also supports connecting to RabbitMQ over the network;
# to use a remote RabbitMQ instance, set RABBITMQ_HOST here.
# RABBITMQ_HOST = "localhost"
# To use another rabbitmq user than the default 'zulip', set RABBITMQ_USERNAME here.
# RABBITMQ_USERNAME = 'zulip'

# Memcached configuration
#
# By default, Zulip connects to memcached running locally on the machine,
# but Zulip also supports connecting to memcached over the network;
# to use a remote Memcached instance, set MEMCACHED_LOCATION here.
# Format HOST:PORT
# MEMCACHED_LOCATION = 127.0.0.1:11211

# Redis configuration
#
# By default, Zulip connects to redis running locally on the machine,
# but Zulip also supports connecting to redis over the network;
# to use a remote RabbitMQ instance, set REDIS_HOST here.
# REDIS_HOST = '127.0.0.1'
# For a different redis port set the REDIS_PORT here.
# REDIS_PORT = 6379

# Controls whether Zulip will rate-limit user requests.
# RATE_LIMITING = True
AUTHENTICATION_BACKENDS = ('zproject.backends.ZulipLDAPAuthBackend',)
AUTH_LDAP_USER_SEARCH = LDAPSearch("ou=Users,dc=comnmodel,dc=org",ldap.SCOPE_SUBTREE,"(uid=%(user)s)")
REDIS_HOST = 'redis'
RABBITMQ_HOST = 'rabbitmq'
MEMCACHED_LOCATION = 'memcached:11211'
ADMIN_DOMAIN = 'comnmodel.org'
(END)

And the other :


from __future__ import absolute_import
# Django settings for zulip project.
########################################################################
# Here's how settings for the Zulip project work:
#
# * settings.py contains non-site-specific and settings configuration
# for the Zulip Django app.
# * settings.py imports local_settings.py, and any site-specific configuration
# belongs there.  The template for local_settings.py is local_settings_template.py
########################################################################
import os
import platform
import time
import sys
import six.moves.configparser

from zerver.lib.db import TimeTrackingConnection

########################################################################
# INITIAL SETTINGS
########################################################################

config_file = six.moves.configparser.RawConfigParser()
config_file.read("/etc/zulip/zulip.conf")

# Whether this instance of Zulip is running in a production environment.
PRODUCTION = config_file.has_option('machine', 'deploy_type')
DEVELOPMENT = not PRODUCTION

secrets_file = six.moves.configparser.RawConfigParser()
if PRODUCTION:
    secrets_file.read("/etc/zulip/zulip-secrets.conf")
else:
    secrets_file.read("zproject/dev-secrets.conf")

def get_secret(key):
    if secrets_file.has_option('secrets', key):
        return secrets_file.get('secrets', key)
    return None
# Make this unique, and don't share it with anybody.
SECRET_KEY = get_secret("secret_key")

# A shared secret, used to authenticate different parts of the app to each other.
SHARED_SECRET = get_secret("shared_secret")

# We use this salt to hash a user's email into a filename for their user-uploaded
# avatar.  If this salt is discovered, attackers will only be able to determine
# that the owner of an email account has uploaded an avatar to Zulip, which isn't
# the end of the world.  Don't use the salt where there is more security exposure.
AVATAR_SALT = get_secret("avatar_salt")

# SERVER_GENERATION is used to track whether the server has been
# restarted for triggering browser clients to reload.
SERVER_GENERATION = int(time.time())

if not 'DEBUG' in globals():
    # Uncomment end of next line to test JS/CSS minification.
    DEBUG = DEVELOPMENT # and platform.node() != 'your-machine'

TEMPLATE_DEBUG = DEBUG
if DEBUG:
    INTERNAL_IPS = ('127.0.0.1',)

# Detect whether we're running as a queue worker; this impacts the logging configuration.
if len(sys.argv) > 2 and sys.argv[0].endswith('manage.py') and sys.argv[1] == 'process_queue':
    IS_WORKER = True
else:
    IS_WORKER = False

# This is overridden in test_settings.py for the test suites
TEST_SUITE = False
# The new user tutorial is enabled by default, but disabled for client tests.
TUTORIAL_ENABLED = True
# Import variables like secrets from the local_settings file
# Import local_settings after determining the deployment/machine type
if PRODUCTION:
    from .local_settings import *
else:
    # For the Dev VM environment, we use the same settings as the
    # sample local_settings.py file, with a few exceptions.
    from .local_settings_template import *
    EXTERNAL_HOST = 'localhost:9991'
    ALLOWED_HOSTS = ['localhost']
    AUTHENTICATION_BACKENDS = ('zproject.backends.DevAuthBackend',)
    # Add some of the below if you're testing other backends
    # AUTHENTICATION_BACKENDS = ('zproject.backends.EmailAuthBackend',
    #                            'zproject.backends.GoogleMobileOauth2Backend',)
    EXTERNAL_URI_SCHEME = "http://"
    EMAIL_GATEWAY_PATTERN = "%s@" + EXTERNAL_HOST
    ADMIN_DOMAIN = "zulip.com"
    NOTIFICATION_BOT = "notification-bot@zulip.com"
    ERROR_BOT = "error-bot@zulip.com"
    NEW_USER_BOT = "new-user-bot@zulip.com"
    EMAIL_GATEWAY_BOT = "emailgateway@zulip.com"

########################################################################
# DEFAULT VALUES FOR SETTINGS
########################################################################

# For any settings that are not defined in local_settings.py,
# we want to initialize them to sane default
DEFAULT_SETTINGS = {'TWITTER_CONSUMER_KEY': '',
                    'TWITTER_CONSUMER_SECRET': '',
                    'TWITTER_ACCESS_TOKEN_KEY': '',
                    'TWITTER_ACCESS_TOKEN_SECRET': '',
                    'EMAIL_GATEWAY_PATTERN': '',
                    'EMAIL_GATEWAY_EXAMPLE': '',
                    'EMAIL_GATEWAY_BOT': None,
                    'EMAIL_GATEWAY_LOGIN': None,
                    'EMAIL_GATEWAY_PASSWORD': None,
                    'EMAIL_GATEWAY_IMAP_SERVER': None,
                    'EMAIL_GATEWAY_IMAP_PORT': None,
                    'EMAIL_GATEWAY_IMAP_FOLDER': None,
                    'MANDRILL_API_KEY': '',
                    'S3_KEY': '',
                    'S3_SECRET_KEY': '',
                    'S3_BUCKET': '',
                    'S3_AVATAR_BUCKET': '',
                    'LOCAL_UPLOADS_DIR': None,
                    'MAX_FILE_UPLOAD_SIZE': 25,
                    'DROPBOX_APP_KEY': '',
                    'ERROR_REPORTING': True,
                    'JWT_AUTH_KEYS': {},
                    'NAME_CHANGES_DISABLED': False,
                    'DEPLOYMENT_ROLE_NAME': "",
                    'RABBITMQ_HOST': 'localhost',
                    'RABBITMQ_USERNAME': 'zulip',
                    'MEMCACHED_LOCATION': '127.0.0.1:11211',
                    'RATE_LIMITING': True,
                    'REDIS_HOST': '127.0.0.1',
                    'REDIS_PORT': 6379,
                    # The following bots only exist in non-VOYAGER installs
                    'ERROR_BOT': None,
                    'NEW_USER_BOT': None,
                    'NAGIOS_STAGING_SEND_BOT': None,
                    'NAGIOS_STAGING_RECEIVE_BOT': None,
                    'APNS_CERT_FILE': None,
                    'ANDROID_GCM_API_KEY': None,
                    'INITIAL_PASSWORD_SALT': None,
                    'FEEDBACK_BOT': 'feedback@zulip.com',
                    'FEEDBACK_BOT_NAME': 'Zulip Feedback Bot',
                    'API_SUPER_USERS': set(),
                    'ADMINS': '',
                    'INLINE_IMAGE_PREVIEW': True,
                    'CAMO_URI': '',
                    'ENABLE_FEEDBACK': PRODUCTION,
                    'FEEDBACK_EMAIL': None,
                    'ENABLE_GRAVATAR': True,
                    'DEFAULT_AVATAR_URI': '/static/images/default-avatar.png',
                    'AUTH_LDAP_SERVER_URI': "",
                    'EXTERNAL_URI_SCHEME': "https://",
                    'ZULIP_COM': False,
                    'ZULIP_COM_STAGING': False,
                    'STATSD_HOST': '',
                    'REMOTE_POSTGRES_HOST': '',
                    'REMOTE_POSTGRES_SSLMODE': '',
                    'GOOGLE_CLIENT_ID': '',
                    'DBX_APNS_CERT_FILE': None,
                    }

for setting_name, setting_val in DEFAULT_SETTINGS.iteritems():
    if not setting_name in vars():
        vars()[setting_name] = setting_val

# These are the settings that we will check that the user has filled in for
# production deployments before starting the app.  It consists of a series
# of pairs of (setting name, default value that it must be changed from)
REQUIRED_SETTINGS = [("EXTERNAL_HOST", "zulip.example.com"),
                     ("ZULIP_ADMINISTRATOR", "zulip-admin@example.com"),
                     ("ADMIN_DOMAIN", "example.com"),
                     # SECRET_KEY doesn't really need to be here, in
                     # that we set it automatically, but just in
                     # case, it seems worth having in this list
                     ("SECRET_KEY", ""),
                     ("AUTHENTICATION_BACKENDS", ()),
                     ("NOREPLY_EMAIL_ADDRESS", "noreply@example.com"),
                     ("DEFAULT_FROM_EMAIL", "Zulip <zulip@example.com>"),
                     ("ALLOWED_HOSTS", "*"),
                     ]

if ADMINS == "":
    ADMINS = (("Zulip Administrator", ZULIP_ADMINISTRATOR),)
MANAGERS = ADMINS

# Voyager is a production zulip server that is not zulip.com or
# staging.zulip.com VOYAGER is the standalone all-on-one-server
# production deployment model for based on the original Zulip
# ENTERPRISE implementation.  We expect most users of the open source
# project will be using VOYAGER=True in production.
VOYAGER = PRODUCTION and not ZULIP_COM

########################################################################
# STANDARD DJANGO SETTINGS
########################################################################

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# In a Windows environment this must be set to your system time zone.
TIME_ZONE = 'America/New_York'

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'

# The ID, as an integer, of the current site in the django_site database table.
# This is used so that application data can hook into specific site(s) and a
# single database can manage content for multiple sites.
#
# We set this site's domain to 'zulip.com' in populate_db.
SITE_ID = 1

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True

# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale.
USE_L10N = True

# If you set this to False, Django will not use timezone-aware datetimes.
USE_TZ = True

DEPLOY_ROOT = os.path.join(os.path.realpath(os.path.dirname(__file__)), '..')
TEMPLATE_DIRS = ( os.path.join(DEPLOY_ROOT, 'templates'), )
LOCALE_PATHS = ( os.path.join(DEPLOY_ROOT, 'locale'), )

# Make redirects work properly behind a reverse proxy
USE_X_FORWARDED_HOST = True

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
    )
if PRODUCTION:
    # Template caching is a significant performance win in production.
    TEMPLATE_LOADERS = (
        ('django.template.loaders.cached.Loader',
         TEMPLATE_LOADERS),
        )

MIDDLEWARE_CLASSES = (
    # Our logging middleware should be the first middleware item.
    'zerver.middleware.TagRequests',
    'zerver.middleware.LogRequests',
    'zerver.middleware.JsonErrorHandler',
    'zerver.middleware.RateLimitMiddleware',
    'zerver.middleware.FlushDisplayRecipientCache',
    'django.middleware.common.CommonMiddleware',
    'zerver.middleware.SessionHostDomainMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
)
ANONYMOUS_USER_ID = None

AUTH_USER_MODEL = "zerver.UserProfile"

TEST_RUNNER = 'zerver.lib.test_runner.Runner'

ROOT_URLCONF = 'zproject.urls'

# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'zproject.wsgi.application'

INSTALLED_APPS = [
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.staticfiles',
    'confirmation',
    'guardian',
    'pipeline',
    'zerver',
]

if not VOYAGER:
    INSTALLED_APPS += [
        'analytics',
        'zilencer',
    ]

# Base URL of the Tornado server
# We set it to None when running backend tests or populate_db.
# We override the port number when running frontend tests.
TORNADO_SERVER = 'http://localhost:9993'
RUNNING_INSIDE_TORNADO = False

########################################################################
# DATABASE CONFIGURATION
########################################################################

DATABASES = {"default": {
    'ENGINE': 'django.db.backends.postgresql_psycopg2',
    'NAME': 'zulip',
    'USER': 'zulip',
    'PASSWORD': '', # Authentication done via certificates
    'HOST': '',  # Host = '' => connect through a local socket
    'SCHEMA': 'zulip',
    'CONN_MAX_AGE': 600,
    'OPTIONS': {
        'connection_factory': TimeTrackingConnection
        },
    },
}

if DEVELOPMENT:
    LOCAL_DATABASE_PASSWORD = get_secret("local_database_password")
    DATABASES["default"].update({
            'PASSWORD': LOCAL_DATABASE_PASSWORD,
            'HOST': 'localhost'
            })
elif REMOTE_POSTGRES_HOST != '':
    DATABASES['default'].update({
            'HOST': REMOTE_POSTGRES_HOST,
            })
    if get_secret("postgres_password") is not None:
        DATABASES['default'].update({
            'PASSWORD': get_secret("postgres_password"),
            })
    if REMOTE_POSTGRES_SSLMODE != '':
        DATABASES['default']['OPTIONS']['sslmode'] = REMOTE_POSTGRES_SSLMODE
    else:
        DATABASES['default']['OPTIONS']['sslmode'] = 'verify-full'

#######################################################################
# RABBITMQ CONFIGURATION
########################################################################

USING_RABBITMQ = True
RABBITMQ_PASSWORD = get_secret("rabbitmq_password")

########################################################################
# CACHING CONFIGURATION
########################################################################

SESSION_ENGINE = "django.contrib.sessions.backends.cached_db"

CACHES = {
    'default': {
        'BACKEND':  'django.core.cache.backends.memcached.PyLibMCCache',
        'LOCATION': MEMCACHED_LOCATION,
        'TIMEOUT':  3600
    },
    'database': {
        'BACKEND':  'django.core.cache.backends.db.DatabaseCache',
        'LOCATION':  'third_party_api_results',
        # Basically never timeout.  Setting to 0 isn't guaranteed
        # to work, see https://code.djangoproject.com/ticket/9595
        'TIMEOUT': 2000000000,
        'OPTIONS': {
            'MAX_ENTRIES': 100000000,
            'CULL_FREQUENCY': 10,
        }
    },
}

########################################################################
# REDIS-BASED RATE LIMITING CONFIGURATION
########################################################################

RATE_LIMITING_RULES = [
    (60, 100),     # 100 requests max every minute
    ]

########################################################################
# SECURITY SETTINGS
########################################################################

# Tell the browser to never send our cookies without encryption, e.g.
# when executing the initial http -> https redirect.
#
# Turn it off for local testing because we don't have SSL.
if PRODUCTION:
    SESSION_COOKIE_SECURE = True
    CSRF_COOKIE_SECURE    = True

try:
    # For get_updates hostname sharding.
    domain = config_file.get('django', 'cookie_domain')
    SESSION_COOKIE_DOMAIN = '.' + domain
    CSRF_COOKIE_DOMAIN    = '.' + domain
except six.moves.configparser.Error:
    # Failing here is OK
    pass

# Prevent Javascript from reading the CSRF token from cookies.  Our code gets
# the token from the DOM, which means malicious code could too.  But hiding the
# cookie will slow down some attackers.
CSRF_COOKIE_PATH = '/;HttpOnly'
CSRF_FAILURE_VIEW = 'zerver.middleware.csrf_failure'

if DEVELOPMENT:
    # Use fast password hashing for creating testing users when not
    # PRODUCTION.  Saves a bunch of time.
    PASSWORD_HASHERS = (
                'django.contrib.auth.hashers.SHA1PasswordHasher',
                'django.contrib.auth.hashers.PBKDF2PasswordHasher'
            )
    # Also we auto-generate passwords for the default users which you
    # can query using ./manage.py print_initial_password
    INITIAL_PASSWORD_SALT = get_secret("initial_password_salt")

########################################################################
# API/BOT SETTINGS
########################################################################

if "EXTERNAL_API_PATH" not in vars():
    EXTERNAL_API_PATH = EXTERNAL_HOST + "/api"
EXTERNAL_API_URI = EXTERNAL_URI_SCHEME + EXTERNAL_API_PATH

S3_KEY = get_secret("s3_key")
S3_SECRET_KEY = get_secret("s3_secret_key")

# GCM tokens are IP-whitelisted; if we deploy to additional
# servers you will need to explicitly add their IPs here:
# https://cloud.google.com/console/project/apps~zulip-android/apiui/credential
ANDROID_GCM_API_KEY = get_secret("android_gcm_api_key")

GOOGLE_OAUTH2_CLIENT_SECRET = get_secret('google_oauth2_client_secret')

DROPBOX_APP_KEY = get_secret("dropbox_app_key")

MAILCHIMP_API_KEY = get_secret("mailchimp_api_key")

# This comes from our mandrill accounts page
MANDRILL_API_KEY = get_secret("mandrill_api_key")

# Twitter API credentials
# Secrecy not required because its only used for R/O requests.
# Please don't make us go over our rate limit.
TWITTER_CONSUMER_KEY = get_secret("twitter_consumer_key")
TWITTER_CONSUMER_SECRET = get_secret("twitter_consumer_secret")
TWITTER_ACCESS_TOKEN_KEY = get_secret("twitter_access_token_key")
TWITTER_ACCESS_TOKEN_SECRET = get_secret("twitter_access_token_secret")

# These are the bots that Zulip sends automated messages as.
INTERNAL_BOTS = [ {'var_name': 'NOTIFICATION_BOT',
                   'email_template': 'notification-bot@%s',
                   'name': 'Notification Bot'},
                  {'var_name': 'EMAIL_GATEWAY_BOT',
                   'email_template': 'emailgateway@%s',
                   'name': 'Email Gateway'},
                  {'var_name': 'NAGIOS_SEND_BOT',
                   'email_template': 'nagios-send-bot@%s',
                   'name': 'Nagios Send Bot'},
                  {'var_name': 'NAGIOS_RECEIVE_BOT',
                   'email_template': 'nagios-receive-bot@%s',
                   'name': 'Nagios Receive Bot'},
                  {'var_name': 'WELCOME_BOT',
                   'email_template': 'welcome-bot@%s',
                   'name': 'Welcome Bot'} ]

INTERNAL_BOT_DOMAIN = "zulip.com"

# Set the realm-specific bot names
for bot in INTERNAL_BOTS:
    if not bot['var_name'] in vars():
        bot_email = bot['email_template'] % (INTERNAL_BOT_DOMAIN,)
        vars()[bot['var_name'] ] = bot_email

if EMAIL_GATEWAY_BOT not in API_SUPER_USERS:
    API_SUPER_USERS.add(EMAIL_GATEWAY_BOT)
if EMAIL_GATEWAY_PATTERN != "":
    EMAIL_GATEWAY_EXAMPLE = EMAIL_GATEWAY_PATTERN % ("support+abcdefg",)

DEPLOYMENT_ROLE_KEY = get_secret("deployment_role_key")

if PRODUCTION:
    FEEDBACK_TARGET="https://zulip.com/api"
else:
    FEEDBACK_TARGET="http://localhost:9991/api"

########################################################################
# STATSD CONFIGURATION
########################################################################

# Statsd is not super well supported; if you want to use it you'll need
# to set STATSD_HOST and STATSD_PREFIX.
if STATSD_HOST != '':
    INSTALLED_APPS += ['django_statsd']
    STATSD_PORT = 8125
    STATSD_CLIENT = 'django_statsd.clients.normal'

########################################################################
# CAMO HTTPS CACHE CONFIGURATION
########################################################################

if CAMO_URI != '':
    # This needs to be synced with the Camo installation
    CAMO_KEY = get_secret("camo_key")

########################################################################
# STATIC CONTENT AND MINIFICATION SETTINGS
########################################################################

STATIC_URL = '/static/'

# ZulipStorage is a modified version of PipelineCachedStorage,
# and, like that class, it inserts a file hash into filenames
# to prevent the browser from using stale files from cache.
#
# Unlike PipelineStorage, it requires the files to exist in
# STATIC_ROOT even for dev servers.  So we only use
# ZulipStorage when not DEBUG.

# This is the default behavior from Pipeline, but we set it
# here so that urls.py can read it.
PIPELINE = not DEBUG

if DEBUG:
    STATICFILES_STORAGE = 'pipeline.storage.PipelineStorage'
    STATICFILES_FINDERS = (
        'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    )
    if PIPELINE:
        STATIC_ROOT = 'prod-static/serve'
    else:
        STATIC_ROOT = 'static/'
else:
    STATICFILES_STORAGE = 'zerver.storage.ZulipStorage'
    STATICFILES_FINDERS = (
        'zerver.finders.ZulipFinder',
    )
    if PRODUCTION:
        STATIC_ROOT = '/home/zulip/prod-static'
    else:
        STATIC_ROOT = 'prod-static/serve'

# We want all temporary uploaded files to be stored on disk.
FILE_UPLOAD_MAX_MEMORY_SIZE = 0

STATICFILES_DIRS = ['static/']
STATIC_HEADER_FILE = 'zerver/static_header.txt'

# To use minified files in dev, set PIPELINE = True.  For the full
# cache-busting behavior, you must also set DEBUG = False.
#
# You will need to run update-prod-static after changing
# static files.

PIPELINE_CSS = {
    'activity': {
        'source_filenames': ('styles/activity.css',),
        'output_filename':  'min/activity.css'
    },
    'portico': {
        'source_filenames': (
            'third/zocial/zocial.css',
            'styles/portico.css',
            'styles/pygments.css',
            'styles/thirdparty-fonts.css',
            'styles/fonts.css',
        ),
        'output_filename': 'min/portico.css'
    },
    # Two versions of the app CSS exist because of QTBUG-3467
    'app-fontcompat': {
        'source_filenames': (
            'third/bootstrap-notify/css/bootstrap-notify.css',
            'third/spectrum/spectrum.css',
            'styles/zulip.css',
            'styles/pygments.css',
            'styles/thirdparty-fonts.css',
            # We don't want fonts.css on QtWebKit, so its omitted here
        ),
        'output_filename': 'min/app-fontcompat.css'
    },
    'app': {
        'source_filenames': (
            'third/bootstrap-notify/css/bootstrap-notify.css',
            'third/spectrum/spectrum.css',
            'third/jquery-perfect-scrollbar/css/perfect-scrollbar.css',
            'styles/zulip.css',
            'styles/pygments.css',
            'styles/thirdparty-fonts.css',
            'styles/fonts.css',
        ),
        'output_filename': 'min/app.css'
    },
    'common': {
        'source_filenames': (
            'third/bootstrap/css/bootstrap.css',
            'third/bootstrap/css/bootstrap-btn.css',
            'third/bootstrap/css/bootstrap-responsive.css',
        ),
        'output_filename': 'min/common.css'
    },
}

JS_SPECS = {
    'common': {
        'source_filenames': (
            'third/jquery/jquery-1.7.2.js',
            'third/underscore/underscore.js',
            'js/blueslip.js',
            'third/bootstrap/js/bootstrap.js',
            'js/common.js',
            ),
        'output_filename':  'min/common.js'
    },
    'signup': {
        'source_filenames': (
            'js/signup.js',
            'third/jquery-validate/jquery.validate.js',
            ),
        'output_filename':  'min/signup.js'
    },
    'initial_invite': {
        'source_filenames': (
            'third/jquery-validate/jquery.validate.js',
            'js/initial_invite.js',
            ),
        'output_filename':  'min/initial_invite.js'
    },
   'api': {
        'source_filenames': ('js/api.js',),
        'output_filename':  'min/api.js'
    },
    'app_debug': {
        'source_filenames': ('js/debug.js',),
        'output_filename':  'min/app_debug.js'
    },
    'app': {
        'source_filenames': [
            'third/bootstrap-notify/js/bootstrap-notify.js',
            'third/html5-formdata/formdata.js',
            'third/jquery-validate/jquery.validate.js',
            'third/jquery-form/jquery.form.js',
            'third/jquery-filedrop/jquery.filedrop.js',
            'third/jquery-caret/jquery.caret.1.02.js',
            'third/xdate/xdate.dev.js',
            'third/spin/spin.js',
            'third/jquery-mousewheel/jquery.mousewheel.js',
            'third/jquery-throttle-debounce/jquery.ba-throttle-debounce.js',
            'third/jquery-idle/jquery.idle.js',
            'third/jquery-autosize/jquery.autosize.js',
            'third/jquery-perfect-scrollbar/js/perfect-scrollbar.js',
            'third/lazyload/lazyload.js',
            'third/spectrum/spectrum.js',
            'third/winchan/winchan.js',
            'third/sockjs/sockjs-0.3.4.js',
            'third/handlebars/handlebars.runtime.js',
            'third/marked/lib/marked.js',
            'templates/compiled.js',
            'js/feature_flags.js',
            'js/loading.js',
            'js/util.js',
            'js/dict.js',
            'js/localstorage.js',
            'js/channel.js',
            'js/setup.js',
            'js/muting.js',
            'js/muting_ui.js',
            'js/viewport.js',
            'js/rows.js',
            'js/unread.js',
            'js/stream_list.js',
            'js/filter.js',
            'js/narrow.js',
            'js/reload.js',
            'js/compose_fade.js',
            'js/fenced_code.js',
            'js/echo.js',
            'js/socket.js',
            'js/compose.js',
            'js/stream_color.js',
            'js/admin.js',
            'js/stream_data.js',
            'js/subs.js',
            'js/message_edit.js',
            'js/condense.js',
            'js/resize.js',
            'js/floating_recipient_bar.js',
            'js/ui.js',
            'js/click_handlers.js',
            'js/scroll_bar.js',
            'js/gear_menu.js',
            'js/copy_and_paste.js',
            'js/popovers.js',
            'js/typeahead_helper.js',
            'js/search_suggestion.js',
            'js/search.js',
            'js/composebox_typeahead.js',
            'js/navigate.js',
            'js/hotkey.js',
            'js/favicon.js',
            'js/notifications.js',
            'js/hashchange.js',
            'js/invite.js',
            'js/message_list_view.js',
            'js/message_list.js',
            'js/message_flags.js',
            'js/alert_words.js',
            'js/alert_words_ui.js',
            'js/people.js',
            'js/message_store.js',
            'js/server_events.js',
            'js/zulip.js',
            'js/activity.js',
            'js/colorspace.js',
            'js/timerender.js',
            'js/tutorial.js',
            'js/templates.js',
            'js/avatar.js',
            'js/settings.js',
            'js/tab_bar.js',
            'js/emoji.js',
            'js/referral.js',
            'js/custom_markdown.js',
            'js/bot_data.js',
            # JS bundled by webpack is also included here if PIPELINE setting is true
        ],
        'output_filename': 'min/app.js'
    },
    'activity': {
        'source_filenames': (
            'third/sorttable/sorttable.js',
        ),
        'output_filename': 'min/activity.js'
    },
    # We also want to minify sockjs separately for the sockjs iframe transport
    'sockjs': {
        'source_filenames': ('third/sockjs/sockjs-0.3.4.js',),
        'output_filename': 'min/sockjs-0.3.4.min.js'
    },
}

if PIPELINE:
    JS_SPECS['app']['source_filenames'].append('js/bundle.js')

app_srcs = JS_SPECS['app']['source_filenames']

PIPELINE_JS = {}  # Now handled in tools/minify-js
PIPELINE_JS_COMPRESSOR  = None
PIPELINE_CSS_COMPRESSOR = 'pipeline.compressors.yui.YUICompressor'
PIPELINE_YUI_BINARY     = '/usr/bin/env yui-compressor'

########################################################################
# LOGGING SETTINGS
########################################################################

ZULIP_PATHS = [
    ("SERVER_LOG_PATH", "/var/log/zulip/server.log"),
    ("ERROR_FILE_LOG_PATH", "/var/log/zulip/errors.log"),
    ("MANAGEMENT_LOG_PATH", "/var/log/zulip/manage.log"),
    ("WORKER_LOG_PATH", "/var/log/zulip/workers.log"),
    ("PERSISTENT_QUEUE_FILENAME", "/home/zulip/tornado/event_queues.pickle"),
    ("JSON_PERSISTENT_QUEUE_FILENAME", "/home/zulip/tornado/event_queues.json"),
    ("EMAIL_MIRROR_LOG_PATH", "/var/log/zulip/email-mirror.log"),
    ("EMAIL_DELIVERER_LOG_PATH", "/var/log/zulip/email-deliverer.log"),
    ("LDAP_SYNC_LOG_PATH", "/var/log/zulip/sync_ldap_user_data.log"),
    ("QUEUE_ERROR_DIR", "/var/log/zulip/queue_error"),
    ("STATS_DIR", "/home/zulip/stats"),
    ("DIGEST_LOG_PATH", "/var/log/zulip/digest.log"),
    ]

# The Event log basically logs most significant database changes,
# which can be useful for debugging.
if VOYAGER:
    EVENT_LOG_DIR = None
else:
    ZULIP_PATHS.append(("EVENT_LOG_DIR", "/home/zulip/logs/event_log"))

for (var, path) in ZULIP_PATHS:
    if DEVELOPMENT:
        # if DEVELOPMENT, store these files in the Zulip checkout
        path = os.path.basename(path)
    vars()[var] = path

ZULIP_WORKER_TEST_FILE = '/tmp/zulip-worker-test-file'

if IS_WORKER:
    FILE_LOG_PATH = WORKER_LOG_PATH
else:
    FILE_LOG_PATH = SERVER_LOG_PATH

LOGGING = {
    'version': 1,
    'disable_existing_loggers': True,
    'formatters': {
        'default': {
            'format': '%(asctime)s %(levelname)-8s %(message)s'
        }
    },
    'filters': {
        'ZulipLimiter': {
            '()': 'zerver.lib.logging_util.ZulipLimiter',
        },
        'EmailLimiter': {
            '()': 'zerver.lib.logging_util.EmailLimiter',
        },
        'require_debug_false': {
            '()': 'django.utils.log.RequireDebugFalse',
        },
        'nop': {
            '()': 'zerver.lib.logging_util.ReturnTrue',
        },
        'require_really_deployed': {
            '()': 'zerver.lib.logging_util.RequireReallyDeployed',
        },
    },
    'handlers': {
        'zulip_admins': {
            'level':     'ERROR',
            'class':     'zerver.handlers.AdminZulipHandler',
            # For testing the handler delete the next line
            'filters':   ['ZulipLimiter', 'require_debug_false', 'require_really_deployed'],
            'formatter': 'default'
        },
       'console': {
            'level':     'DEBUG',
            'class':     'logging.StreamHandler',
            'formatter': 'default'
        },
        'file': {
            'level':       'DEBUG',
            'class':       'logging.handlers.TimedRotatingFileHandler',
            'formatter':   'default',
            'filename':    FILE_LOG_PATH,
            'when':        'D',
            'interval':    7,
            'backupCount': 100000000,
        },
        'errors_file': {
            'level':       'WARNING',
            'class':       'logging.handlers.TimedRotatingFileHandler',
            'formatter':   'default',
            'filename':    ERROR_FILE_LOG_PATH,
            'when':        'D',
            'interval':    7,
            'backupCount': 100000000,
        },
    },
    'loggers': {
        '': {
            'handlers': ['console', 'file', 'errors_file'],
            'level':    'INFO',
            'propagate': False,
        },
        'django': {
            'handlers': (['zulip_admins'] if ERROR_REPORTING else [])
                        + ['console', 'file', 'errors_file'],
            'level':    'INFO',
            'propagate': False,
        },
        'zulip.requests': {
            'handlers': ['console', 'file', 'errors_file'],
            'level':    'INFO',
            'propagate': False,
        },
        'zulip.queue': {
            'handlers': ['console', 'file', 'errors_file'],
            'level':    'WARNING',
            'propagate': False,
        },
        'zulip.management': {
            'handlers': ['file', 'errors_file'],
            'level':    'INFO',
            'propagate': False,
        },
        'requests': {
            'handlers': ['console', 'file', 'errors_file'],
            'level':    'WARNING',
            'propagate': False,
        },
        ## Uncomment the following to get all database queries logged to the console
        # 'django.db': {
        #     'handlers': ['console'],
        #     'level': 'DEBUG',
        #     'propagate': False,
        # },
    }
}

TEMPLATE_CONTEXT_PROCESSORS = (
    'zerver.context_processors.add_settings',
    'zerver.context_processors.add_metrics',
)

ACCOUNT_ACTIVATION_DAYS=7

LOGIN_REDIRECT_URL='/'

# Client-side polling timeout for get_events, in milliseconds.
# We configure this here so that the client test suite can override it.
# We already kill the connection server-side with heartbeat events,
# but it's good to have a safety.  This value should be greater than
# (HEARTBEAT_MIN_FREQ_SECS + 10)
POLL_TIMEOUT = 90 * 1000
# iOS App IDs
ZULIP_IOS_APP_ID = 'com.zulip.Zulip'
DBX_IOS_APP_ID = 'com.dropbox.Zulip'

########################################################################
# SSO AND LDAP SETTINGS
########################################################################

USING_APACHE_SSO = ('zproject.backends.ZulipRemoteUserBackend' in AUTHENTICATION_BACKENDS)

if (len(AUTHENTICATION_BACKENDS) == 1 and
    AUTHENTICATION_BACKENDS[0] == "zproject.backends.ZulipRemoteUserBackend"):
    HOME_NOT_LOGGED_IN = "/accounts/login/sso"
    ONLY_SSO = True
else:
    HOME_NOT_LOGGED_IN = '/login'
    ONLY_SSO = False
AUTHENTICATION_BACKENDS += ('guardian.backends.ObjectPermissionBackend',)
AUTHENTICATION_BACKENDS += ('zproject.backends.ZulipDummyBackend',)

POPULATE_PROFILE_VIA_LDAP = bool(AUTH_LDAP_SERVER_URI)

if POPULATE_PROFILE_VIA_LDAP and \
       not 'zproject.backends.ZulipLDAPAuthBackend' in AUTHENTICATION_BACKENDS:
    AUTHENTICATION_BACKENDS += ('zproject.backends.ZulipLDAPUserPopulator',)
else:
    POPULATE_PROFILE_VIA_LDAP = 'zproject.backends.ZulipLDAPAuthBackend' in AUTHENTICATION_BACKENDS or POPULATE_PROFILE_VIA_LDAP
########################################################################
# EMAIL SETTINGS
########################################################################

# If an email host is not specified, fail silently and gracefully
if not EMAIL_HOST and PRODUCTION:
    EMAIL_BACKEND = 'django.core.mail.backends.dummy.EmailBackend'
elif DEVELOPMENT:
    # In the dev environment, emails are printed to the run-dev.py console.
    EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
else:
    EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'

EMAIL_HOST_PASSWORD = get_secret('email_password')
if "EMAIL_GATEWAY_PASSWORD" not in vars():
    EMAIL_GATEWAY_PASSWORD = get_secret('email_gateway_password')
if "AUTH_LDAP_BIND_PASSWORD" not in vars():
    AUTH_LDAP_BIND_PASSWORD = get_secret('auth_ldap_bind_password')

########################################################################
# MISC SETTINGS
########################################################################

if PRODUCTION:
    # Filter out user data
    DEFAULT_EXCEPTION_REPORTER_FILTER = 'zerver.filters.ZulipExceptionReporterFilter'

# This is a debugging option only
PROFILE_ALL_REQUESTS = False

CROSS_REALM_BOT_EMAILS = set(('feedback@zulip.com', 'notification-bot@zulip.com'))
DATABASES = {
  'default': {
    'ENGINE': 'django.db.backends.postgresql_psycopg2',
    'NAME': 'zulip',
    'USER': 'zulip',
    'PASSWORD': 'zulip',
    'HOST': 'database',
    'PORT': '5432',
    'SCHEMA': 'zulip',
    'CONN_MAX_AGE': 600,
    'OPTIONS': {
        'connection_factory': TimeTrackingConnection,
        'sslmode': 'prefer',
    },
  },
}
EXTERNAL_HOST = 'team.comnmodel.org'
EMAIL_HOST = 'smtp.gmail.com'
AUTH_LDAP_BIND_DN = 'cn=admin,dc=comnmodel,dc=org'
NOREPLY_EMAIL_ADDRESS = 'noreply@comnmodel.org'
AUTH_LDAP_SERVER_URI = 'ldap.comnmodel.org'
ZULIP_ADMINISTRATOR = 'rey@gmail.com'
AUTH_LDAP_BIND_PASSWORD = 'xxx'
EMAIL_HOST_USER = 'rey@gmail.com'
DEFAULT_FROM_EMAIL = 'Zulip <noreply@comnmodel.org>'
AUTH_LDAP_APPEND_DOMAIN = 'None'
galexrt commented 8 years ago

@reyman I think I now know what one of the problems is. Could you show what files are listed (with ls -ahl option) in your data mount on your host, then I can tell you need to do to fix your problem, that the entrypoint always tries to create the database default data.

Other bugs I found (will fix):

  1. I'm adding exceptions more variables that need to be in another config file then the default confi file (not related to your problem, but should save me some issues later on)
reyman commented 8 years ago

Yeah, the file into /data


➜  /data ls -ahl /data
total 12K
drwxr-xr-x  3 root root 4,0K janv. 13 18:27 .
drwxr-xr-x 23 root root 4,0K févr. 28 23:29 ..
drwxr-xr-x  4 root root 4,0K janv. 13 18:56 slapd
galexrt commented 8 years ago

Is this your host data mount folder or the container one? (the host data mount folder with the zulip, postgresql, etc. folder in it.) Run ls -ahl * in your hosts mount folder.

reyman commented 8 years ago

This is my host folder (vps /data)

galexrt commented 8 years ago

And the docker-compose.yml volumes points to it?

galexrt commented 8 years ago

Taken from the default docker-compose.yml

volumes:
    - "/opt/docker/zulip/zulip:/data:rw"

Then your host mount directory would be /opt/docker/zulip/zulip, did you change the directory?

reyman commented 8 years ago

You're right, here the content :


➜  ~ sudo ls -ahl /opt/docker/zulip/zulip 
total 24K
drwxr-xr-x 5 root   root   4,0K mars   6 00:28 .
drwxr-xr-x 5 root   root   4,0K mars   5 23:57 ..
drwxr-xr-x 2 root   root   4,0K mars   5 23:57 backups
drwxr-xr-x 2 root   root   4,0K mars   6 00:28 certs
drwxr-xr-x 2 reyman reyman 4,0K mars   5 23:57 uploads
-rw-r--r-- 1 root   root    609 mars   6 00:28 zulip-secrets.conf
galexrt commented 8 years ago

Create a file at /opt/docker/zulip/zulip named .initiated and try again. That should fix your problem.

reyman commented 8 years ago

I have one error :

zulip_1     | 2016-03-13 18:37:48,940 INFO exited: zulip-postsetup-create_user (exit status 127; not e
xpected)
galexrt commented 8 years ago

@reyman I'm going to fix the postsetup user creation script returning a bad return code. But so that you know, this isn't a "real"/bad error.

Thanks for helping me test it! :)

galexrt commented 8 years ago

I pushed a small change for this, as it should now not show this as an error anymore.

reyman commented 8 years ago

Yes, i retry later. When i launch sudo docker-compose up, how can i get the hand after execution without closing ?

galexrt commented 8 years ago

Add -d to the docker-compose -d up.

reyman commented 8 years ago

Yeah, it works :)

Juste, when i log, i have this error

Forbidden (403)
CSRF verification failed. Request aborted.
galexrt commented 8 years ago

Do you run Zulip behind a proxy?

On Mon, Mar 14, 2016, 4:48 PM Rey notifications@github.com wrote:

Yeah, it works :)

Juste, when i log, i have this error

Forbidden (403) CSRF verification failed. Request aborted.

— Reply to this email directly or view it on GitHub https://github.com/Galexrt/docker-zulip/issues/61#issuecomment-196376890 .

reyman commented 8 years ago

Hum @Galexrt, yeah, Zulip run using the nginx docker nginx proxy image osixia/openldap

2d9c16de8669 jwilder/nginx-proxy "/app/docker-entrypoi" 2 weeks ago Up 2 hours 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp nginx

I configure using the option given in the doc.

    VIRTUAL_HOST: "team.comnmodel.org"
    VIRTUAL_PROTO: "https"
    VIRTUAL_PORT: "443"
galexrt commented 8 years ago

Could you try running zulip on different ports without the proxy? Because this seems to be related to a missing header (maybe with the proxy).

@reyman Could you please open a new issue for this new error?