Repository: getsentry/sentry

Issue:
Add a `sentry init --dev` command
This should spit out a similar, but slightly different config tuned for local development.

Basically, the changes should be:
- set `DEBUG = True` in `sentry.conf.py`.
- set `mail.backend` to something more sensible, probably `console` is a sane default since most people aren't running local SMTP servers in `config.yml`
- set `CELERY_ALWAYS_EAGER = True` on `sentry.conf.py`
- Prefill stuff in `SENTRY_FEATURES`?

Thoughts? @getsentry/team What else do you do in your local config to make things work reasonably.



Discussion:
Maybe (maybe) a preference to sqlite if it's installed and/or on?

-1 on CELERY_ALWAYS_EAGER, it causes recursion issues and should not be promoted (especially with --workers)

> Maybe (maybe) a preference to sqlite if it's installed and/or on?

I think we're trying to get away from using sqlite at all since our code pretty much depends on Postgres at this point. Generally sqlite is fine, but we don't really want to encourage it since it'll likely cause issues with certain things.

we removed support for all dbs that aren't Postgres (including sqlite) so -1

> 1 on CELERY_ALWAYS_EAGER, it causes recursion issues and should not be promoted

I've never had a single issue. Was this an issue a while back, or is this currently an issue? Or am I just lucky and have never hit an issue?

> (especially with --workers)

Yeah, I agree it's much less of an issue now that it's easier to spawn all the workers. Maybe we also make `--workers` default? and you have to opt out with `--no-workers`?


Resolving patch:
diff --git a/src/sentry/runner/commands/init.py b/src/sentry/runner/commands/init.py
--- a/src/sentry/runner/commands/init.py
+++ b/src/sentry/runner/commands/init.py
@@ -12,9 +12,10 @@
 
 
 @click.command()
+@click.option('--dev', default=False, is_flag=True, help='Use settings more conducive to local development.')
 @click.argument('directory', required=False)
 @click.pass_context
-def init(ctx, directory):
+def init(ctx, dev, directory):
     "Initialize new configuration directory."
     from sentry.runner.settings import discover_configs, generate_settings
     if directory is not None:
@@ -34,7 +35,7 @@ def init(ctx, directory):
     if directory and not os.path.exists(directory):
         os.makedirs(directory)
 
-    py_contents, yaml_contents = generate_settings()
+    py_contents, yaml_contents = generate_settings(dev)
 
     if os.path.isfile(yaml):
         click.confirm("File already exists at '%s', overwrite?" % click.format_filename(yaml), abort=True)
diff --git a/src/sentry/runner/settings.py b/src/sentry/runner/settings.py
--- a/src/sentry/runner/settings.py
+++ b/src/sentry/runner/settings.py
@@ -48,6 +48,7 @@
 # Instruct Sentry that this install intends to be run by a single organization
 # and thus various UI optimizations should be enabled.
 SENTRY_SINGLE_ORGANIZATION = True
+DEBUG = %(debug_flag)s
 
 #########
 # Cache #
@@ -178,7 +179,7 @@
 # Mail Server #
 ###############
 
-# mail.backend: 'smtp'  # Use dummy if you want to disable email entirely
+# mail.backend: '%(mail.backend)s'  # Use dummy if you want to disable email entirely
 # mail.host: 'localhost'
 # mail.port: 25
 # mail.username: ''
@@ -210,13 +211,18 @@ def generate_secret_key():
     return get_random_string(50, chars)
 
 
-def generate_settings():
+def generate_settings(dev=False):
     """
     This command is run when ``default_path`` doesn't exist, or ``init`` is
     run and returns a string representing the default data to put into their
     settings file.
     """
-    context = {'secret_key': generate_secret_key()}
+    context = {
+        'secret_key': generate_secret_key(),
+        'debug_flag': dev,
+        'mail.backend': 'console' if dev else 'smtp',
+    }
+
     py = PY_CONFIG_TEMPLATE % context
     yaml = YAML_CONFIG_TEMPLATE % context
     return py, yaml


Test patch: