Граф коммитов

139 Коммитов

Автор SHA1 Сообщение Дата
Ed Morley 6945c4c471
Bug 1165259 - Add infrastructure documentation (#4766)
- Adds a new "infrastructure" section to the docs, which describes
  architecture, administration and troubleshooting (fixes bug 1165259).
- Adds code comments to any deployment-related files in the repository.
- Adds documentation for the various ways in which users can access
  Treeherder data (fixes bug 1335172).
- Reorganises the structure of some of the existing non-infrastructure
  docs, to make the documentation easier to navigate.
2019-03-11 21:39:34 +00:00
Ed Morley 7cce7b2fa7 Bug 1308354 - Remove SCL3-specific code now we're on Heroku 2016-10-24 18:55:03 +01:00
Ed Morley 1b4010f728 Bug 1297666 - Remove supervisord configs/documentation
Since it's a non-default workflow that isn't kept up to date, and is
going to be even less relevant once we switch to tooling that uses the
Procfile.
2016-08-26 15:56:53 +01:00
Ed Morley 9e20b7934d Bug 1247344 - Enable Django system checks during testing and deployment
`manage.py check --deploy` is now run during Travis testing and as part
of stage/prod/Heroku deployment. It checks for a number of common
configuration mistakes & ensures security best practices are being
followed:
https://docs.djangoproject.com/en/1.8/ref/checks/
2016-05-06 16:09:11 +01:00
Ed Morley 5b48f4b49b Bug 1258700 - Update to WhiteNoise 3.0
There are some backwards incompatible changes:
http://whitenoise.evans.io/en/latest/changelog.html
https://github.com/evansd/whitenoise/compare/v2.0.6...v3.0

Specifically:
* The CLI compression utility must now be called via
`python -m whitenoise.compress` rather than `python -m whitenoise.gzip`.
* The `whitenoise.django.GzipManifestStaticFilesStorage` storage backend
has moved to `whitenoise.storage.CompressedManifestStaticFilesStorage`.
* The internal `add_files()` method has been split into two and the part
which we need to subclass is now named `update_files_dictionary()`. See:
07f9c0bece
2016-03-30 13:00:23 +02:00
Ed Morley a83f930296 Bug 1213230 - Use pip 8's require-hashes feature instead of peep
As of pip 8, peep has now been integrated into pip.

Migrating from peep to this native feature has several advantages:
* It avoids the complexity/learning curve of using a wrapper around pip.
* It means we do not need to fork the official Heroku Python buildpack
  (which handles pip installation of requirements files) in order to use
  hash verification on Heroku. (Once the buildpack updates to pip 8.)
* Omitted sub-dependencies result in install-time errors rather than
  the user discovering omissions at run-time.
* pip's native caching is used, and all packages are installed in one
  pip invocation, so it's significantly faster.
* It has better handling of errors and corner cases.

Key facts about the native feature:
* hash-checking mode is enabled if at least one hash is found in the
  requirements files passed to pip, or can be force enabled by passing
  `--requires-hashes` when running `pip install`.
* Once enabled, hash-checking mode enforces that all packages:
  - are pinned to a specific version
  - have hashes listed
  - have all sub-dependencies specified
* Older versions of pip will error out if either `--require-hashes` or
  the requirements file `--hash` syntax is used, meaning it's not
  possible to accidentally lose hash-checking protection if the pip used
  is older than expected.

For more details, see:
https://pip.pypa.io/en/stable/user_guide/#hash-checking-mode
https://pip.pypa.io/en/stable/reference/pip_install/#hash-checking-mode

The pip version on Travis and in the Vagrant virtualenv has been updated
to 8.0.2 in bug 1241144, and the stage/prod virtualenv in bug 1241519.
The Heroku Python buildpack pip was updated in bug 1241909.

The requirements files hashes were ported using `peep port`, and then
comments/URLs re-added by hand.
2016-02-15 12:06:17 +00:00
Ed Morley 61d596267a Bug 1212937 - Remove API support for OAuth credentials
Since they are deprecated and all submitters have switched over to using
Hawk credentials instead.

The automatically created migrations file was edited to remove the
unused `models` import, since otherwise flake8 complains. We could
alternatively exclude the migrations directory from flake8, however we
would then miss linter errors in any hand-written migrations files.

In addition, Django have fixed the issue in 1.9:
a7bc00e17b
2015-12-16 18:12:41 +00:00
Ed Morley 26946f754c Bug 1223384 - Stop running clear_cache on stage/prod deploy
Since it should be unnecessary, and causes additional load until the
cache is re-populated, since:
* the builds-{4hr,running,pending} tasks have to ingest all jobs,
  including those previously seen
* the pushlog task defaults back to "the last 10 pushes", which in the
  case of inactive repos, means extra busy work, and for active repos
  means we might actually miss commits (particularly if the prod push
  was to fix an issue that has say broken ingestion for the last X mins)
2015-11-12 09:51:35 +00:00
Ed Morley f059f88d85 Bug 1205758 - Run `grunt build` as part of the stage/prod deploy
In update.py, the line outputting revision.txt has to be moved later,
since the `dist/` directory won't exist until grunt build has run. In
addition, since `grunt build` removes the entire `dist/` directory, we
no longer need to manually remove *.gz.

We use the `--production` options for both `npm install` and
`grunt build`, so that the `devDependencies` in package.json are
ignored, and we only install/load the ones listed under `dependencies`
in package.json - since that's all that is required for the build.

We have to use `./node_modules/.bin/grunt` rather than `grunt`, since
grunt-cli is not installed globally on the treeherder admin machine for
greater isolation between stage and production.
2015-10-31 16:06:08 +00:00
Ed Morley 2e0cf48846 Bug 1205758 - Run `npm install --production` during stage/prod deploy
Install the non-development packages listed under `dependencies` in
package.json, in preparation for running grunt build during the deploy.
2015-10-28 09:41:11 +00:00
Ed Morley d7d106e68c Bug 1214183 - Make the deploy script use requests not urllib/urllib2
Also remove unnecessary check for the API key and app id, and make any
errors raise (since it won't affect the deploy itself, but will make
issues more obvious in the IRC bot comments).
2015-10-13 19:40:15 +01:00
Ed Morley 6735213a04 Bug 1212886 - Fail early if stage/prod grunt build forgotten
This prevents 404s on the UI if the output from `grunt build` hasn't
been committed to the repo prior to deploying to stage/prod.
2015-10-08 16:09:09 +01:00
Ed Morley 525866a553 Bug 1201517 - Export a revision.txt containing the Git SHA on Heroku too
The Git SHA is available in the SOURCE_VERSION environment variable:
https://devcenter.heroku.com/articles/buildpack-api#bin-compile-summary

Also update the What's Deployed links to include Heroku in the
comparison alongside stage/prod.
2015-09-08 17:22:24 +01:00
Ed Morley 5892c72eb2 Bug 1197796 - Make WhiteNoise serve the static assets gzipped
On Heroku, there is no load balancer or Varnish-like cache in front of
gunicorn, so we must handle gzipping responses in the app.

In order for WhiteNoise to serve gzipped static content, assets must be
gzipped on disk in advance (doing so on-demand in Python would not be
as performant). WhiteNoise will then serve the `.gz` version of files in
preference to the original, if the client indicated it supported gzip.

For assets covered by Django's collectstatic, gzipping the assets only
requires using WhiteNoise's GzipManifestStaticFilesStorage backend,
which wraps Django's ManifestStaticFilesStorage to create hashed+gzipped
versions of static assets:
http://whitenoise.evans.io/en/latest/django.html#add-gzip-and-caching-support

The collectstatic generated files will then contain the file hash in
their filename, so WhiteNoise can also serve them with a large max-age
to avoid further requests if the file contents have not changed.

For the UI files under `dist/`, we cannot rely on the Django storage
backend, since the directory isn't covered by STATICFILES_DIRS (it is
instead made known to WhiteNoise via `WHITENOISE_ROOT`). As such, files
under `dist/` are gzipped via an additional step during deployment. See:
http://whitenoise.evans.io/en/latest/base.html#gzip-support

Files whose extension is on the blacklist, or that are not >5% smaller
when compressed, are skipped during compression.
2015-08-26 22:10:05 +01:00
Ed Morley abbaa1918d Bug 1198452 - Stop creating treeherder.*.org/media/revision
Now that the IRC pushbot configs/What's Deployed links have been updated
to use the new revision.txt file location, we can stop creating the file
in the old location.
2015-08-26 19:36:33 +01:00
Ed Morley 90576b9fd9 Bug 1198452 - Save the deployed revision to <site-root>/revision.txt
Since WhiteNoise won't serve files from /media/, so the existing file
in `treeherder/webapp/media/` 404s when accessed via:
https://treeherder.{mozilla,allizom}.org/media/revision

IMO the site root makes more sense for this file anyway, so let's just
save it under `dist/`. Also adds a .txt extension for clarity.

The old file has been left for now to ease the transition, and will be
deleted once the IRC pushbots config and What's Deployed URLs have been
updated.
2015-08-25 21:37:48 +01:00
Ed Morley 90ba77e596 Bug 1192801 - Remove per-file MPL boilerplate since it's unnecessary
The MPL 2.0 terms state that as long as a LICENSE file is present, the
per-file header text is not required. See "Exhibit A" at the end of:
https://www.mozilla.org/MPL/2.0/
2015-08-18 23:32:11 +01:00
Ed Morley f9ee81d999 Bug 1169944 - Always install the New Relic package, not just on prod
For bug 1124278, we're going to want to sprinkle new relic annotations
around the codebase, so by always installing it, we save having to stub
these out in development/on Travis. It also seems wise to have prod
running as close to the same packages as in development.

Since NEW_RELIC_LICENSE_KEY isn't set locally, plus
NEW_RELIC_DEVELOPER_MODE is set to true, the New Relic agent doesn't
submit anything. See:
https://docs.newrelic.com/docs/agents/python-agent/installation-configuration/python-agent-configuration#developer_mode
2015-08-11 23:23:26 +01:00
Ed Morley 1c00ccfcc7 Bug 1192661 - Clean up Python import order
Created using |isort -p tests -rc .| and a couple of manual tweaks.

The order is:
* futures
* std library
* third party packages
* local imports
* relative local imports
...with each group ordered with "import x" before "from x import y", and
then alphabetically.
2015-08-10 18:33:49 +01:00
Ed Morley 1af312e0cc Bug 1175432 - Use dj-database-url to simplify DB environment variables
dj-database-url extracts DB host, port, username, password and database
name from the env variable 'DATABASE_URL' (unless another env variable
name is specified). If the env variable is not defined, it falls back to
the default passed to dj_database_url.config().

This means for Heroku and similar we can replace the multiple DB env
variables with just one URL for default & one for read_only.

This also effectively makes the setting of the read only DB variable
mandatory for stage/production/heroku, since DEFAULT_DATABASE_URL won't
be valid for them - so prevents us inadvertently not using the read only
DB.

The deployment script also had to be updated, so that we set the
prod/stage-specific environment variables before using manage.py, since
dj-database-url cannot rely on what's in the stage/prod local.py config
(which isn't a bad thing, since we're deprecating that file).
2015-07-15 14:58:46 +01:00
Ed Morley b9855cb9f9 Bug 1178832 - Cleanup leftovers from using Cython
Also remove some .gitignore entries from when we had a vendor directory.
2015-07-01 00:21:36 +01:00
Ed Morley 58813b0c51 Bug 1169916 - Stop using Cython to build the log parser
Since it only speeds up parsing by a few percent of total runtime, and
is therefore not worth the added complexity for deployment and local
hack-test-debug cycles when working on the log parser.

The .gitignore and update.py entries will be removed in a later commit,
once the stage/prod src directories have been cleaned up.
2015-06-30 14:51:57 +01:00
Ed Morley caaec5d047 Bug 1178719 - Use --noinput when running migrate from scripts
Since otherwise we may end up with interactive prompts.
Note: When using call_command() we instead have to use 'interactive'
instead of 'noinput' due to https://code.djangoproject.com/ticket/22985,
which is only fixed in Django 1.8+.
2015-06-30 14:15:02 +01:00
Ed Morley 27d8f69dee Bug 1169178 - Consolidate peep invocations
There's no need to make multiple calls to peep - we can just combine
them into one. Not changing the puppet instances for Vagrant, since the
calls are made in two separate puppet modules and so would require a bit
of refactoring, which is going to occur in bug 1074151 and friends.
2015-05-28 09:40:20 +01:00
Ed Morley da294ba761 Bug 1056877 - Stop using/referring to the separate treeherder-ui repo
Since it has now been merged into this one.
2015-05-20 16:55:55 +01:00
Ed Morley 57af1d7e2d Merge pull request #537 from MikeLing/bugfix-1160873
Bug 1160873 - Add timeout to requests that are missing them
2015-05-16 01:45:04 +01:00
MikeLing 4dc05d21b5 Bug 1160873 - Add timeout to requests that are missing them 2015-05-16 08:34:56 +08:00
Mauro Doglio 597282fe58 Bug 1145606 - Setup treeherder to deploy on heroku
I added a Procfile listing all the different python services treeherder needs.
Heroku provides deployment-specific settings via environment variables, so I had to modify the settings file to listen to them where that wasn't the case. I created an enviroment variable IS_HEROKU which allows to have a heroku-only configuration where needed.
The db service is provided by Amazon RDS, which requires a ssl connection. To enable ssl in the MySQLdb python client I had to modify Datasource (and bump up the version used).
The cache service is provided by the memcachier heroku addon. Heroku recommends to use pylibmc, so I set it up according to the docs here https://devcenter.heroku.com/articles/memcachier#python.
The amqp service is provided by the CloudAMQP addon.
I added a post_compile script that runs every time we deploy. We should run every build step we require in there, like static asset minification, collection, etc.
To share the oauth credentials among the various services I used an environment variable. I also added an option to export_project_credentials so that the credentials can be printed to stdout. This should come handy when we will need to update the environment-stored credentials with the ones in the db.
2015-05-14 13:54:41 +01:00
Ed Morley 343d112f93 Bug 1158893 - Delete any existing Cython build output as part of deploy
The Cython build process creates .c and .so files in the log_parser
directory, which only get re-created if the original source changes.
We recently updated the version of Cython, however this doesn't trigger
re-building them. To avoid surprises, we should purge them like we do
for the .pyc files.

In addition, there is no need to delete .pyc files from the UI source
directory, since that does not contain any Python files.
2015-04-27 18:06:55 +01:00
Ed Morley bd60d36364 Bug 1076886 - Deploy: Don't specify the wrong revision to New Relic
We're passing settings.UPDATE_REF, which is the default ref value, not
the actual value that was passed via the Chief web UI. As such, New
Relic was always displaying the revision deployed as "master", even if
it was a non-master branch deploy. Ideally we'd use the value of 'ref'
from pre_update(), but that's not available during the deploy() task
(the script is run in three independent stages & Chief unhelpfully only
passes 'ref' to the first stage), so we'll have to read it back from the
media/revision file - which will require more mangling in bug 1076886.

For now, seeing as the 'revision' property is optional, lets just omit
it, rather than setting it to a sometimes wrong value.
2015-04-23 14:19:04 +01:00
Ed Morley 72ca5826fe Bug 1146184 - Use virtualenv and peep for stage/prod package management
Prior to this change, on stage/production we didn't use virtualenvs
(unlike dev/the local Vagrant project) and instead pip installed
packages globally (when puppet ran periodically), using requirements
files that are not in the repo.

Now during deployment, a virtualenv is created and then populated using
peep (which uses hashes to verify the contents of packages before pip
installing them). The virtualenv is then made relocatable (as best as it
can, the feature isn't perfect), the lib64 symlinks are made relative,
and then the virtualenv is rsynced to all nodes, along with the source.

The one main remaining limitation of --relocatable is that the bash
activate script will not work on the other nodes - however the wrapper
scripts under treeherder-service/bin/ add venv/bin/ to PATH so using the
activate script is unnecessary for them. This just leaves running
manage.py commands locally on a node, for we can use:
|../venv/bin/python manage.py foo|, an alias or else we can fix up the
activate scripts in a follow-up bug.
2015-04-20 23:48:27 +01:00
Ed Morley 8478629ef4 Bug 1056877 - Update links & puppet/Vagrant config for new repo name
The 'treeherder-service' repo has been renamed to 'treeherder', ready
for when the treeherder-ui repo is imported into it. This means the
Github URL, Travis URL and directory name when cloned changes. The Read
The Docs URL cannot be changed, so for now we will leave as-is, and in
the future (once service and UI docs combined) we will create a new
project on RTD with name "treeherder".

This updates doc links and puppet/Vagrant configs, but leaves the
stage/prod deploy script alone, since renaming the directories on our
infra is non-trivial. The dev instance will need some TLC since unlike
stage/prod, it does use the puppet scripts in the repo.
2015-04-20 22:00:04 +01:00
Ed Morley d40ce31922 Bug 1156457 - Set the New Relic deploy user to "Chief"
So we don't use the default.
2015-04-20 21:13:31 +01:00
Ed Morley 96470f8d19 Bug 1076737 - Correct New Relic deployment URL and attribute name
The current values were copied from another project's deploy script, but
they are not working - so let's use what the latest New Relic docs say
we should use.
2015-04-20 15:08:18 +01:00
Ed Morley 45cee6856e Bug 1076737 - Followup to fix exception whilst notifying New Relic 2015-04-20 14:49:16 +01:00
Mauro Doglio 8039330160 Bug 1076737 - notify newrelic on deployment 2015-04-20 13:39:24 +01:00
Ed Morley e889dd1c95 Bug 1139917 - Deploy script: Don't restart apache in rsync_code()
The restart-jobs script now also gracefuls apache (after draining the
nodes to avoid errors), so we don't want to do so in update.py any more.
2015-03-05 15:15:23 +00:00
Ed Morley b4a2fb6ea8 Bug 1138392 - Deploy script: don't pass 'ctx' to @hostgroups functions
...same as @task. Oops.
2015-03-02 17:57:18 +00:00
Ed Morley cc60b10517 Bug 1138392 - Deploy script: @task functions shouldn't be passed 'ctx'
...since the decorator does that for us.
2015-03-02 17:54:02 +00:00
Ed Morley c0e59f9bea Bug 1059814 - Deploy script: Fix commander_settings import
Apparently the current directory is only sometimes on the path & I
mis-read or understood the docs, sigh. Let's just keep the sys.path
manipulation and use #noqa to keep flake8 quiet.
2015-03-02 17:44:46 +00:00
Ed Morley 87f7a32e00 Bug 1138392 - Deploy script: Make IRC output more accurate
Anything in the deploy script decorated with @task or @hostgroups ends
up having it's progress displayed in IRC by the bot - eg:
[2015-02-23 20:09:40] Finished deploy_log (0.454s)

However, the "deploy_X" @hostgroup functions were actually only
rsyncing the code (which is fast compared to restarting the processes),
but the name used to imply the whole deploy for that node type was
complete.

The new structure not only reduces code duplication, but makes the IRC
output more accurate, to provide a better idea as to what stage the
deploy is at, and which are the problematic steps in the case of errors.
2015-03-02 15:47:41 +00:00
Ed Morley 532429a9c4 Bug 1088705 - Deploy script: Make the git output less chatty
The git reset already outputs the SHA/commit message for HEAD so
most of this additional output is unnecessary.
2015-03-02 15:47:40 +00:00
Ed Morley 0e67ca47a4 Bug 1088705 - Deploy script: Generate revision file before rsyncing it
Previously the revision file was regenerated after it had already been
rsynced to the webheads, and as such the publicly accessible file
displayed the previous revision, not the new revision.
2015-03-02 15:47:40 +00:00
Ed Morley d011d2f9bd Bug 1135798 - Deploy script: Remove unnecessary submodule git commands
We don't use git submodules, so let's not bother trying to update them.
2015-03-02 15:47:39 +00:00
Ed Morley c3afe9584d Bug 1135798 - Deploy script: Fix the git fetch/reset commands
The current fetch/reset/checkout doesn't correctly update the working
directory when switching between branches. This new approach is
recommended by:
http://stackoverflow.com/a/9589927
2015-03-02 15:47:39 +00:00
Ed Morley ebd237d5a0 Bug 1059814 - Deploy script: Remove unnecessary sys.path additions
The directory of the currently running script is already on the path:
https://docs.python.org/2/tutorial/modules.html#the-module-search-path
...so adding it is unnecessary.

In addition, I don't believe we need the treeherder-service directory on
the path, since we don't directly import anything from there.
2015-03-02 15:47:38 +00:00
Cameron Dawson eabe3a47de Bug 1119479 - Fix update script and puppet manifest 2015-02-10 11:34:56 -08:00
Ed Morley 7fa4e973b2 Bug 1130408 - deploy: Only call restart-jobs once per hostgroup
The @hostgroups decorator was causing us to call restart-jobs multiple
times (once for each host within a host group), when we only want to
call it once per group of hosts.

Abstracting the restart-jobs call to its own method also means the IRC
bot will output "restart_jobs complete" after each restart-jobs call,
making the progress through the deployment task clearer.
2015-02-09 13:29:35 +00:00
mdoglio 864148d099 Bug 1079270 - Restart workers individually 2015-02-03 14:04:49 +00:00
mdoglio fd9eb17603 Bug 1123479 - add startup script for a prefork-based log parser 2015-02-02 12:45:29 +00:00