mirror of https://gitlab.com/tildes/tildes.git
Deimos
7 years ago
commit
e980ab3bda
414 changed files with 26238 additions and 0 deletions
-
23.gitignore
-
49CONTRIBUTING.md
-
660LICENSE.md
-
15README.md
-
27Vagrantfile
-
7git_hooks/pre-commit
-
8git_hooks/pre-push
-
19salt/minion
-
5salt/pillar/dev.sls
-
8salt/pillar/monitoring-secrets.example.sls
-
5salt/pillar/monitoring.sls
-
6salt/pillar/prod.sls
-
8salt/pillar/top.sls
-
13salt/salt/boussole.service.jinja2
-
32salt/salt/boussole.sls
-
25salt/salt/cmark-gfm.sls
-
13salt/salt/common.jinja2
-
11salt/salt/consumers/init.sls
-
16salt/salt/consumers/topic_metadata_generator.service.jinja2
-
7salt/salt/cronjobs.sls
-
21salt/salt/development.sls
-
17salt/salt/final-setup.sls
-
19salt/salt/grafana/grafana.conf.jinja2
-
17salt/salt/grafana/grafana.ini.jinja2
-
61salt/salt/grafana/init.sls
-
1salt/salt/gunicorn/gunicorn.conf
-
22salt/salt/gunicorn/gunicorn.service.jinja2
-
11salt/salt/gunicorn/gunicorn.socket
-
41salt/salt/gunicorn/init.sls
-
25salt/salt/nginx/init.sls
-
89salt/salt/nginx/nginx.conf.jinja2
-
16salt/salt/nginx/site-config.sls
-
16salt/salt/nginx/static-sites-config.sls
-
35salt/salt/nginx/tildes-static-sites.conf.jinja2
-
97salt/salt/nginx/tildes.conf.jinja2
-
56salt/salt/postgresql/init.sls
-
6salt/salt/postgresql/pg_hba.conf.jinja2
-
21salt/salt/postgresql/pgbouncer.ini.jinja2
-
25salt/salt/postgresql/pgbouncer.sls
-
57salt/salt/postgresql/site-db.sls
-
44salt/salt/postgresql/test-db.sls
-
28salt/salt/prometheus/exporters/node_exporter.sls
-
28salt/salt/prometheus/exporters/postgres_exporter.sls
-
14salt/salt/prometheus/exporters/prometheus_node_exporter.service
-
15salt/salt/prometheus/exporters/prometheus_postgres_exporter.service
-
14salt/salt/prometheus/exporters/prometheus_redis_exporter.service
-
27salt/salt/prometheus/exporters/redis_exporter.sls
-
57salt/salt/prometheus/init.sls
-
21salt/salt/prometheus/prometheus.conf.jinja2
-
14salt/salt/prometheus/prometheus.service
-
23salt/salt/prometheus/prometheus.yml
-
7salt/salt/prometheus/user.sls
-
58salt/salt/python.sls
-
1salt/salt/rabbitmq/definitions.json
-
82salt/salt/rabbitmq/init.sls
-
14salt/salt/rabbitmq/pg-amqp-bridge.service
-
5salt/salt/rabbitmq/rabbitmq.config
-
6salt/salt/raven.sls
-
144salt/salt/redis/init.sls
-
14salt/salt/redis/modules/rebloom.sls
-
20salt/salt/redis/modules/redis-cell.sls
-
1297salt/salt/redis/redis.conf.jinja2
-
14salt/salt/redis/redis.service
-
24salt/salt/redis/redis_breached_passwords.conf
-
14salt/salt/redis/redis_breached_passwords.service
-
11salt/salt/redis/transparent_hugepage.service
-
7salt/salt/scripts/activate.sh.jinja2
-
5salt/salt/scripts/generate-site-icons.sh.jinja2
-
7salt/salt/scripts/init.sls
-
17salt/salt/self-signed-cert.sls
-
4salt/salt/sentry/common.jinja2
-
64salt/salt/sentry/config.yml.jinja2
-
143salt/salt/sentry/init.sls
-
15salt/salt/sentry/sentry-cron.service.jinja2
-
17salt/salt/sentry/sentry-web.service.jinja2
-
15salt/salt/sentry/sentry-worker.service.jinja2
-
21salt/salt/sentry/sentry.conf.jinja2
-
135salt/salt/sentry/sentry.conf.py
-
42salt/salt/site-icons-spriter.sls
-
40salt/salt/top.sls
-
12salt/salt/webassets.service.jinja2
-
17salt/salt/webassets.sls
-
38tildes/alembic.ini
-
80tildes/alembic/env.py
-
24tildes/alembic/script.py.mako
-
6tildes/boussole.yaml
-
80tildes/consumers/topic_metadata_generator.py
-
49tildes/development.ini
-
14tildes/gunicorn_config.py
-
4tildes/mypy.ini
-
37tildes/production.ini.example
-
54tildes/pylama.ini
-
3tildes/pytest.ini
-
38tildes/requirements-to-freeze.txt
-
105tildes/requirements.txt
-
1tildes/scripts/__init__.py
-
177tildes/scripts/breached_passwords.py
-
124tildes/scripts/clean_private_data.py
-
81tildes/scripts/initialize_db.py
-
22tildes/scripts/site-icons-spriter/css_template.jinja2
@ -0,0 +1,23 @@ |
|||
.vagrant |
|||
Customfile |
|||
|
|||
__pycache__ |
|||
*.py[co] |
|||
|
|||
*.egg-info/ |
|||
|
|||
.cache/ |
|||
.mypy_cache/ |
|||
.webassets-cache/ |
|||
.webassets-manifest |
|||
|
|||
*.gz |
|||
*.log |
|||
|
|||
# don't track the built versions of CSS and JS |
|||
tildes/static/css/* |
|||
tildes/static/js/third_party.js |
|||
tildes/static/js/tildes.js |
|||
|
|||
# don't track the site-icons spritesheet(s) |
|||
tildes/static/images/site-icons* |
@ -0,0 +1,49 @@ |
|||
# Contributing to Tildes development |
|||
|
|||
Outside of actual code changes, there are several other ways to contribute to Tildes development: |
|||
|
|||
* Known issues and plans for upcoming changes are [tracked on GitLab](https://gitlab.com/tildes/tildes/issues). If you've found a bug/problem on the site or have a suggestion, please feel free to submit an issue for it (if one doesn't already exist). If you have a Tildes account, you can also post in [the ~tildes group](https://tildes.net/~tildes) with issues, suggestions, or questions. |
|||
* The [Tildes Docs site](https://docs.tildes.net) is also open-source and accepts contributions. It has a separate repository, also on GitLab: https://gitlab.com/tildes/tildes-static-sites |
|||
* [Donating to Tildes](https://docs.tildes.net/donate) supports its development directly by enabling Deimos to continue working on it full-time. Tildes is a non-profit with no investors and no advertising. Its operation and development relies on donations. |
|||
|
|||
## License |
|||
|
|||
Please take note that Tildes uses [the AGPLv3 license](https://www.gnu.org/licenses/why-affero-gpl.html). This means that if you use the Tildes code to run your own instance of the site, you *must* also open-source the code for your site, including any changes that you've made. If you are not able to open-source the code for your instance, you can not use the Tildes code to run it. |
|||
|
|||
## Setting up a development version |
|||
|
|||
Please see this page on the Tildes Docs for instructions to set up a development version: https://docs.tildes.net/development-setup |
|||
|
|||
## General development information |
|||
|
|||
This page on the Tildes docs contains information about many aspects of Tildes development: https://docs.tildes.net/development |
|||
|
|||
## Contributing code |
|||
|
|||
**Please do not work on significant changes or features without first ensuring that the changes are desired.** If there isn't already an issue related to the change you're intending to make, please [create one first](https://gitlab.com/tildes/tildes/issues/new) to discuss your plans. Similarly, even when there *is* already an issue, if the specifics of how it should work aren't clear, please try to sort that out first (by posting comments on the issue) before doing the work. |
|||
|
|||
In general, anything beyond straightforward fixes and adjustments should have an associated issue. This is for everyone's benefit—it ensures that you don't waste effort working on changes that won't be accepted, and makes it easier for other contributors to see what's already being worked on. |
|||
|
|||
### Choosing what to work on |
|||
|
|||
If you look at [the list of issues](https://gitlab.com/tildes/tildes/issues), there are a few indicators you can use to find a good contribution to work on: |
|||
|
|||
* Make sure the issue isn't already being worked on by someone else. Check the comments on it, and whether it's set as "assigned to" someone. If someone else was working on it but there hasn't been any activity in a while, please post a comment first to check if they're still making progress. |
|||
* Issues with the "high priority" label are ones that are needed soon, and contributions for these will probably be most appreciated. However, they may also be more complex than many other issues, and might not be the best place for a newer contributor to start. |
|||
* Check the "Weight" field on the issue. If set, this is an estimate of how complex it will be to address, ranging from 1 (extremely simple, very small changes) to 9 (major changes, possibly requiring days or even weeks of work). |
|||
|
|||
Once you've selected an issue to work on, please leave a comment saying so. This will allow other people to see that they shouldn't also start on that issue. |
|||
|
|||
### Before submitting a merge request |
|||
|
|||
After you've finished making your changes, there are a few things to check before proposing your changes as a merge request. |
|||
|
|||
First, ensure that all the checks (tests, mypy and code-style) pass successfully. Merge requests that fail any of the checks will not be accepted. For more information, see this section of the development docs: https://docs.tildes.net/development#running-checks-on-your-code |
|||
|
|||
Squash your changes into logical commits. For many changes there should only be a single commit, but some can be broken into multiple logical sections. The commit messages should follow [the formatting described in this article](https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html), with the summary line written in the imperative form. The summary line should make sense if you were to use it in a sentence like "If applied, this commit will \_\_\_\_\_\_\_\_". For example, "Add a new X", "Fix a bug with Y", and so on. |
|||
|
|||
### Merge request and code review |
|||
|
|||
Once your code is ready, you can [submit a new merge request on GitLab](https://gitlab.com/tildes/tildes/merge_requests/new). |
|||
|
|||
After creating the merge request, if you need to make any further changes to your code (whether in response to code review or not), please add the changes as new commits. Do not modify the existing commits, this makes it far simpler for other people to follow what changes you're making. Once the merge request is approved, a final pass can be done to squash the commits down, make updates to commit messages, etc. before it's actually merged. |
@ -0,0 +1,660 @@ |
|||
### GNU AFFERO GENERAL PUBLIC LICENSE |
|||
|
|||
Version 3, 19 November 2007 |
|||
|
|||
Copyright (C) 2007 Free Software Foundation, Inc. |
|||
<https://fsf.org/> |
|||
|
|||
Everyone is permitted to copy and distribute verbatim copies of this |
|||
license document, but changing it is not allowed. |
|||
|
|||
### Preamble |
|||
|
|||
The GNU Affero General Public License is a free, copyleft license for |
|||
software and other kinds of works, specifically designed to ensure |
|||
cooperation with the community in the case of network server software. |
|||
|
|||
The licenses for most software and other practical works are designed |
|||
to take away your freedom to share and change the works. By contrast, |
|||
our General Public Licenses are intended to guarantee your freedom to |
|||
share and change all versions of a program--to make sure it remains |
|||
free software for all its users. |
|||
|
|||
When we speak of free software, we are referring to freedom, not |
|||
price. Our General Public Licenses are designed to make sure that you |
|||
have the freedom to distribute copies of free software (and charge for |
|||
them if you wish), that you receive source code or can get it if you |
|||
want it, that you can change the software or use pieces of it in new |
|||
free programs, and that you know you can do these things. |
|||
|
|||
Developers that use our General Public Licenses protect your rights |
|||
with two steps: (1) assert copyright on the software, and (2) offer |
|||
you this License which gives you legal permission to copy, distribute |
|||
and/or modify the software. |
|||
|
|||
A secondary benefit of defending all users' freedom is that |
|||
improvements made in alternate versions of the program, if they |
|||
receive widespread use, become available for other developers to |
|||
incorporate. Many developers of free software are heartened and |
|||
encouraged by the resulting cooperation. However, in the case of |
|||
software used on network servers, this result may fail to come about. |
|||
The GNU General Public License permits making a modified version and |
|||
letting the public access it on a server without ever releasing its |
|||
source code to the public. |
|||
|
|||
The GNU Affero General Public License is designed specifically to |
|||
ensure that, in such cases, the modified source code becomes available |
|||
to the community. It requires the operator of a network server to |
|||
provide the source code of the modified version running there to the |
|||
users of that server. Therefore, public use of a modified version, on |
|||
a publicly accessible server, gives the public access to the source |
|||
code of the modified version. |
|||
|
|||
An older license, called the Affero General Public License and |
|||
published by Affero, was designed to accomplish similar goals. This is |
|||
a different license, not a version of the Affero GPL, but Affero has |
|||
released a new version of the Affero GPL which permits relicensing |
|||
under this license. |
|||
|
|||
The precise terms and conditions for copying, distribution and |
|||
modification follow. |
|||
|
|||
### TERMS AND CONDITIONS |
|||
|
|||
#### 0. Definitions. |
|||
|
|||
"This License" refers to version 3 of the GNU Affero General Public |
|||
License. |
|||
|
|||
"Copyright" also means copyright-like laws that apply to other kinds |
|||
of works, such as semiconductor masks. |
|||
|
|||
"The Program" refers to any copyrightable work licensed under this |
|||
License. Each licensee is addressed as "you". "Licensees" and |
|||
"recipients" may be individuals or organizations. |
|||
|
|||
To "modify" a work means to copy from or adapt all or part of the work |
|||
in a fashion requiring copyright permission, other than the making of |
|||
an exact copy. The resulting work is called a "modified version" of |
|||
the earlier work or a work "based on" the earlier work. |
|||
|
|||
A "covered work" means either the unmodified Program or a work based |
|||
on the Program. |
|||
|
|||
To "propagate" a work means to do anything with it that, without |
|||
permission, would make you directly or secondarily liable for |
|||
infringement under applicable copyright law, except executing it on a |
|||
computer or modifying a private copy. Propagation includes copying, |
|||
distribution (with or without modification), making available to the |
|||
public, and in some countries other activities as well. |
|||
|
|||
To "convey" a work means any kind of propagation that enables other |
|||
parties to make or receive copies. Mere interaction with a user |
|||
through a computer network, with no transfer of a copy, is not |
|||
conveying. |
|||
|
|||
An interactive user interface displays "Appropriate Legal Notices" to |
|||
the extent that it includes a convenient and prominently visible |
|||
feature that (1) displays an appropriate copyright notice, and (2) |
|||
tells the user that there is no warranty for the work (except to the |
|||
extent that warranties are provided), that licensees may convey the |
|||
work under this License, and how to view a copy of this License. If |
|||
the interface presents a list of user commands or options, such as a |
|||
menu, a prominent item in the list meets this criterion. |
|||
|
|||
#### 1. Source Code. |
|||
|
|||
The "source code" for a work means the preferred form of the work for |
|||
making modifications to it. "Object code" means any non-source form of |
|||
a work. |
|||
|
|||
A "Standard Interface" means an interface that either is an official |
|||
standard defined by a recognized standards body, or, in the case of |
|||
interfaces specified for a particular programming language, one that |
|||
is widely used among developers working in that language. |
|||
|
|||
The "System Libraries" of an executable work include anything, other |
|||
than the work as a whole, that (a) is included in the normal form of |
|||
packaging a Major Component, but which is not part of that Major |
|||
Component, and (b) serves only to enable use of the work with that |
|||
Major Component, or to implement a Standard Interface for which an |
|||
implementation is available to the public in source code form. A |
|||
"Major Component", in this context, means a major essential component |
|||
(kernel, window system, and so on) of the specific operating system |
|||
(if any) on which the executable work runs, or a compiler used to |
|||
produce the work, or an object code interpreter used to run it. |
|||
|
|||
The "Corresponding Source" for a work in object code form means all |
|||
the source code needed to generate, install, and (for an executable |
|||
work) run the object code and to modify the work, including scripts to |
|||
control those activities. However, it does not include the work's |
|||
System Libraries, or general-purpose tools or generally available free |
|||
programs which are used unmodified in performing those activities but |
|||
which are not part of the work. For example, Corresponding Source |
|||
includes interface definition files associated with source files for |
|||
the work, and the source code for shared libraries and dynamically |
|||
linked subprograms that the work is specifically designed to require, |
|||
such as by intimate data communication or control flow between those |
|||
subprograms and other parts of the work. |
|||
|
|||
The Corresponding Source need not include anything that users can |
|||
regenerate automatically from other parts of the Corresponding Source. |
|||
|
|||
The Corresponding Source for a work in source code form is that same |
|||
work. |
|||
|
|||
#### 2. Basic Permissions. |
|||
|
|||
All rights granted under this License are granted for the term of |
|||
copyright on the Program, and are irrevocable provided the stated |
|||
conditions are met. This License explicitly affirms your unlimited |
|||
permission to run the unmodified Program. The output from running a |
|||
covered work is covered by this License only if the output, given its |
|||
content, constitutes a covered work. This License acknowledges your |
|||
rights of fair use or other equivalent, as provided by copyright law. |
|||
|
|||
You may make, run and propagate covered works that you do not convey, |
|||
without conditions so long as your license otherwise remains in force. |
|||
You may convey covered works to others for the sole purpose of having |
|||
them make modifications exclusively for you, or provide you with |
|||
facilities for running those works, provided that you comply with the |
|||
terms of this License in conveying all material for which you do not |
|||
control copyright. Those thus making or running the covered works for |
|||
you must do so exclusively on your behalf, under your direction and |
|||
control, on terms that prohibit them from making any copies of your |
|||
copyrighted material outside their relationship with you. |
|||
|
|||
Conveying under any other circumstances is permitted solely under the |
|||
conditions stated below. Sublicensing is not allowed; section 10 makes |
|||
it unnecessary. |
|||
|
|||
#### 3. Protecting Users' Legal Rights From Anti-Circumvention Law. |
|||
|
|||
No covered work shall be deemed part of an effective technological |
|||
measure under any applicable law fulfilling obligations under article |
|||
11 of the WIPO copyright treaty adopted on 20 December 1996, or |
|||
similar laws prohibiting or restricting circumvention of such |
|||
measures. |
|||
|
|||
When you convey a covered work, you waive any legal power to forbid |
|||
circumvention of technological measures to the extent such |
|||
circumvention is effected by exercising rights under this License with |
|||
respect to the covered work, and you disclaim any intention to limit |
|||
operation or modification of the work as a means of enforcing, against |
|||
the work's users, your or third parties' legal rights to forbid |
|||
circumvention of technological measures. |
|||
|
|||
#### 4. Conveying Verbatim Copies. |
|||
|
|||
You may convey verbatim copies of the Program's source code as you |
|||
receive it, in any medium, provided that you conspicuously and |
|||
appropriately publish on each copy an appropriate copyright notice; |
|||
keep intact all notices stating that this License and any |
|||
non-permissive terms added in accord with section 7 apply to the code; |
|||
keep intact all notices of the absence of any warranty; and give all |
|||
recipients a copy of this License along with the Program. |
|||
|
|||
You may charge any price or no price for each copy that you convey, |
|||
and you may offer support or warranty protection for a fee. |
|||
|
|||
#### 5. Conveying Modified Source Versions. |
|||
|
|||
You may convey a work based on the Program, or the modifications to |
|||
produce it from the Program, in the form of source code under the |
|||
terms of section 4, provided that you also meet all of these |
|||
conditions: |
|||
|
|||
- a) The work must carry prominent notices stating that you modified |
|||
it, and giving a relevant date. |
|||
- b) The work must carry prominent notices stating that it is |
|||
released under this License and any conditions added under |
|||
section 7. This requirement modifies the requirement in section 4 |
|||
to "keep intact all notices". |
|||
- c) You must license the entire work, as a whole, under this |
|||
License to anyone who comes into possession of a copy. This |
|||
License will therefore apply, along with any applicable section 7 |
|||
additional terms, to the whole of the work, and all its parts, |
|||
regardless of how they are packaged. This License gives no |
|||
permission to license the work in any other way, but it does not |
|||
invalidate such permission if you have separately received it. |
|||
- d) If the work has interactive user interfaces, each must display |
|||
Appropriate Legal Notices; however, if the Program has interactive |
|||
interfaces that do not display Appropriate Legal Notices, your |
|||
work need not make them do so. |
|||
|
|||
A compilation of a covered work with other separate and independent |
|||
works, which are not by their nature extensions of the covered work, |
|||
and which are not combined with it such as to form a larger program, |
|||
in or on a volume of a storage or distribution medium, is called an |
|||
"aggregate" if the compilation and its resulting copyright are not |
|||
used to limit the access or legal rights of the compilation's users |
|||
beyond what the individual works permit. Inclusion of a covered work |
|||
in an aggregate does not cause this License to apply to the other |
|||
parts of the aggregate. |
|||
|
|||
#### 6. Conveying Non-Source Forms. |
|||
|
|||
You may convey a covered work in object code form under the terms of |
|||
sections 4 and 5, provided that you also convey the machine-readable |
|||
Corresponding Source under the terms of this License, in one of these |
|||
ways: |
|||
|
|||
- a) Convey the object code in, or embodied in, a physical product |
|||
(including a physical distribution medium), accompanied by the |
|||
Corresponding Source fixed on a durable physical medium |
|||
customarily used for software interchange. |
|||
- b) Convey the object code in, or embodied in, a physical product |
|||
(including a physical distribution medium), accompanied by a |
|||
written offer, valid for at least three years and valid for as |
|||
long as you offer spare parts or customer support for that product |
|||
model, to give anyone who possesses the object code either (1) a |
|||
copy of the Corresponding Source for all the software in the |
|||
product that is covered by this License, on a durable physical |
|||
medium customarily used for software interchange, for a price no |
|||
more than your reasonable cost of physically performing this |
|||
conveying of source, or (2) access to copy the Corresponding |
|||
Source from a network server at no charge. |
|||
- c) Convey individual copies of the object code with a copy of the |
|||
written offer to provide the Corresponding Source. This |
|||
alternative is allowed only occasionally and noncommercially, and |
|||
only if you received the object code with such an offer, in accord |
|||
with subsection 6b. |
|||
- d) Convey the object code by offering access from a designated |
|||
place (gratis or for a charge), and offer equivalent access to the |
|||
Corresponding Source in the same way through the same place at no |
|||
further charge. You need not require recipients to copy the |
|||
Corresponding Source along with the object code. If the place to |
|||
copy the object code is a network server, the Corresponding Source |
|||
may be on a different server (operated by you or a third party) |
|||
that supports equivalent copying facilities, provided you maintain |
|||
clear directions next to the object code saying where to find the |
|||
Corresponding Source. Regardless of what server hosts the |
|||
Corresponding Source, you remain obligated to ensure that it is |
|||
available for as long as needed to satisfy these requirements. |
|||
- e) Convey the object code using peer-to-peer transmission, |
|||
provided you inform other peers where the object code and |
|||
Corresponding Source of the work are being offered to the general |
|||
public at no charge under subsection 6d. |
|||
|
|||
A separable portion of the object code, whose source code is excluded |
|||
from the Corresponding Source as a System Library, need not be |
|||
included in conveying the object code work. |
|||
|
|||
A "User Product" is either (1) a "consumer product", which means any |
|||
tangible personal property which is normally used for personal, |
|||
family, or household purposes, or (2) anything designed or sold for |
|||
incorporation into a dwelling. In determining whether a product is a |
|||
consumer product, doubtful cases shall be resolved in favor of |
|||
coverage. For a particular product received by a particular user, |
|||
"normally used" refers to a typical or common use of that class of |
|||
product, regardless of the status of the particular user or of the way |
|||
in which the particular user actually uses, or expects or is expected |
|||
to use, the product. A product is a consumer product regardless of |
|||
whether the product has substantial commercial, industrial or |
|||
non-consumer uses, unless such uses represent the only significant |
|||
mode of use of the product. |
|||
|
|||
"Installation Information" for a User Product means any methods, |
|||
procedures, authorization keys, or other information required to |
|||
install and execute modified versions of a covered work in that User |
|||
Product from a modified version of its Corresponding Source. The |
|||
information must suffice to ensure that the continued functioning of |
|||
the modified object code is in no case prevented or interfered with |
|||
solely because modification has been made. |
|||
|
|||
If you convey an object code work under this section in, or with, or |
|||
specifically for use in, a User Product, and the conveying occurs as |
|||
part of a transaction in which the right of possession and use of the |
|||
User Product is transferred to the recipient in perpetuity or for a |
|||
fixed term (regardless of how the transaction is characterized), the |
|||
Corresponding Source conveyed under this section must be accompanied |
|||
by the Installation Information. But this requirement does not apply |
|||
if neither you nor any third party retains the ability to install |
|||
modified object code on the User Product (for example, the work has |
|||
been installed in ROM). |
|||
|
|||
The requirement to provide Installation Information does not include a |
|||
requirement to continue to provide support service, warranty, or |
|||
updates for a work that has been modified or installed by the |
|||
recipient, or for the User Product in which it has been modified or |
|||
installed. Access to a network may be denied when the modification |
|||
itself materially and adversely affects the operation of the network |
|||
or violates the rules and protocols for communication across the |
|||
network. |
|||
|
|||
Corresponding Source conveyed, and Installation Information provided, |
|||
in accord with this section must be in a format that is publicly |
|||
documented (and with an implementation available to the public in |
|||
source code form), and must require no special password or key for |
|||
unpacking, reading or copying. |
|||
|
|||
#### 7. Additional Terms. |
|||
|
|||
"Additional permissions" are terms that supplement the terms of this |
|||
License by making exceptions from one or more of its conditions. |
|||
Additional permissions that are applicable to the entire Program shall |
|||
be treated as though they were included in this License, to the extent |
|||
that they are valid under applicable law. If additional permissions |
|||
apply only to part of the Program, that part may be used separately |
|||
under those permissions, but the entire Program remains governed by |
|||
this License without regard to the additional permissions. |
|||
|
|||
When you convey a copy of a covered work, you may at your option |
|||
remove any additional permissions from that copy, or from any part of |
|||
it. (Additional permissions may be written to require their own |
|||
removal in certain cases when you modify the work.) You may place |
|||
additional permissions on material, added by you to a covered work, |
|||
for which you have or can give appropriate copyright permission. |
|||
|
|||
Notwithstanding any other provision of this License, for material you |
|||
add to a covered work, you may (if authorized by the copyright holders |
|||
of that material) supplement the terms of this License with terms: |
|||
|
|||
- a) Disclaiming warranty or limiting liability differently from the |
|||
terms of sections 15 and 16 of this License; or |
|||
- b) Requiring preservation of specified reasonable legal notices or |
|||
author attributions in that material or in the Appropriate Legal |
|||
Notices displayed by works containing it; or |
|||
- c) Prohibiting misrepresentation of the origin of that material, |
|||
or requiring that modified versions of such material be marked in |
|||
reasonable ways as different from the original version; or |
|||
- d) Limiting the use for publicity purposes of names of licensors |
|||
or authors of the material; or |
|||
- e) Declining to grant rights under trademark law for use of some |
|||
trade names, trademarks, or service marks; or |
|||
- f) Requiring indemnification of licensors and authors of that |
|||
material by anyone who conveys the material (or modified versions |
|||
of it) with contractual assumptions of liability to the recipient, |
|||
for any liability that these contractual assumptions directly |
|||
impose on those licensors and authors. |
|||
|
|||
All other non-permissive additional terms are considered "further |
|||
restrictions" within the meaning of section 10. If the Program as you |
|||
received it, or any part of it, contains a notice stating that it is |
|||
governed by this License along with a term that is a further |
|||
restriction, you may remove that term. If a license document contains |
|||
a further restriction but permits relicensing or conveying under this |
|||
License, you may add to a covered work material governed by the terms |
|||
of that license document, provided that the further restriction does |
|||
not survive such relicensing or conveying. |
|||
|
|||
If you add terms to a covered work in accord with this section, you |
|||
must place, in the relevant source files, a statement of the |
|||
additional terms that apply to those files, or a notice indicating |
|||
where to find the applicable terms. |
|||
|
|||
Additional terms, permissive or non-permissive, may be stated in the |
|||
form of a separately written license, or stated as exceptions; the |
|||
above requirements apply either way. |
|||
|
|||
#### 8. Termination. |
|||
|
|||
You may not propagate or modify a covered work except as expressly |
|||
provided under this License. Any attempt otherwise to propagate or |
|||
modify it is void, and will automatically terminate your rights under |
|||
this License (including any patent licenses granted under the third |
|||
paragraph of section 11). |
|||
|
|||
However, if you cease all violation of this License, then your license |
|||
from a particular copyright holder is reinstated (a) provisionally, |
|||
unless and until the copyright holder explicitly and finally |
|||
terminates your license, and (b) permanently, if the copyright holder |
|||
fails to notify you of the violation by some reasonable means prior to |
|||
60 days after the cessation. |
|||
|
|||
Moreover, your license from a particular copyright holder is |
|||
reinstated permanently if the copyright holder notifies you of the |
|||
violation by some reasonable means, this is the first time you have |
|||
received notice of violation of this License (for any work) from that |
|||
copyright holder, and you cure the violation prior to 30 days after |
|||
your receipt of the notice. |
|||
|
|||
Termination of your rights under this section does not terminate the |
|||
licenses of parties who have received copies or rights from you under |
|||
this License. If your rights have been terminated and not permanently |
|||
reinstated, you do not qualify to receive new licenses for the same |
|||
material under section 10. |
|||
|
|||
#### 9. Acceptance Not Required for Having Copies. |
|||
|
|||
You are not required to accept this License in order to receive or run |
|||
a copy of the Program. Ancillary propagation of a covered work |
|||
occurring solely as a consequence of using peer-to-peer transmission |
|||
to receive a copy likewise does not require acceptance. However, |
|||
nothing other than this License grants you permission to propagate or |
|||
modify any covered work. These actions infringe copyright if you do |
|||
not accept this License. Therefore, by modifying or propagating a |
|||
covered work, you indicate your acceptance of this License to do so. |
|||
|
|||
#### 10. Automatic Licensing of Downstream Recipients. |
|||
|
|||
Each time you convey a covered work, the recipient automatically |
|||
receives a license from the original licensors, to run, modify and |
|||
propagate that work, subject to this License. You are not responsible |
|||
for enforcing compliance by third parties with this License. |
|||
|
|||
An "entity transaction" is a transaction transferring control of an |
|||
organization, or substantially all assets of one, or subdividing an |
|||
organization, or merging organizations. If propagation of a covered |
|||
work results from an entity transaction, each party to that |
|||
transaction who receives a copy of the work also receives whatever |
|||
licenses to the work the party's predecessor in interest had or could |
|||
give under the previous paragraph, plus a right to possession of the |
|||
Corresponding Source of the work from the predecessor in interest, if |
|||
the predecessor has it or can get it with reasonable efforts. |
|||
|
|||
You may not impose any further restrictions on the exercise of the |
|||
rights granted or affirmed under this License. For example, you may |
|||
not impose a license fee, royalty, or other charge for exercise of |
|||
rights granted under this License, and you may not initiate litigation |
|||
(including a cross-claim or counterclaim in a lawsuit) alleging that |
|||
any patent claim is infringed by making, using, selling, offering for |
|||
sale, or importing the Program or any portion of it. |
|||
|
|||
#### 11. Patents. |
|||
|
|||
A "contributor" is a copyright holder who authorizes use under this |
|||
License of the Program or a work on which the Program is based. The |
|||
work thus licensed is called the contributor's "contributor version". |
|||
|
|||
A contributor's "essential patent claims" are all patent claims owned |
|||
or controlled by the contributor, whether already acquired or |
|||
hereafter acquired, that would be infringed by some manner, permitted |
|||
by this License, of making, using, or selling its contributor version, |
|||
but do not include claims that would be infringed only as a |
|||
consequence of further modification of the contributor version. For |
|||
purposes of this definition, "control" includes the right to grant |
|||
patent sublicenses in a manner consistent with the requirements of |
|||
this License. |
|||
|
|||
Each contributor grants you a non-exclusive, worldwide, royalty-free |
|||
patent license under the contributor's essential patent claims, to |
|||
make, use, sell, offer for sale, import and otherwise run, modify and |
|||
propagate the contents of its contributor version. |
|||
|
|||
In the following three paragraphs, a "patent license" is any express |
|||
agreement or commitment, however denominated, not to enforce a patent |
|||
(such as an express permission to practice a patent or covenant not to |
|||
sue for patent infringement). To "grant" such a patent license to a |
|||
party means to make such an agreement or commitment not to enforce a |
|||
patent against the party. |
|||
|
|||
If you convey a covered work, knowingly relying on a patent license, |
|||
and the Corresponding Source of the work is not available for anyone |
|||
to copy, free of charge and under the terms of this License, through a |
|||
publicly available network server or other readily accessible means, |
|||
then you must either (1) cause the Corresponding Source to be so |
|||
available, or (2) arrange to deprive yourself of the benefit of the |
|||
patent license for this particular work, or (3) arrange, in a manner |
|||
consistent with the requirements of this License, to extend the patent |
|||
license to downstream recipients. "Knowingly relying" means you have |
|||
actual knowledge that, but for the patent license, your conveying the |
|||
covered work in a country, or your recipient's use of the covered work |
|||
in a country, would infringe one or more identifiable patents in that |
|||
country that you have reason to believe are valid. |
|||
|
|||
If, pursuant to or in connection with a single transaction or |
|||
arrangement, you convey, or propagate by procuring conveyance of, a |
|||
covered work, and grant a patent license to some of the parties |
|||
receiving the covered work authorizing them to use, propagate, modify |
|||
or convey a specific copy of the covered work, then the patent license |
|||
you grant is automatically extended to all recipients of the covered |
|||
work and works based on it. |
|||
|
|||
A patent license is "discriminatory" if it does not include within the |
|||
scope of its coverage, prohibits the exercise of, or is conditioned on |
|||
the non-exercise of one or more of the rights that are specifically |
|||
granted under this License. You may not convey a covered work if you |
|||
are a party to an arrangement with a third party that is in the |
|||
business of distributing software, under which you make payment to the |
|||
third party based on the extent of your activity of conveying the |
|||
work, and under which the third party grants, to any of the parties |
|||
who would receive the covered work from you, a discriminatory patent |
|||
license (a) in connection with copies of the covered work conveyed by |
|||
you (or copies made from those copies), or (b) primarily for and in |
|||
connection with specific products or compilations that contain the |
|||
covered work, unless you entered into that arrangement, or that patent |
|||
license was granted, prior to 28 March 2007. |
|||
|
|||
Nothing in this License shall be construed as excluding or limiting |
|||
any implied license or other defenses to infringement that may |
|||
otherwise be available to you under applicable patent law. |
|||
|
|||
#### 12. No Surrender of Others' Freedom. |
|||
|
|||
If conditions are imposed on you (whether by court order, agreement or |
|||
otherwise) that contradict the conditions of this License, they do not |
|||
excuse you from the conditions of this License. If you cannot convey a |
|||
covered work so as to satisfy simultaneously your obligations under |
|||
this License and any other pertinent obligations, then as a |
|||
consequence you may not convey it at all. For example, if you agree to |
|||
terms that obligate you to collect a royalty for further conveying |
|||
from those to whom you convey the Program, the only way you could |
|||
satisfy both those terms and this License would be to refrain entirely |
|||
from conveying the Program. |
|||
|
|||
#### 13. Remote Network Interaction; Use with the GNU General Public License. |
|||
|
|||
Notwithstanding any other provision of this License, if you modify the |
|||
Program, your modified version must prominently offer all users |
|||
interacting with it remotely through a computer network (if your |
|||
version supports such interaction) an opportunity to receive the |
|||
Corresponding Source of your version by providing access to the |
|||
Corresponding Source from a network server at no charge, through some |
|||
standard or customary means of facilitating copying of software. This |
|||
Corresponding Source shall include the Corresponding Source for any |
|||
work covered by version 3 of the GNU General Public License that is |
|||
incorporated pursuant to the following paragraph. |
|||
|
|||
Notwithstanding any other provision of this License, you have |
|||
permission to link or combine any covered work with a work licensed |
|||
under version 3 of the GNU General Public License into a single |
|||
combined work, and to convey the resulting work. The terms of this |
|||
License will continue to apply to the part which is the covered work, |
|||
but the work with which it is combined will remain governed by version |
|||
3 of the GNU General Public License. |
|||
|
|||
#### 14. Revised Versions of this License. |
|||
|
|||
The Free Software Foundation may publish revised and/or new versions |
|||
of the GNU Affero General Public License from time to time. Such new |
|||
versions will be similar in spirit to the present version, but may |
|||
differ in detail to address new problems or concerns. |
|||
|
|||
Each version is given a distinguishing version number. If the Program |
|||
specifies that a certain numbered version of the GNU Affero General |
|||
Public License "or any later version" applies to it, you have the |
|||
option of following the terms and conditions either of that numbered |
|||
version or of any later version published by the Free Software |
|||
Foundation. If the Program does not specify a version number of the |
|||
GNU Affero General Public License, you may choose any version ever |
|||
published by the Free Software Foundation. |
|||
|
|||
If the Program specifies that a proxy can decide which future versions |
|||
of the GNU Affero General Public License can be used, that proxy's |
|||
public statement of acceptance of a version permanently authorizes you |
|||
to choose that version for the Program. |
|||
|
|||
Later license versions may give you additional or different |
|||
permissions. However, no additional obligations are imposed on any |
|||
author or copyright holder as a result of your choosing to follow a |
|||
later version. |
|||
|
|||
#### 15. Disclaimer of Warranty. |
|||
|
|||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY |
|||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT |
|||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT |
|||
WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT |
|||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|||
A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND |
|||
PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE |
|||
DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR |
|||
CORRECTION. |
|||
|
|||
#### 16. Limitation of Liability. |
|||
|
|||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING |
|||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR |
|||
CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, |
|||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES |
|||
ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT |
|||
NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR |
|||
LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM |
|||
TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER |
|||
PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. |
|||
|
|||
#### 17. Interpretation of Sections 15 and 16. |
|||
|
|||
If the disclaimer of warranty and limitation of liability provided |
|||
above cannot be given local legal effect according to their terms, |
|||
reviewing courts shall apply local law that most closely approximates |
|||
an absolute waiver of all civil liability in connection with the |
|||
Program, unless a warranty or assumption of liability accompanies a |
|||
copy of the Program in return for a fee. |
|||
|
|||
END OF TERMS AND CONDITIONS |
|||
|
|||
### How to Apply These Terms to Your New Programs |
|||
|
|||
If you develop a new program, and you want it to be of the greatest |
|||
possible use to the public, the best way to achieve this is to make it |
|||
free software which everyone can redistribute and change under these |
|||
terms. |
|||
|
|||
To do so, attach the following notices to the program. It is safest to |
|||
attach them to the start of each source file to most effectively state |
|||
the exclusion of warranty; and each file should have at least the |
|||
"copyright" line and a pointer to where the full notice is found. |
|||
|
|||
<one line to give the program's name and a brief idea of what it does.> |
|||
Copyright (C) <year> <name of author> |
|||
|
|||
This program is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU Affero General Public License as |
|||
published by the Free Software Foundation, either version 3 of the |
|||
License, or (at your option) any later version. |
|||
|
|||
This program is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU Affero General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU Affero General Public License |
|||
along with this program. If not, see <https://www.gnu.org/licenses/>. |
|||
|
|||
Also add information on how to contact you by electronic and paper |
|||
mail. |
|||
|
|||
If your software can interact with users remotely through a computer |
|||
network, you should also make sure that it provides a way for users to |
|||
get its source. For example, if your program is a web application, its |
|||
interface could display a "Source" link that leads users to an archive |
|||
of the code. There are many ways you could offer source, and different |
|||
solutions will be better for different programs; see section 13 for |
|||
the specific requirements. |
|||
|
|||
You should also get your employer (if you work as a programmer) or |
|||
school, if any, to sign a "copyright disclaimer" for the program, if |
|||
necessary. For more information on this, and how to apply and follow |
|||
the GNU AGPL, see <https://www.gnu.org/licenses/>. |
@ -0,0 +1,15 @@ |
|||
# Tildes |
|||
|
|||
This is the code behind [Tildes](https://tildes.net), a non-profit community site. The official repository is located on GitLab at https://gitlab.com/tildes/tildes |
|||
|
|||
For general information about Tildes and its goals, please see [the announcement blog post](https://blog.tildes.net/announcing-tildes) and [the Tildes Docs site](https://docs.tildes.net). |
|||
|
|||
## Issue tracker / plans |
|||
|
|||
Known issues and plans for upcoming changes are tracked on GitLab: https://gitlab.com/tildes/tildes/issues |
|||
|
|||
The "board" view is useful as an overview: https://gitlab.com/tildes/tildes/boards |
|||
|
|||
## Contributing to Tildes development |
|||
|
|||
Please see [the Contributing doc](CONTRIBUTING.md) for more detailed information about setting up a development version of Tildes and how to contribute to development. |
@ -0,0 +1,27 @@ |
|||
# -*- mode: ruby -*- |
|||
# vi: set ft=ruby : |
|||
|
|||
VAGRANT_CONFIG_VERSION = "2" |
|||
|
|||
Vagrant.configure(VAGRANT_CONFIG_VERSION) do |config| |
|||
config.vm.box = "ubuntu/xenial64" |
|||
|
|||
# Main application folder |
|||
config.vm.synced_folder "tildes/", "/opt/tildes/" |
|||
|
|||
# Mount the salt file root and pillar root |
|||
config.vm.synced_folder "salt/salt/", "/srv/salt/" |
|||
config.vm.synced_folder "salt/pillar/", "/srv/pillar/" |
|||
|
|||
config.vm.network "forwarded_port", guest: 443, host: 4443 |
|||
config.vm.network "forwarded_port", guest: 9090, host: 9090 |
|||
|
|||
# Masterless salt provisioning |
|||
config.vm.provision :salt do |salt| |
|||
salt.masterless = true |
|||
salt.minion_config = "salt/minion" |
|||
salt.run_highstate = true |
|||
salt.verbose = true |
|||
salt.log_level = "info" |
|||
end |
|||
end |
@ -0,0 +1,7 @@ |
|||
#!/bin/sh |
|||
# |
|||
# Pre-commit hook script that ensures mypy checks and tests pass |
|||
|
|||
vagrant ssh -c ". activate \ |
|||
&& echo 'Checking mypy type annotations...' && mypy . \ |
|||
&& echo -n 'Running tests: ' && pytest -q" |
@ -0,0 +1,8 @@ |
|||
#!/bin/sh |
|||
# |
|||
# Pre-push hook script that ensures mypy checks, style checks, and tests pass |
|||
|
|||
vagrant ssh -c ". activate \ |
|||
&& echo 'Checking mypy type annotations...' && mypy . \ |
|||
&& echo -n 'Running tests: ' && pytest -q \ |
|||
&& echo 'Checking code style (takes a while)...' && pylama" |
@ -0,0 +1,19 @@ |
|||
# look for files on the minion, not the master |
|||
file_client: local |
|||
|
|||
# set a specific minion ID for use in top file / pillars |
|||
# options: |
|||
# - "dev" for the vagrant setup |
|||
# - "prod" for (single-server) production |
|||
# - "monitoring" for the monitoring server |
|||
id: dev |
|||
|
|||
# base path for SSL certificates |
|||
ca.cert_base_path: '/etc/pki' |
|||
|
|||
state_verbose: False |
|||
|
|||
# enable new module.run state syntax |
|||
# https://docs.saltstack.com/en/develop/topics/releases/2017.7.0.html#state-module-changes |
|||
use_superseded: |
|||
- module.run |
@ -0,0 +1,5 @@ |
|||
ini_file: development.ini |
|||
ssl_cert_path: /etc/pki/tls/certs/localhost.crt |
|||
ssl_private_key_path: /etc/pki/tls/certs/localhost.key |
|||
nginx_worker_processes: 1 |
|||
postgresql_version: 10 |
@ -0,0 +1,8 @@ |
|||
sentry_secret: 'sentry_secret_token' |
|||
sentry_email: 'sentry_superuser@email.address' |
|||
sentry_password: 'passwordforsentrysuperuser' |
|||
sentry_server_name: 'sentry.example.com' |
|||
developer_ips: ['127.0.0.1'] |
|||
prometheus_server_name: 'prom.example.com' |
|||
grafana_server_name: 'grafana.example.com' |
|||
grafana_admin_password: 'passwordforgrafanaadmin' |
@ -0,0 +1,5 @@ |
|||
ssl_cert_path: /etc/pki/tls/certs/localhost.crt |
|||
ssl_private_key_path: /etc/pki/tls/certs/localhost.key |
|||
hsts_max_age: 60 |
|||
nginx_worker_processes: auto |
|||
postgresql_version: 9.6 |
@ -0,0 +1,6 @@ |
|||
ini_file: production.ini |
|||
ssl_cert_path: /etc/letsencrypt/live/tildes.net/fullchain.pem |
|||
ssl_private_key_path: /etc/letsencrypt/live/tildes.net/privkey.pem |
|||
hsts_max_age: 63072000 |
|||
nginx_worker_processes: auto |
|||
postgresql_version: 10 |
@ -0,0 +1,8 @@ |
|||
base: |
|||
'dev': |
|||
- dev |
|||
'prod': |
|||
- prod |
|||
'monitoring': |
|||
- monitoring |
|||
- monitoring-secrets |
@ -0,0 +1,13 @@ |
|||
{% from 'common.jinja2' import app_dir, bin_dir -%} |
|||
[Unit] |
|||
Description=Boussole - auto-compile SCSS files on change |
|||
|
|||
[Service] |
|||
WorkingDirectory={{ app_dir }} |
|||
Environment="LC_ALL=C.UTF-8" "LANG=C.UTF-8" |
|||
ExecStart={{ bin_dir }}/boussole watch --backend=yaml --config=boussole.yaml --poll |
|||
Restart=always |
|||
RestartSec=5 |
|||
|
|||
[Install] |
|||
WantedBy=multi-user.target |
@ -0,0 +1,32 @@ |
|||
{% from 'common.jinja2' import app_dir, bin_dir %} |
|||
|
|||
/etc/systemd/system/boussole.service: |
|||
file.managed: |
|||
- source: salt://boussole.service.jinja2 |
|||
- template: jinja |
|||
- user: root |
|||
- group: root |
|||
- mode: 644 |
|||
- require_in: |
|||
- service: boussole.service |
|||
|
|||
boussole.service: |
|||
service.running: |
|||
- enable: True |
|||
- require: |
|||
- pip: pip-installs |
|||
|
|||
create-css-directory: |
|||
file.directory: |
|||
- name: {{ app_dir }}/static/css |
|||
|
|||
initial-boussole-run: |
|||
cmd.run: |
|||
- name: {{ bin_dir }}/boussole compile --backend=yaml --config=boussole.yaml |
|||
- cwd: {{ app_dir }} |
|||
- env: |
|||
- LC_ALL: C.UTF-8 |
|||
- LANG: C.UTF-8 |
|||
- require: |
|||
- file: create-css-directory |
|||
- unless: ls {{ app_dir }}/static/css/*.css |
@ -0,0 +1,25 @@ |
|||
unpack-cmark-gfm: |
|||
archive.extracted: |
|||
- name: /tmp/cmark-gfm |
|||
- source: |
|||
- salt://cmark-gfm.tar.gz |
|||
- https://github.com/github/cmark/archive/0.28.0.gfm.11.tar.gz |
|||
- source_hash: sha256=a95ee221c3f6d718bbb38bede95f05f05e07827f8f3c29ed6cb09ddb7d05c2cd |
|||
- if_missing: /usr/local/lib/libcmark-gfm.so |
|||
- options: --strip-components=1 |
|||
- enforce_toplevel: False |
|||
|
|||
install-cmark-build-deps: |
|||
pkg.installed: |
|||
- name: cmake |
|||
|
|||
install-cmark-gfm: |
|||
cmd.run: |
|||
- cwd: /tmp/cmark-gfm/ |
|||
- names: |
|||
- make |
|||
- make install |
|||
- onchanges: |
|||
- archive: unpack-cmark-gfm |
|||
- require: |
|||
- pkg: install-cmark-build-deps |
@ -0,0 +1,13 @@ |
|||
{% set python_version = '3.6.5' %} |
|||
|
|||
{% set app_dir = '/opt/tildes' %} |
|||
{% set static_sites_dir = '/opt/tildes-static-sites' %} |
|||
|
|||
{% set venv_dir = '/opt/venvs/tildes' %} |
|||
{% set bin_dir = venv_dir + '/bin' %} |
|||
|
|||
{% if grains['id'] == 'dev' %} |
|||
{% set app_username = 'vagrant' %} |
|||
{% else %} |
|||
{% set app_username = 'tildes' %} |
|||
{% endif %} |
@ -0,0 +1,11 @@ |
|||
/etc/systemd/system/consumer-topic_metadata_generator.service: |
|||
file.managed: |
|||
- source: salt://consumers/topic_metadata_generator.service.jinja2 |
|||
- template: jinja |
|||
- user: root |
|||
- group: root |
|||
- mode: 644 |
|||
|
|||
consumer-topic_metadata_generator.service: |
|||
service.running: |
|||
- enable: True |
@ -0,0 +1,16 @@ |
|||
{% from 'common.jinja2' import app_dir, bin_dir -%} |
|||
[Unit] |
|||
Description=Topic Metadata Generator (Queue Consumer) |
|||
Requires=rabbitmq-server.service |
|||
After=rabbitmq-server.service |
|||
PartOf=rabbitmq-server.service |
|||
|
|||
[Service] |
|||
WorkingDirectory={{ app_dir }}/consumers |
|||
Environment="INI_FILE={{ app_dir }}/{{ pillar['ini_file'] }}" |
|||
ExecStart={{ bin_dir }}/python topic_metadata_generator.py |
|||
Restart=always |
|||
RestartSec=5 |
|||
|
|||
[Install] |
|||
WantedBy=multi-user.target |
@ -0,0 +1,7 @@ |
|||
{% from 'common.jinja2' import app_dir, bin_dir %} |
|||
|
|||
data-cleanup-cronjob: |
|||
cron.present: |
|||
- name: {{ bin_dir }}/python -c "from scripts.clean_private_data import clean_all_data; clean_all_data('{{ app_dir }}/{{ pillar['ini_file'] }}')" |
|||
- hour: 4 |
|||
- minute: 10 |
@ -0,0 +1,21 @@ |
|||
{% from 'common.jinja2' import app_username, bin_dir %} |
|||
|
|||
{% set profile_dir = '/home/' + app_username + '/.ipython/profile_default' %} |
|||
|
|||
ipython-profile: |
|||
cmd.run: |
|||
- name: {{ bin_dir }}/ipython profile create |
|||
- runas: {{ app_username }} |
|||
- creates: {{ profile_dir }} |
|||
file.managed: |
|||
- name: {{ profile_dir }}/ipython_config.py |
|||
- contents: |
|||
- c.InteractiveShellApp.extensions = ['autoreload'] |
|||
- c.InteractiveShellApp.exec_lines = ['%autoreload 2'] |
|||
require: |
|||
- pip: pip-installs |
|||
|
|||
automatic-activate: |
|||
file.append: |
|||
- name: '/home/{{ app_username }}/.bashrc' |
|||
- text: 'source activate' |
@ -0,0 +1,17 @@ |
|||
{% from 'common.jinja2' import app_dir, bin_dir %} |
|||
|
|||
initialize-db: |
|||
cmd.run: |
|||
- name: {{ bin_dir }}/python -c "from scripts.initialize_db import initialize_db; initialize_db('{{ app_dir }}/{{ pillar['ini_file'] }}')" |
|||
- cwd: {{ app_dir }} |
|||
- onchanges: |
|||
- postgres_database: tildes |
|||
|
|||
{% if grains['id'] == 'dev' %} |
|||
insert-dev-data: |
|||
cmd.run: |
|||
- name: {{ bin_dir }}/python -c "from scripts.initialize_db import insert_dev_data; insert_dev_data('{{ app_dir }}/{{ pillar['ini_file'] }}')" |
|||
- cwd: {{ app_dir }} |
|||
- onchanges: |
|||
- cmd: initialize-db |
|||
{% endif %} |
@ -0,0 +1,19 @@ |
|||
server { |
|||
listen 443 ssl http2; |
|||
listen [::]:443 ssl http2; |
|||
|
|||
{% for ip in pillar['developer_ips'] %} |
|||
allow {{ ip }}; |
|||
{% endfor %} |
|||
deny all; |
|||
|
|||
add_header Strict-Transport-Security "max-age={{ pillar['hsts_max_age'] }}; includeSubDomains; preload" always; |
|||
|
|||
server_name {{ pillar['grafana_server_name'] }}; |
|||
|
|||
location / { |
|||
proxy_set_header Host $host; |
|||
proxy_redirect off; |
|||
proxy_pass http://localhost:3000; |
|||
} |
|||
} |
@ -0,0 +1,17 @@ |
|||
[server] |
|||
domain = {{ pillar['grafana_server_name'] }} |
|||
root_url = https://{{ pillar['grafana_server_name'] }} |
|||
|
|||
[analytics] |
|||
reporting_enabled = false |
|||
|
|||
[security] |
|||
admin_password = """{{ pillar['grafana_admin_password'] }}""" |
|||
disable_gravatar = true |
|||
|
|||
[snapshots] |
|||
external_enabled = false |
|||
|
|||
[users] |
|||
allow_sign_up = false |
|||
allow_org_create = false |
@ -0,0 +1,61 @@ |
|||
grafana: |
|||
pkgrepo.managed: |
|||
- name: deb https://packagecloud.io/grafana/stable/debian/ jessie main |
|||
- dist: jessie |
|||
- file: /etc/apt/sources.list.d/grafana.list |
|||
- key_url: https://packagecloud.io/gpg.key |
|||
- require_in: |
|||
- pkg: grafana |
|||
pkg.installed: |
|||
- name: grafana |
|||
- refresh: True |
|||
# note: this file must be set up before the server is started for the first |
|||
# time, otherwise the admin password will not be set correctly |
|||
file.managed: |
|||
- name: /etc/grafana/grafana.ini |
|||
- source: salt://grafana/grafana.ini.jinja2 |
|||
- template: jinja |
|||
- user: root |
|||
- group: grafana |
|||
- mode: 640 |
|||
service.running: |
|||
- name: grafana-server |
|||
- enable: True |
|||
- require: |
|||
- pkg: grafana |
|||
- file: /etc/grafana/grafana.ini |
|||
- watch: |
|||
- file: /etc/grafana/grafana.ini |
|||
http.query: |
|||
- name: http://localhost:3000/api/datasources |
|||
- method: POST |
|||
- username: admin |
|||
- password: {{ pillar['grafana_admin_password'] }} |
|||
- data: | |
|||
{"name": "Prometheus", |
|||
"type": "prometheus", |
|||
"url": "http://localhost:9090", |
|||
"access": "proxy", |
|||
"isDefault": true} |
|||
- header_list: |
|||
- 'Content-Type: application/json' |
|||
- status: 200 |
|||
- unless: |
|||
- curl -f http://admin:{{ pillar['grafana_admin_password'] }}@localhost:3000/api/datasources/name/Prometheus |
|||
|
|||
/etc/nginx/sites-available/grafana.conf: |
|||
file.managed: |
|||
- source: salt://grafana/grafana.conf.jinja2 |
|||
- template: jinja |
|||
- user: root |
|||
- group: root |
|||
- mode: 644 |
|||
- makedirs: True |
|||
|
|||
/etc/nginx/sites-enabled/grafana.conf: |
|||
file.symlink: |
|||
- target: /etc/nginx/sites-available/grafana.conf |
|||
- makedirs: True |
|||
- user: root |
|||
- group: root |
|||
- mode: 644 |
@ -0,0 +1 @@ |
|||
d /run/gunicorn 0755 gunicorn gunicorn - |
@ -0,0 +1,22 @@ |
|||
{% from 'common.jinja2' import app_dir, bin_dir -%} |
|||
[Unit] |
|||
Description=gunicorn daemon |
|||
Requires=gunicorn.socket |
|||
After=network.target |
|||
|
|||
[Service] |
|||
PIDFile=/run/gunicorn/pid |
|||
User=gunicorn |
|||
Group=gunicorn |
|||
RuntimeDirectory=gunicorn |
|||
WorkingDirectory={{ app_dir }} |
|||
ExecStart={{ bin_dir }}/gunicorn --paste {{ pillar['ini_file'] }} --config {{ app_dir }}/gunicorn_config.py |
|||
ExecReload=/bin/kill -s HUP $MAINPID |
|||
ExecStop=/bin/kill -s TERM $MAINPID |
|||
PrivateTmp=true |
|||
Environment=prometheus_multiproc_dir=/tmp |
|||
Restart=always |
|||
RestartSec=30 |
|||
|
|||
[Install] |
|||
WantedBy=multi-user.target |
@ -0,0 +1,11 @@ |
|||
[Unit] |
|||
Description=gunicorn socket |
|||
PartOf=gunicorn.service |
|||
|
|||
[Socket] |
|||
ListenStream=/run/gunicorn/socket |
|||
SocketUser=gunicorn |
|||
SocketGroup=gunicorn |
|||
|
|||
[Install] |
|||
WantedBy=sockets.target |
@ -0,0 +1,41 @@ |
|||
gunicorn: |
|||
group.present: |
|||
- name: gunicorn |
|||
user.present: |
|||
- name: gunicorn |
|||
- groups: [gunicorn] |
|||
- createhome: False |
|||
|
|||
/etc/systemd/system/gunicorn.service: |
|||
file.managed: |
|||
- source: salt://gunicorn/gunicorn.service.jinja2 |
|||
- template: jinja |
|||
- user: root |
|||
- group: root |
|||
- mode: 644 |
|||
- require_in: |
|||
- service: gunicorn.socket |
|||
|
|||
/etc/systemd/system/gunicorn.socket: |
|||
file.managed: |
|||
- source: salt://gunicorn/gunicorn.socket |
|||
- user: root |
|||
- group: root |
|||
- mode: 644 |
|||
- require_in: |
|||
- service: gunicorn.socket |
|||
|
|||
/usr/lib/tmpfiles.d/gunicorn.conf: |
|||
file.managed: |
|||
- source: salt://gunicorn/gunicorn.conf |
|||
- user: root |
|||
- group: root |
|||
- mode: 644 |
|||
- require_in: |
|||
- service: gunicorn.socket |
|||
|
|||
gunicorn.socket: |
|||
service.running: |
|||
- enable: True |
|||
- require: |
|||
- user: gunicorn |
@ -0,0 +1,25 @@ |
|||
nginx: |
|||
pkgrepo.managed: |
|||
- name: deb http://nginx.org/packages/ubuntu/ xenial nginx |
|||
- dist: xenial |
|||
- file: /etc/apt/sources.list.d/nginx.list |
|||
- key_url: https://nginx.org/keys/nginx_signing.key |
|||
- require_in: |
|||
- pkg: nginx |
|||
pkg.installed: |
|||
- name: nginx |
|||
- refresh: True |
|||
service.running: |
|||
- require: |
|||
- pkg: nginx |
|||
- reload: True |
|||
- watch: |
|||
- file: /etc/nginx/* |
|||
|
|||
/etc/nginx/nginx.conf: |
|||
file.managed: |
|||
- source: salt://nginx/nginx.conf.jinja2 |
|||
- template: jinja |
|||
- user: root |
|||
- group: root |
|||
- mode: 644 |
@ -0,0 +1,89 @@ |
|||
user nginx; |
|||
worker_processes {{ pillar['nginx_worker_processes'] }}; |
|||
|
|||
error_log /var/log/nginx/error.log warn; |
|||
pid /var/run/nginx.pid; |
|||
|
|||
|
|||
events { |
|||
worker_connections 1024; |
|||
} |
|||
|
|||
|
|||
http { |
|||
include /etc/nginx/mime.types; |
|||
default_type application/octet-stream; |
|||
|
|||
server_tokens off; |
|||
|
|||
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' |
|||
'$status $body_bytes_sent "$http_referer" ' |
|||
'"$http_user_agent" "$http_x_forwarded_for"'; |
|||
|
|||
access_log /var/log/nginx/access.log main; |
|||
|
|||
{% if grains['id'] == 'dev' %} |
|||
# have to disable sendfile for vagrant due to a virtualbox bug |
|||
sendfile off; |
|||
{% else %} |
|||
sendfile on; |
|||
{% endif %} |
|||
|
|||
keepalive_timeout 65; |
|||
|
|||
# redirect non-https accesses to the https version |
|||
server { |
|||
listen 80 default_server; |
|||
listen [::]:80 default_server; |
|||
server_name _; |
|||
|
|||
return 301 https://$host$request_uri; |
|||
} |
|||
|
|||
gzip on; |
|||
gzip_min_length 1000; |
|||
gzip_comp_level 6; |
|||
gzip_vary on; |
|||
gzip_proxied any; |
|||
|
|||
# type list from https://github.com/h5bp/server-configs-nginx |
|||
gzip_types |
|||
application/atom+xml |
|||
application/javascript |
|||
application/json |
|||
application/ld+json |
|||
application/manifest+json |
|||
application/rss+xml |
|||
application/vnd.geo+json |
|||
application/vnd.ms-fontobject |
|||
application/x-font-ttf |
|||
application/x-web-app-manifest+json |
|||
application/xhtml+xml |
|||
application/xml |
|||
font/opentype |
|||
image/bmp |
|||
image/svg+xml |
|||
image/x-icon |
|||
text/cache-manifest |
|||
text/css |
|||
text/plain |
|||
text/vcard |
|||
text/vnd.rim.location.xloc |
|||
text/vtt |
|||
text/x-component |
|||
text/x-cross-domain-policy; |
|||
|
|||
ssl_certificate {{ pillar['ssl_cert_path'] }}; |
|||
ssl_certificate_key {{ pillar['ssl_private_key_path'] }}; |
|||
ssl_session_timeout 1d; |
|||
ssl_session_cache shared:SSL:50m; |
|||
ssl_session_tickets off; |
|||
|
|||
# "modern" configuration from Mozilla guidelines |
|||
ssl_protocols TLSv1.2; |
|||
ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256'; |
|||
ssl_prefer_server_ciphers on; |
|||
|
|||
include /etc/nginx/sites-enabled/*.conf; |
|||
} |
|||
|
@ -0,0 +1,16 @@ |
|||
/etc/nginx/sites-available/tildes.conf: |
|||
file.managed: |
|||
- source: salt://nginx/tildes.conf.jinja2 |
|||
- template: jinja |
|||
- user: root |
|||
- group: root |
|||
- mode: 644 |
|||
- makedirs: True |
|||
|
|||
/etc/nginx/sites-enabled/tildes.conf: |
|||
file.symlink: |
|||
- target: /etc/nginx/sites-available/tildes.conf |
|||
- makedirs: True |
|||
- user: root |
|||
- group: root |
|||
- mode: 644 |
@ -0,0 +1,16 @@ |
|||
/etc/nginx/sites-available/tildes-static-sites.conf: |
|||
file.managed: |
|||
- source: salt://nginx/tildes-static-sites.conf.jinja2 |
|||
- template: jinja |
|||
- user: root |
|||
- group: root |
|||
- mode: 644 |
|||
- makedirs: True |
|||
|
|||
/etc/nginx/sites-enabled/tildes-static-sites.conf: |
|||
file.symlink: |
|||
- target: /etc/nginx/sites-available/tildes-static-sites.conf |
|||
- makedirs: True |
|||
- user: root |
|||
- group: root |
|||
- mode: 644 |
@ -0,0 +1,35 @@ |
|||
{% from 'common.jinja2' import static_sites_dir -%} |
|||
|
|||
{% for subdomain in ('blog', 'docs') %} |
|||
server { |
|||
listen 443 ssl http2; |
|||
listen [::]:443 ssl http2; |
|||
|
|||
add_header Strict-Transport-Security "max-age={{ pillar['hsts_max_age'] }}; includeSubDomains; preload" always; |
|||
|
|||
add_header X-Content-Type-Options "nosniff" always; |
|||
add_header X-Frame-Options "SAMEORIGIN" always; |
|||
add_header X-Xss-Protection "1; mode=block" always; |
|||
add_header Referrer-Policy "same-origin" always; |
|||
|
|||
server_name {{ subdomain }}.tildes.net; |
|||
|
|||
keepalive_timeout 5; |
|||
gzip_static on; |
|||
|
|||
location /favicon.ico { |
|||
root /opt/tildes-static-sites/theme/images; |
|||
try_files $uri =404; |
|||
} |
|||
|
|||
location /theme { |
|||
root {{ static_sites_dir }}; |
|||
try_files $uri =404; |
|||
} |
|||
|
|||
location / { |
|||
root {{ static_sites_dir }}/{{ subdomain }}; |
|||
try_files $uri $uri.html $uri/index.html =404; |
|||
} |
|||
} |
|||
{% endfor %} |
@ -0,0 +1,97 @@ |
|||
{% from 'common.jinja2' import app_dir -%} |
|||
upstream app_server { |
|||
server unix:/run/gunicorn/socket fail_timeout=0; |
|||
} |
|||
|
|||
# define map to set Expires+Cache-Control headers for files based on type |
|||
map $sent_http_content_type $expires_type_map { |
|||
default off; |
|||
text/css max; |
|||
application/javascript max; |
|||
image/x-icon 1d; |
|||
~image/ max; |
|||
} |
|||
|
|||
# redirect www. to base domain |
|||
server { |
|||
listen 80; |
|||
listen 443 ssl http2; |
|||
listen [::]:443 ssl http2; |
|||
|
|||
server_name www.tildes.net; |
|||
return 301 https://tildes.net$request_uri; |
|||
} |
|||
|
|||
server { |
|||
# remove trailing slash from addresses, the $port thing is a hack for |
|||
# development in Vagrant, so the port forwarding from the host is kept |
|||
set $port ''; |
|||
if ($http_host ~ :(\d+)$) { |
|||
set $port :$1; |
|||
} |
|||
rewrite ^/(.*)/$ https://$host$port/$1 permanent; |
|||
|
|||
# redirect /u/username to /user/username |
|||
rewrite ^/u/(.*)$ https://$host$port/user/$1; |
|||
|
|||
listen 443 ssl http2; |
|||
listen [::]:443 ssl http2; |
|||
|
|||
{% if grains['id'] != 'dev' %} |
|||
add_header Strict-Transport-Security "max-age={{ pillar['hsts_max_age'] }}; includeSubDomains; preload" always; |
|||
{% endif %} |
|||
|
|||
# Content Security Policy: |
|||
# - "img-src data:" is needed for Spectre.css icons |
|||
set $csp_value "default-src 'none'; script-src 'self'; style-src 'self'; img-src 'self' data:; connect-src 'self'; manifest-src 'self'; form-action 'self'; frame-ancestors 'none'; base-uri 'none'"; |
|||
|
|||
{% if grains['id'] == 'dev' %} |
|||
add_header Content-Security-Policy-Report-Only $csp_value always; |
|||
{% else %} |
|||
add_header Content-Security-Policy $csp_value always; |
|||
{% endif %} |
|||
|
|||
add_header X-Content-Type-Options "nosniff" always; |
|||
add_header X-Frame-Options "DENY" always; |
|||
add_header X-Xss-Protection "1; mode=block" always; |
|||
add_header Referrer-Policy "same-origin" always; |
|||
|
|||
server_name tildes.net localhost; |
|||
|
|||
keepalive_timeout 5; |
|||
|
|||
root {{ app_dir }}/static; |
|||
|
|||
# Block access to /metrics except from localhost (for Prometheus) |
|||
location /metrics { |
|||
allow 127.0.0.1; |
|||
deny all; |
|||
|
|||
# try_files is unnecessary here, but I don't know the "proper" way |
|||
try_files $uri @proxy_to_app; |
|||
} |
|||
|
|||
# add Expires+Cache-Control headers from the mime-type map defined above |
|||
expires $expires_type_map; |
|||
|
|||
location / { |
|||
# checks for static file, if not found proxy to app |
|||
try_files $uri @proxy_to_app; |
|||
gzip_static on; |
|||
} |
|||
|
|||
location @proxy_to_app { |
|||
# Cornice adds the X-Content-Type-Options header, so it will end up |
|||
# being duplicated since nginx is also configured to send it (above). |
|||
# It's better to drop the header coming from Gunicorn here than to |
|||
# stop sending it in nginx, since if I ever stop using Cornice I would |
|||
# lose that header (and probably not realize). |
|||
proxy_hide_header X-Content-Type-Options; |
|||
|
|||
proxy_set_header Host $host; |
|||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
|||
proxy_set_header X-Forwarded-Proto $scheme; |
|||
proxy_redirect off; |
|||
proxy_pass http://app_server; |
|||
} |
|||
} |
@ -0,0 +1,56 @@ |
|||
postgresql: |
|||
pkgrepo.managed: |
|||
- name: deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main |
|||
- dist: xenial-pgdg |
|||
- file: /etc/apt/sources.list.d/psql.list |
|||
- key_url: https://www.postgresql.org/media/keys/ACCC4CF8.asc |
|||
- require_in: |
|||
- pkg: postgresql |
|||
pkg.installed: |
|||
- name: postgresql-{{ pillar['postgresql_version'] }} |
|||
- refresh: True |
|||
service.running: |
|||
- require: |
|||
- pkg: postgresql |
|||
- reload: True |
|||
- watch: |
|||
- file: /etc/postgresql/{{ pillar['postgresql_version'] }}/main/*.conf |
|||
|
|||
set-lock-timeout: |
|||
file.replace: |
|||
- name: /etc/postgresql/{{ pillar['postgresql_version'] }}/main/postgresql.conf |
|||
- pattern: '^#?lock_timeout = (?!5000).*$' |
|||
- repl: 'lock_timeout = 5000' |
|||
|
|||
set-statement-timeout: |
|||
file.replace: |
|||
- name: /etc/postgresql/{{ pillar['postgresql_version'] }}/main/postgresql.conf |
|||
- pattern: '^#?statement_timeout = (?!5000).*$' |
|||
- repl: 'statement_timeout = 5000' |
|||
|
|||
set-idle-in-transaction-timeout: |
|||
file.replace: |
|||
- name: /etc/postgresql/{{ pillar['postgresql_version'] }}/main/postgresql.conf |
|||
- pattern: '^#?idle_in_transaction_session_timeout = (?!600000).*$' |
|||
- repl: 'idle_in_transaction_session_timeout = 600000' |
|||
|
|||
enable-pg-stat-statements: |
|||
file.replace: |
|||
- name: /etc/postgresql/{{ pillar['postgresql_version'] }}/main/postgresql.conf |
|||
- pattern: '^#?shared_preload_libraries = .*$' |
|||
- repl: "shared_preload_libraries = 'pg_stat_statements'" |
|||
- watch_in: |
|||
- module: enable-pg-stat-statements |
|||
module.wait: |
|||
- service.restart: |
|||
- name: postgresql.service |
|||
|
|||
/etc/postgresql/{{ pillar['postgresql_version'] }}/main/pg_hba.conf: |
|||
file.managed: |
|||
- source: salt://postgresql/pg_hba.conf.jinja2 |
|||
- template: jinja |
|||
- user: postgres |
|||
- group: postgres |
|||
- mode: 640 |
|||
require: |
|||
- service: postgresql |
@ -0,0 +1,6 @@ |
|||
{% for line in accumulator['pg_hba_lines'] -%} |
|||
{{ line }} |
|||
{% endfor %} |
|||
|
|||
# Required: allow the database superuser to connect via socket |
|||
local all postgres peer |
@ -0,0 +1,21 @@ |
|||
[databases] |
|||
{% for line in accumulator['pgbouncer_db_lines'] -%} |
|||
{{ line }} |
|||
{% endfor %} |
|||
|
|||
[pgbouncer] |
|||
logfile = /var/log/postgresql/pgbouncer.log |
|||
log_connections = 0 |
|||
log_disconnections = 0 |
|||
|
|||
pidfile = /var/run/postgresql/pgbouncer.pid |
|||
|
|||
listen_port = 6432 |
|||
|
|||
unix_socket_dir = /var/run/postgresql |
|||
|
|||
auth_type = hba |
|||
auth_file = /etc/pgbouncer/userlist.txt |
|||
auth_hba_file = /etc/postgresql/{{ pillar['postgresql_version'] }}/main/pg_hba.conf |
|||
|
|||
pool_mode = transaction |
@ -0,0 +1,25 @@ |
|||
install-pgbouncer: |
|||
pkg.installed: |
|||
- name: pgbouncer |
|||
|
|||
/etc/pgbouncer/pgbouncer.ini: |
|||
file.managed: |
|||
- source: salt://postgresql/pgbouncer.ini.jinja2 |
|||
- template: jinja |
|||
- user: postgres |
|||
- group: postgres |
|||
- mode: 640 |
|||
|
|||
/etc/pgbouncer/userlist.txt: |
|||
file.managed: |
|||
- contents: '"tildes" ""' |
|||
- user: postgres |
|||
- group: postgres |
|||
- mode: 640 |
|||
|
|||
pgbouncer.service: |
|||
service.running: |
|||
- enable: True |
|||
- reload: True |
|||
- watch: |
|||
- file: /etc/pgbouncer/pgbouncer.ini |
@ -0,0 +1,57 @@ |
|||
site-db-user: |
|||
postgres_user.present: |
|||
- name: tildes |
|||
- require: |
|||
- service: postgresql |
|||
|
|||
site-db-database: |
|||
postgres_database.present: |
|||
- name: tildes |
|||
- owner: tildes |
|||
- require: |
|||
- postgres_user: tildes |
|||
|
|||
site-db-enable-citext: |
|||
postgres_extension.present: |
|||
- name: citext |
|||
- maintenance_db: tildes |
|||
- require: |
|||
- postgres_database: tildes |
|||
|
|||
site-db-enable-ltree: |
|||
postgres_extension.present: |
|||
- name: ltree |
|||
- maintenance_db: tildes |
|||
- require: |
|||
- postgres_database: tildes |
|||
|
|||
site-db-enable-intarray: |
|||
postgres_extension.present: |
|||
- name: intarray |
|||
- maintenance_db: tildes |
|||
- require: |
|||
- postgres_database: tildes |
|||
|
|||
site-db-enable-pg_stat_statements: |
|||
postgres_extension.present: |
|||
- name: pg_stat_statements |
|||
- maintenance_db: tildes |
|||
- require: |
|||
- postgres_database: tildes |
|||
|
|||
site-db-pg_hba-lines: |
|||
file.accumulated: |
|||
- name: pg_hba_lines |
|||
- filename: /etc/postgresql/{{ pillar['postgresql_version'] }}/main/pg_hba.conf |
|||
- text: |
|||
- 'local sameuser tildes trust' |
|||
- require_in: |
|||
- file: /etc/postgresql/{{ pillar['postgresql_version'] }}/main/pg_hba.conf |
|||
|
|||
site-db-pgbouncer-lines: |
|||
file.accumulated: |
|||
- name: pgbouncer_db_lines |
|||
- filename: /etc/pgbouncer/pgbouncer.ini |
|||
- text: 'tildes =' |
|||
- require_in: |
|||
- file: /etc/pgbouncer/pgbouncer.ini |
@ -0,0 +1,44 @@ |
|||
test-db-database: |
|||
postgres_database.present: |
|||
- name: tildes_test |
|||
- owner: tildes |
|||
- require: |
|||
- postgres_user: tildes |
|||
|
|||
test-db-enable-citext: |
|||
postgres_extension.present: |
|||
- name: citext |
|||
- maintenance_db: tildes_test |
|||
- require: |
|||
- postgres_database: tildes_test |
|||
|
|||
test-db-enable-ltree: |
|||
postgres_extension.present: |
|||
- name: ltree |
|||
- maintenance_db: tildes_test |
|||
- require: |
|||
- postgres_database: tildes_test |
|||
|
|||
test-db-enable-intarray: |
|||
postgres_extension.present: |
|||
- name: intarray |
|||
- maintenance_db: tildes_test |
|||
- require: |
|||
- postgres_database: tildes_test |
|||
|
|||
test-db-pg_hba-lines: |
|||
file.accumulated: |
|||
- name: pg_hba_lines |
|||
- filename: /etc/postgresql/{{ pillar['postgresql_version'] }}/main/pg_hba.conf |
|||
- text: |
|||
- 'local tildes_test tildes trust' |
|||
- require_in: |
|||
- file: /etc/postgresql/{{ pillar['postgresql_version'] }}/main/pg_hba.conf |
|||
|
|||
test-db-pgbouncer-lines: |
|||
file.accumulated: |
|||
- name: pgbouncer_db_lines |
|||
- filename: /etc/pgbouncer/pgbouncer.ini |
|||
- text: 'tildes_test =' |
|||
- require_in: |
|||
- file: /etc/pgbouncer/pgbouncer.ini |
@ -0,0 +1,28 @@ |
|||
# Download/extract and set up the node exporter (hardware/OS metrics) |
|||
include: |
|||
- prometheus.user |
|||
|
|||
unpack-node-exporter: |
|||
archive.extracted: |
|||
- name: /opt/prometheus_node_exporter |
|||
- source: |
|||
- salt://prometheus/exporters/node_exporter-0.13.0.linux-amd64.tar.gz |
|||
- https://github.com/prometheus/node_exporter/releases/download/v0.13.0/node_exporter-0.13.0.linux-amd64.tar.gz |
|||
- source_hash: sha256=2de5d1e51330c41588ed4c88bc531a3d2dccf6b4d7b99d5782d95cff27a3c049 |
|||
- if_missing: /opt/prometheus_node_exporter |
|||
- user: prometheus |
|||
- group: prometheus |
|||
- options: --strip-components=1 |
|||
- enforce_toplevel: False |
|||
|
|||
/etc/systemd/system/prometheus_node_exporter.service: |
|||
file.managed: |
|||
- source: salt://prometheus/exporters/prometheus_node_exporter.service |
|||
- user: root |
|||
- group: root |
|||
- mode: 644 |
|||
|
|||
prometheus-node-exporter-service: |
|||
service.running: |
|||
- name: prometheus_node_exporter |
|||
- enable: True |
@ -0,0 +1,28 @@ |
|||
# Download and set up the postgres exporter |
|||
include: |
|||
- prometheus.user |
|||
|
|||
postgres-exporter: |
|||
file.managed: |
|||
- name: /opt/prometheus_postgres_exporter/postgres_exporter |
|||
- source: |
|||
- salt://prometheus/exporters/postgres_exporter |
|||
- https://github.com/wrouesnel/postgres_exporter/releases/download/v0.3.0/postgres_exporter |
|||
- source_hash: sha256=44654860e3122acf183e8cad504bddc3bf9dd717910cddc99b589a3463d2ec6f |
|||
- user: postgres |
|||
- group: postgres |
|||
- mode: 774 |
|||
- makedirs: True |
|||
- unless: ls /opt/prometheus_postgres_exporter/postgres_exporter |
|||
|
|||
/etc/systemd/system/prometheus_postgres_exporter.service: |
|||
file.managed: |
|||
- source: salt://prometheus/exporters/prometheus_postgres_exporter.service |
|||
- user: root |
|||
- group: root |
|||
- mode: 644 |
|||
|
|||
prometheus-postgres-exporter-service: |
|||
service.running: |
|||
- name: prometheus_postgres_exporter |
|||
- enable: True |
@ -0,0 +1,14 @@ |
|||
[Unit] |
|||
Description=Prometheus Node Exporter |
|||
After=syslog.target network.target |
|||
|
|||
[Service] |
|||
Type=simple |
|||
RemainAfterExit=no |
|||
WorkingDirectory=/opt/prometheus_node_exporter |
|||
User=prometheus |
|||
Group=prometheus |
|||
ExecStart=/opt/prometheus_node_exporter/node_exporter -log.level info |
|||
|
|||
[Install] |
|||
WantedBy=multi-user.target |
@ -0,0 +1,15 @@ |
|||
[Unit] |
|||
Description=Prometheus Postgres Exporter |
|||
After=syslog.target network.target |
|||
|
|||
[Service] |
|||
Type=simple |
|||
RemainAfterExit=no |
|||
WorkingDirectory=/opt/prometheus_postgres_exporter |
|||
User=postgres |
|||
Group=postgres |
|||
Environment="DATA_SOURCE_NAME=user=postgres host=/run/postgresql/ sslmode=disable" |
|||
ExecStart=/opt/prometheus_postgres_exporter/postgres_exporter |
|||
|
|||
[Install] |
|||
WantedBy=multi-user.target |
@ -0,0 +1,14 @@ |
|||
[Unit] |
|||
Description=Prometheus Redis Exporter |
|||
After=syslog.target network.target |
|||
|
|||
[Service] |
|||
Type=simple |
|||
RemainAfterExit=no |
|||
WorkingDirectory=/opt/prometheus_redis_exporter |
|||
User=prometheus |
|||
Group=prometheus |
|||
ExecStart=/opt/prometheus_redis_exporter/redis_exporter |
|||
|
|||
[Install] |
|||
WantedBy=multi-user.target |
@ -0,0 +1,27 @@ |
|||
# Download/extract and set up the redis exporter |
|||
include: |
|||
- prometheus.user |
|||
|
|||
unpack-redis-exporter: |
|||
archive.extracted: |
|||
- name: /opt/prometheus_redis_exporter |
|||
- source: |
|||
- salt://prometheus/exporters/redis_exporter-v0.10.7.linux-amd64.tar.gz |
|||
- https://github.com/oliver006/redis_exporter/releases/download/v0.10.7/redis_exporter-v0.10.7.linux-amd64.tar.gz |
|||
- source_hash: sha256=b9b48f321a201f3b424f1710d2cac1bca03272d67001812d8b2fb6305099fb09 |
|||
- if_missing: /opt/prometheus_redis_exporter |
|||
- user: prometheus |
|||
- group: prometheus |
|||
- enforce_toplevel: False |
|||
|
|||
/etc/systemd/system/prometheus_redis_exporter.service: |
|||
file.managed: |
|||
- source: salt://prometheus/exporters/prometheus_redis_exporter.service |
|||
- user: root |
|||
- group: root |
|||
- mode: 644 |
|||
|
|||
prometheus-redis-exporter-service: |
|||
service.running: |
|||
- name: prometheus_redis_exporter |
|||
- enable: True |
@ -0,0 +1,57 @@ |
|||
include: |
|||
- prometheus.user |
|||
|
|||
unpack-prometheus: |
|||
archive.extracted: |
|||
- name: /opt/prometheus |
|||
- source: |
|||
- salt://prometheus/prometheus-2.0.0.linux-amd64.tar.gz |
|||
- https://github.com/prometheus/prometheus/releases/download/v2.0.0/prometheus-2.0.0.linux-amd64.tar.gz |
|||
- source_hash: sha256=e12917b25b32980daee0e9cf879d9ec197e2893924bd1574604eb0f550034d46 |
|||
- if_missing: /opt/prometheus |
|||
- user: prometheus |
|||
- group: prometheus |
|||
- options: --strip-components=1 |
|||
- enforce_toplevel: False |
|||
|
|||
/etc/systemd/system/prometheus.service: |
|||
file.managed: |
|||
- source: salt://prometheus/prometheus.service |
|||
- user: root |
|||
- group: root |
|||
- mode: 644 |
|||
|
|||
prometheus-service: |
|||
service.running: |
|||
- name: prometheus |
|||
- enable: True |
|||
- watch: |
|||
- file: /opt/prometheus/prometheus.yml |
|||
|
|||
|
|||
/opt/prometheus/prometheus.yml: |
|||
file.managed: |
|||
- source: salt://prometheus/prometheus.yml |
|||
- user: prometheus |
|||
- group: prometheus |
|||
- mode: 664 |
|||
|
|||
{# Set up nginx to reverse-proxy to prometheus in production #} |
|||
{% if grains['id'] == 'prod' %} |
|||
/etc/nginx/sites-available/prometheus.conf: |
|||
file.managed: |
|||
- source: salt://prometheus/prometheus.conf.jinja2 |
|||
- template: jinja |
|||
- user: root |
|||
- group: root |
|||
- mode: 644 |
|||
- makedirs: True |
|||
|
|||
/etc/nginx/sites-enabled/prometheus.conf: |
|||
file.symlink: |
|||
- target: /etc/nginx/sites-available/prometheus.conf |
|||
- makedirs: True |
|||
- user: root |
|||
- group: root |
|||
- mode: 644 |
|||
{% endif %} |
@ -0,0 +1,21 @@ |
|||
server { |
|||
listen 443 ssl http2; |
|||
listen [::]:443 ssl http2; |
|||
|
|||
{% for ip in pillar['developer_ips'] %} |
|||
allow {{ ip }}; |
|||
{% endfor %} |
|||
deny all; |
|||
|
|||
add_header Strict-Transport-Security "max-age={{ pillar['hsts_max_age'] }}; includeSubDomains; preload" always; |
|||
|
|||
server_name {{ pillar['prometheus_server_name'] }}; |
|||
|
|||
location / { |
|||
proxy_set_header Host $host; |
|||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
|||
proxy_set_header X-Forwarded-Proto $scheme; |
|||
proxy_redirect off; |
|||
proxy_pass http://localhost:9090; |
|||
} |
|||
} |
@ -0,0 +1,14 @@ |
|||
[Unit] |
|||
Description=Prometheus Server |
|||
After=syslog.target network.target |
|||
|
|||
[Service] |
|||
Type=simple |
|||
RemainAfterExit=no |
|||
WorkingDirectory=/opt/prometheus |
|||
User=prometheus |
|||
Group=prometheus |
|||
ExecStart=/opt/prometheus/prometheus --config.file=/opt/prometheus/prometheus.yml --log.level info |
|||
|
|||
[Install] |
|||
WantedBy=multi-user.target |
@ -0,0 +1,23 @@ |
|||
global: |
|||
scrape_interval: 30s |
|||
evaluation_interval: 30s |
|||
|
|||
scrape_configs: |
|||
- job_name: "node" |
|||
static_configs: |
|||
- targets: ['localhost:9100'] |
|||
|
|||
- job_name: "redis" |
|||
static_configs: |
|||
- targets: ['localhost:9121'] |
|||
|
|||
- job_name: "postgres" |
|||
static_configs: |
|||
- targets: ['localhost:9187'] |
|||
|
|||
- job_name: "tildes" |
|||
scheme: https |
|||
static_configs: |
|||
- targets: ['localhost:443'] |
|||
tls_config: |
|||
insecure_skip_verify: true |
@ -0,0 +1,7 @@ |
|||
prometheus-user: |
|||
group.present: |
|||
- name: prometheus |
|||
user.present: |
|||
- name: prometheus |
|||
- groups: [prometheus] |
|||
- createhome: False |
@ -0,0 +1,58 @@ |
|||
{% from 'common.jinja2' import app_dir, bin_dir, python_version, venv_dir %} |
|||
|
|||
pyenv-deps: |
|||
pkg.installed: |
|||
- pkgs: |
|||
- build-essential |
|||
- curl |
|||
- libbz2-dev |
|||
- libncurses5-dev |
|||
- libncursesw5-dev |
|||
- libreadline-dev |
|||
- libsqlite3-dev |
|||
- libssl-dev |
|||
- llvm |
|||
- make |
|||
- wget |
|||
- xz-utils |
|||
- zlib1g-dev |
|||
|
|||
python-3.6: |
|||
pyenv.installed: |
|||
- name: {{ python_version }} |
|||
- default: True |
|||
- require: |
|||
- pkg: pyenv-deps |
|||
|
|||
delete-obsolete-venv: |
|||
file.absent: |
|||
- name: {{ venv_dir }} |
|||
- unless: {{ bin_dir }}/python --version | grep {{ python_version }} |
|||
|
|||
# Salt seems to use the deprecated pyvenv script, manual for now |
|||
venv-setup: |
|||
pkg.installed: |
|||
- name: python3-venv |
|||
cmd.run: |
|||
- name: /usr/local/pyenv/versions/{{ python_version }}/bin/python -m venv {{ venv_dir }} |
|||
- creates: {{ venv_dir }} |
|||
- require: |
|||
- pkg: python3-venv |
|||
- pyenv: {{ python_version }} |
|||
|
|||
pip-installs: |
|||
pip.installed: |
|||
- requirements: {{ app_dir }}/requirements.txt |
|||
- bin_env: {{ venv_dir }} |
|||
require: |
|||
- cmd: venv-setup |
|||
- pkg: pip-deps |
|||
|
|||
self-install: |
|||
pip.installed: |
|||
- bin_env: {{ venv_dir }} |
|||
- editable: |
|||
- {{ app_dir }} |
|||
- require: |
|||
- cmd: venv-setup |
|||
- unless: ls {{ venv_dir }}/lib/python3.6/site-packages/tildes.egg-link |
@ -0,0 +1 @@ |
|||
{"exchanges":[{"name":"pgsql_events","vhost":"/","type":"topic","durable":true,"auto_delete":false,"internal":false,"arguments":{}}]} |
@ -0,0 +1,82 @@ |
|||
erlang: |
|||
pkgrepo.managed: |
|||
- name: deb http://packages.erlang-solutions.com/ubuntu/ xenial contrib |
|||
- dist: xenial |
|||
- file: /etc/apt/sources.list.d/erlang.list |
|||
- key_url: https://packages.erlang-solutions.com/ubuntu/erlang_solutions.asc |
|||
- require_in: |
|||
- pkg: rabbitmq-server |
|||
file.managed: |
|||
- name: /etc/apt/preferences.d/erlang |
|||
- mode: 755 |
|||
- contents: | |
|||
Package: erlang* |
|||
Pin: version 1:20.3-1 |
|||
Pin-Priority: 1000 |
|||
- require_in: |
|||
- pkg: rabbitmq-server |
|||
|
|||
rabbitmq: |
|||
pkgrepo.managed: |
|||
- name: deb http://www.rabbitmq.com/debian/ testing main |
|||
- dist: testing |
|||
- file: /etc/apt/sources.list.d/rabbitmq.list |
|||
- key_url: https://www.rabbitmq.com/rabbitmq-release-signing-key.asc |
|||
- require_in: |
|||
- pkg: rabbitmq-server |
|||
pkg.installed: |
|||
- name: rabbitmq-server |
|||
- refresh: True |
|||
|
|||
rabbitmq-server.service: |
|||
service.running: |
|||
- enable: True |
|||
- watch: |
|||
- file: /etc/rabbitmq/rabbitmq.config |
|||
- file: /etc/rabbitmq/definitions.json |
|||
|
|||
rabbitmq-management: |
|||
cmd.run: |
|||
- name: rabbitmq-plugins enable rabbitmq_management |
|||
- unless: 'rabbitmq-plugins list | grep \\[E.*rabbitmq_management' |
|||
|
|||
/usr/local/bin/rabbitmqadmin: |
|||
cmd.run: |
|||
- name: wget http://localhost:15672/cli/rabbitmqadmin -O /usr/local/bin/rabbitmqadmin |
|||
- creates: /usr/local/bin/rabbitmqadmin |
|||
file.managed: |
|||
- mode: 755 |
|||
|
|||
/etc/rabbitmq/rabbitmq.config: |
|||
file.managed: |
|||
- source: salt://rabbitmq/rabbitmq.config |
|||
- group: rabbitmq |
|||
- mode: 644 |
|||
|
|||
/etc/rabbitmq/definitions.json: |
|||
file.managed: |
|||
- source: salt://rabbitmq/definitions.json |
|||
- group: rabbitmq |
|||
- mode: 644 |
|||
|
|||
install-pg-amqp-bridge: |
|||
archive.extracted: |
|||
- name: /usr/local/bin |
|||
- source: |
|||
- https://github.com/subzerocloud/pg-amqp-bridge/releases/download/0.0.5/pg-amqp-bridge-0.0.5-x86_64-unknown-linux-gnu.tar.gz |
|||
- source_hash: sha256=8194c3307fe7954a0ef1ba66d2f51e14647756d0f87ddd468ef0dc3fbc8476fe |
|||
- unless: ls /usr/local/bin/pg-amqp-bridge |
|||
- enforce_toplevel: False |
|||
|
|||
/etc/systemd/system/pg-amqp-bridge.service: |
|||
file.managed: |
|||
- source: salt://rabbitmq/pg-amqp-bridge.service |
|||
- user: root |
|||
- group: root |
|||
- mode: 644 |
|||
- require_in: |
|||
- pg-amqp-bridge.service |
|||
|
|||
pg-amqp-bridge.service: |
|||
service.running: |
|||
- enable: True |
@ -0,0 +1,14 @@ |
|||
[Unit] |
|||
Description=pg-amqp-bridge - send pgsql NOTIFY to rabbitmq |
|||
Requires=rabbitmq-server.service |
|||
After=rabbitmq-server.service |
|||
PartOf=rabbitmq-server.service |
|||
|
|||
[Service] |
|||
Environment="POSTGRESQL_URI=postgres://tildes@%2Frun%2Fpostgresql/tildes" "AMQP_URI=amqp://localhost//" "BRIDGE_CHANNELS=pgsql_events:pgsql_events" "DELIVERY_MODE=PERSISTENT" |
|||
ExecStart=/usr/local/bin/pg-amqp-bridge |
|||
Restart=always |
|||
RestartSec=5 |
|||
|
|||
[Install] |
|||
WantedBy=multi-user.target |
@ -0,0 +1,5 @@ |
|||
[ |
|||
{rabbitmq_management, [ |
|||
{load_definitions, "/etc/rabbitmq/definitions.json"} |
|||
]} |
|||
]. |
@ -0,0 +1,6 @@ |
|||
{% from 'common.jinja2' import app_dir, venv_dir %} |
|||
|
|||
raven-pip-install: |
|||
pip.installed: |
|||
- name: raven |
|||
- bin_env: {{ venv_dir }} |
@ -0,0 +1,144 @@ |
|||
{% set redis_version = '4.0.9' %} |
|||
|
|||
unpack-redis: |
|||
archive.extracted: |
|||
- name: /tmp/redis-{{ redis_version }} |
|||
- source: |
|||
- salt://redis/{{ redis_version }}.tar.gz |
|||
- https://github.com/antirez/redis/archive/{{ redis_version }}.tar.gz |
|||
- source_hash: sha256=e18eebc08a4ccf48ac28aed692c69cf7b03f188d890803e7ccc6889c049f10b4 |
|||
- unless: /usr/local/bin/redis-server --version | grep v={{ redis_version }} |
|||
- options: --strip-components=1 |
|||
- enforce_toplevel: False |
|||
|
|||
install-redis: |
|||
pkg.installed: |
|||
- pkgs: |
|||
- build-essential |
|||
cmd.run: |
|||
- cwd: /tmp/redis-{{ redis_version }}/ |
|||
- names: |
|||
- make |
|||
- make install |
|||
- onchanges: |
|||
- archive: unpack-redis |
|||
|
|||
redis-user: |
|||
group.present: |
|||
- name: redis |
|||
user.present: |
|||
- name: redis |
|||
- groups: [redis] |
|||
- createhome: False |
|||
|
|||
/run/redis: |
|||
file.directory: |
|||
- user: redis |
|||
- group: redis |
|||
- mode: 755 |
|||
- require: |
|||
- user: redis-user |
|||
|
|||
/var/lib/redis: |
|||
file.directory: |
|||
- user: redis |
|||
- group: redis |
|||
- mode: 700 |
|||
- require: |
|||
- user: redis-user |
|||
|
|||
/var/log/redis: |
|||
file.directory: |
|||
- user: redis |
|||
- group: redis |
|||
- mode: 744 |
|||
- require: |
|||
- user: redis-user |
|||
|
|||
/etc/redis.conf: |
|||
file.managed: |
|||
- source: salt://redis/redis.conf.jinja2 |
|||
- template: jinja |
|||
- user: redis |
|||
- group: redis |
|||
- mode: 600 |
|||
- require: |
|||
- user: redis-user |
|||
|
|||
/etc/systemd/system/redis.service: |
|||
file.managed: |
|||
- source: salt://redis/redis.service |
|||
- user: root |
|||
- group: root |
|||
- mode: 644 |
|||
- require_in: |
|||
- service: redis.service |
|||
|
|||
# add the service file for disabling transparent hugepage |
|||
/etc/systemd/system/transparent_hugepage.service: |
|||
file.managed: |
|||
- source: salt://redis/transparent_hugepage.service |
|||
- user: root |
|||
- group: root |
|||
- mode: 644 |
|||
- require_in: |
|||
- service: disable-transparent-hugepage |
|||
|
|||
# enable the "disable transparent hugepage" service, and run it + restart redis if necessary |
|||
disable-transparent-hugepage: |
|||
service.enabled: |
|||
- name: transparent_hugepage.service |
|||
cmd.run: |
|||
- name: systemctl start transparent_hugepage.service && systemctl restart redis.service |
|||
- unless: 'cat /sys/kernel/mm/transparent_hugepage/enabled | grep \\[never\\]' |
|||
|
|||
# Set kernel overcommit mode (recommended for Redis) |
|||
overcommit-memory: |
|||
# will take effect immediately |
|||
cmd.run: |
|||
- name: sysctl vm.overcommit_memory=1 |
|||
- unless: sysctl -n vm.overcommit_memory | grep 1 |
|||
|
|||
# makes the setting permanent but requires a restart |
|||
file.append: |
|||
- name: /etc/sysctl.conf |
|||
- text: 'vm.overcommit_memory = 1' |
|||
|
|||
redis.service: |
|||
service.running: |
|||
- enable: True |
|||
- watch: |
|||
- file: /etc/redis.conf |
|||
- require: |
|||
- user: redis-user |
|||
- cmd: install-redis |
|||
|
|||
/run/redis_breached_passwords: |
|||
file.directory: |
|||
- user: redis |
|||
- group: redis |
|||
- mode: 755 |
|||
- require: |
|||
- user: redis-user |
|||
|
|||
/etc/redis_breached_passwords.conf: |
|||
file.managed: |
|||
- source: salt://redis/redis_breached_passwords.conf |
|||
- user: redis |
|||
- group: redis |
|||
- mode: 600 |
|||
|
|||
/etc/systemd/system/redis_breached_passwords.service: |
|||
file.managed: |
|||
- source: salt://redis/redis_breached_passwords.service |
|||
- user: root |
|||
- group: root |
|||
- mode: 644 |
|||
- require_in: |
|||
- service: redis_breached_passwords.service |
|||
|
|||
redis_breached_passwords.service: |
|||
service.running: |
|||
- enable: True |
|||
- watch: |
|||
- file: /etc/redis_breached_passwords.conf |
@ -0,0 +1,14 @@ |
|||
rebloom-clone: |
|||
git.latest: |
|||
- name: https://github.com/RedisLabsModules/rebloom |
|||
- rev: 4947c9a75838688df56fc818729b93bf36588400 |
|||
- target: /opt/rebloom |
|||
|
|||
rebloom-make: |
|||
cmd.run: |
|||
- name: make |
|||
- cwd: /opt/rebloom |
|||
- onchanges: |
|||
- git: rebloom-clone |
|||
- require_in: |
|||
- service: redis_breached_passwords.service |
@ -0,0 +1,20 @@ |
|||
redis-cell-unpack: |
|||
archive.extracted: |
|||
- name: /opt/redis-cell |
|||
- source: |
|||
- salt://redis/modules/redis-cell-v0.2.1-x86_64-unknown-linux-gnu.tar.gz |
|||
- https://github.com/brandur/redis-cell/releases/download/v0.2.1/redis-cell-v0.2.1-x86_64-unknown-linux-gnu.tar.gz |
|||
- source_hash: sha256=9427fb100f4cada817f30f854ead7f233de32948a0ec644f15988c275a2ed1cb |
|||
- if_missing: /opt/redis-cell |
|||
- enforce_toplevel: False |
|||
- require_in: |
|||
- service: redis.service |
|||
|
|||
redis-cell-loadmodule-line: |
|||
file.accumulated: |
|||
- name: redis_loadmodule_lines |
|||
- filename: /etc/redis.conf |
|||
- text: |
|||
- 'loadmodule /opt/redis-cell/libredis_cell.so' |
|||
- require_in: |
|||
- file: /etc/redis.conf |
1297
salt/salt/redis/redis.conf.jinja2
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,14 @@ |
|||
[Unit] |
|||
Description=redis daemon |
|||
After=network.target |
|||
|
|||
[Service] |
|||
PIDFile=/run/redis/pid |
|||
User=redis |
|||
Group=redis |
|||
RuntimeDirectory=redis |
|||
ExecStart=/usr/local/bin/redis-server /etc/redis.conf |
|||
Restart=always |
|||
|
|||
[Install] |
|||
WantedBy=multi-user.target |
@ -0,0 +1,24 @@ |
|||
loadmodule /opt/rebloom/rebloom.so |
|||
bind 127.0.0.1 |
|||
|
|||
# only listen on unix socket |
|||
port 0 |
|||
|
|||
unixsocket /run/redis_breached_passwords/socket |
|||
unixsocketperm 777 |
|||
|
|||
timeout 0 |
|||
|
|||
supervised systemd |
|||
pidfile /run/redis_breached_passwords/pid |
|||
|
|||
loglevel notice |
|||
logfile "" |
|||
|
|||
databases 1 |
|||
rdbchecksum yes |
|||
|
|||
dir /var/lib/redis |
|||
dbfilename breached_passwords_dump.rdb |
|||
|
|||
appendonly no |
@ -0,0 +1,14 @@ |
|||
[Unit] |
|||
Description=redis breached passwords daemon |
|||
After=network.target |
|||
|
|||
[Service] |
|||
PIDFile=/run/redis_breached_passwords/pid |
|||
User=redis |
|||
Group=redis |
|||
RuntimeDirectory=redis_breached_passwords |
|||
ExecStart=/usr/local/bin/redis-server /etc/redis_breached_passwords.conf |
|||
Restart=always |
|||
|
|||
[Install] |
|||
WantedBy=multi-user.target |
@ -0,0 +1,11 @@ |
|||
[Unit] |
|||
Description=Disable transparent hugepage for redis |
|||
Before=redis.service |
|||
|
|||
[Service] |
|||
Type=oneshot |
|||
ExecStart=/bin/bash -c 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' |
|||
ExecStart=/bin/bash -c 'echo never > /sys/kernel/mm/transparent_hugepage/defrag' |
|||
|
|||
[Install] |
|||
RequiredBy=redis.service |
@ -0,0 +1,7 @@ |
|||
{% from 'common.jinja2' import app_dir, bin_dir -%} |
|||
#!/bin/bash |
|||
# |
|||
# Simple convenience script to activate the venv and switch to the app dir |
|||
# (Needs to be run by sourcing or it won't do anything) |
|||
cd {{ app_dir }} |
|||
source {{ bin_dir }}/activate |
@ -0,0 +1,5 @@ |
|||
{% from 'common.jinja2' import app_dir -%} |
|||
{% from 'site-icons-spriter.sls' import site_icons_venv_dir, site_icons_data_dir -%} |
|||
#!/bin/bash |
|||
{{ site_icons_venv_dir }}/bin/glue --sprite-namespace= --namespace= --retina --css-template={{ app_dir }}/scripts/site-icons-spriter/css_template.jinja2 {{ site_icons_data_dir }}/site-icons {{ site_icons_data_dir }}/output |
|||
cp {{ site_icons_data_dir }}/output/*.png {{ app_dir }}/static/images |
@ -0,0 +1,7 @@ |
|||
/usr/local/bin/activate: |
|||
file.managed: |
|||
- source: salt://scripts/activate.sh.jinja2 |
|||
- template: jinja |
|||
- user: root |
|||
- group: root |
|||
- mode: 755 |
@ -0,0 +1,17 @@ |
|||
self-signed-cert: |
|||
pkg.installed: |
|||
- name: python3-openssl |
|||
module.run: |
|||
- tls.create_self_signed_cert: |
|||
- days: 3650 |
|||
- require: |
|||
- pkg: python3-openssl |
|||
- unless: ls /etc/pki/tls/certs/localhost.key |
|||
file.managed: |
|||
- name: /etc/pki/tls/certs/localhost.key |
|||
- mode: 600 |
|||
- replace: False |
|||
- require: |
|||
- module: self-signed-cert |
|||
- require_in: |
|||
- service: nginx |
@ -0,0 +1,4 @@ |
|||
{% set sentry_cfg_dir = '/etc/sentry' %} |
|||
|
|||
{% set sentry_venv_dir = '/opt/venvs/sentry' %} |
|||
{% set sentry_bin_dir = sentry_venv_dir + '/bin' %} |
@ -0,0 +1,64 @@ |
|||
# While a lot of configuration in Sentry can be changed via the UI, for all |
|||
# new-style config (as of 8.0) you can also declare values here in this file |
|||
# to enforce defaults or to ensure they cannot be changed via the UI. For more |
|||
# information see the Sentry documentation. |
|||
|
|||
############### |
|||
# Mail Server # |
|||
############### |
|||
|
|||
mail.backend: 'dummy' # Use dummy if you want to disable email entirely |
|||
# mail.host: 'localhost' |
|||
# mail.port: 25 |
|||
# mail.username: '' |
|||
# mail.password: '' |
|||
# mail.use-tls: false |
|||
# The email address to send on behalf of |
|||
# mail.from: 'root@localhost' |
|||
|
|||
# If you'd like to configure email replies, enable this. |
|||
# mail.enable-replies: false |
|||
|
|||
# When email-replies are enabled, this value is used in the Reply-To header |
|||
# mail.reply-hostname: '' |
|||
|
|||
# If you're using mailgun for inbound mail, set your API key and configure a |
|||
# route to forward to /api/hooks/mailgun/inbound/ |
|||
# mail.mailgun-api-key: '' |
|||
|
|||
################### |
|||
# System Settings # |
|||
################### |
|||
|
|||
# If this file ever becomes compromised, it's important to regenerate your a new key |
|||
# Changing this value will result in all current sessions being invalidated. |
|||
# A new key can be generated with `$ sentry config generate-secret-key` |
|||
system.secret-key: '{{ pillar['sentry_secret'] }}' |
|||
|
|||
# The ``redis.clusters`` setting is used, unsurprisingly, to configure Redis |
|||
# clusters. These clusters can be then referred to by name when configuring |
|||
# backends such as the cache, digests, or TSDB backend. |
|||
redis.clusters: |
|||
default: |
|||
hosts: |
|||
0: |
|||
host: 127.0.0.1 |
|||
port: 6379 |
|||
db: 10 |
|||
|
|||
################ |
|||
# File storage # |
|||
################ |
|||
|
|||
# Uploaded media uses these `filestore` settings. The available |
|||
# backends are either `filesystem` or `s3`. |
|||
|
|||
filestore.backend: 'filesystem' |
|||
filestore.options: |
|||
location: '/tmp/sentry-files' |
|||
|
|||
# filestore.backend: 's3' |
|||
# filestore.options: |
|||
# access_key: 'AKIXXXXXX' |
|||
# secret_key: 'XXXXXXX' |
|||
# bucket_name: 's3-bucket-name' |
@ -0,0 +1,143 @@ |
|||
{% from 'sentry/common.jinja2' import sentry_bin_dir, sentry_cfg_dir, sentry_venv_dir %} |
|||
|
|||
sentry-user: |
|||
group.present: |
|||
- name: sentry |
|||
user.present: |
|||
- name: sentry |
|||
- groups: [sentry] |
|||
|
|||
build-deps: |
|||
pkg.installed: |
|||
- pkgs: |
|||
- python-setuptools |
|||
- python-dev |
|||
- python-pip |
|||
- python-virtualenv |
|||
- libxslt1-dev |
|||
- gcc |
|||
- libffi-dev |
|||
- libjpeg-dev |
|||
- libxml2-dev |
|||
- libxslt-dev |
|||
- libyaml-dev |
|||
- libpq-dev |
|||
- zlib1g-dev |
|||
- postgresql-server-dev-{{ pillar['postgresql_version'] }} |
|||
|
|||
{{ sentry_venv_dir }}: |
|||
virtualenv.managed: |
|||
- system_site_packages: False |
|||
|
|||
pip-install: |
|||
pip.installed: |
|||
- name: sentry |
|||
- bin_env: {{ sentry_venv_dir }} |
|||
|
|||
init-sentry: |
|||
cmd.run: |
|||
- name: {{ sentry_bin_dir }}/sentry init {{ sentry_cfg_dir }} |
|||
- creates: {{ sentry_cfg_dir }} |
|||
|
|||
postgres-setup: |
|||
postgres_user.present: |
|||
- name: sentry |
|||
postgres_database.present: |
|||
- name: sentry |
|||
- owner: sentry |
|||
# sentry migrations should add this, but it fails due to not being superuser |
|||
postgres_extension.present: |
|||
- name: citext |
|||
- maintenance_db: sentry |
|||
|
|||
{{ sentry_cfg_dir }}/sentry.conf.py: |
|||
file.managed: |
|||
- source: salt://sentry/sentry.conf.py |
|||
|
|||
{{ sentry_cfg_dir }}/config.yml: |
|||
file.managed: |
|||
- source: salt://sentry/config.yml.jinja2 |
|||
- template: jinja |
|||
|
|||
update-pg_hba: |
|||
file.accumulated: |
|||
- name: pg_hba_lines |
|||
- filename: /etc/postgresql/{{ pillar['postgresql_version'] }}/main/pg_hba.conf |
|||
- text: 'host sameuser sentry 127.0.0.1/32 trust' |
|||
- require_in: |
|||
- file: /etc/postgresql/{{ pillar['postgresql_version'] }}/main/pg_hba.conf |
|||
|
|||
create-sentry-db: |
|||
cmd.run: |
|||
- name: {{ sentry_bin_dir }}/sentry upgrade --noinput |
|||
- env: |
|||
- SENTRY_CONF: '{{ sentry_cfg_dir }}' |
|||
- onchanges: |
|||
- cmd: init-sentry |
|||
|
|||
create-sentry-user: |
|||
cmd.run: |
|||
- name: {{ sentry_bin_dir }}/sentry createuser --no-input --email {{ pillar['sentry_email'] }} --password {{ pillar['sentry_password'] }} |
|||
- env: |
|||
- SENTRY_CONF: '{{ sentry_cfg_dir }}' |
|||
- onchanges: |
|||
- cmd: init-sentry |
|||
|
|||
/etc/systemd/system/sentry-web.service: |
|||
file.managed: |
|||
- source: salt://sentry/sentry-web.service.jinja2 |
|||
- template: jinja |
|||
- user: root |
|||
- group: root |
|||
- mode: 644 |
|||
|
|||
/etc/systemd/system/sentry-worker.service: |
|||
file.managed: |
|||
- source: salt://sentry/sentry-worker.service.jinja2 |
|||
- template: jinja |
|||
- user: root |
|||
- group: root |
|||
- mode: 644 |
|||
|
|||
/etc/systemd/system/sentry-cron.service: |
|||
file.managed: |
|||
- source: salt://sentry/sentry-cron.service.jinja2 |
|||
- template: jinja |
|||
- user: root |
|||
- group: root |
|||
- mode: 644 |
|||
|
|||
sentry-web: |
|||
service.running: |
|||
- enable: True |
|||
|
|||
sentry-worker: |
|||
service.running: |
|||
- enable: True |
|||
|
|||
sentry-cron: |
|||
service.running: |
|||
- enable: True |
|||
|
|||
sentry-cleanup: |
|||
cron.present: |
|||
- name: {{ sentry_bin_dir }}/sentry cleanup --days=30 |
|||
- hour: 4 |
|||
- minute: 0 |
|||
|
|||
/etc/nginx/sites-available/sentry.conf: |
|||
file.managed: |
|||
- source: salt://sentry/sentry.conf.jinja2 |
|||
- template: jinja |
|||
- user: root |
|||
- group: root |
|||
- mode: 644 |
|||
- makedirs: True |
|||
|
|||
/etc/nginx/sites-enabled/sentry.conf: |
|||
file.symlink: |
|||
- target: /etc/nginx/sites-available/sentry.conf |
|||
- makedirs: True |
|||
- user: root |
|||
- group: root |
|||
- mode: 644 |
@ -0,0 +1,15 @@ |
|||
{% from 'sentry/common.jinja2' import sentry_bin_dir, sentry_cfg_dir, sentry_venv_dir -%} |
|||
[Unit] |
|||
Description=Sentry Beat Service |
|||
After=network.target |
|||
|
|||
[Service] |
|||
Type=simple |
|||
User=sentry |
|||
Group=sentry |
|||
WorkingDirectory={{ sentry_venv_dir }} |
|||
Environment=SENTRY_CONF={{ sentry_cfg_dir }} |
|||
ExecStart={{ sentry_bin_dir }}/sentry run cron |
|||
|
|||
[Install] |
|||
WantedBy=multi-user.target |
@ -0,0 +1,17 @@ |
|||
{% from 'sentry/common.jinja2' import sentry_bin_dir, sentry_cfg_dir, sentry_venv_dir -%} |
|||
[Unit] |
|||
Description=Sentry Main Service |
|||
After=network.target |
|||
Requires=sentry-worker.service |
|||
Requires=sentry-cron.service |
|||
|
|||
[Service] |
|||
Type=simple |
|||
User=sentry |
|||
Group=sentry |
|||
WorkingDirectory={{ sentry_venv_dir }} |
|||
Environment=SENTRY_CONF={{ sentry_cfg_dir }} |
|||
ExecStart={{ sentry_bin_dir }}/sentry run web |
|||
|
|||
[Install] |
|||
WantedBy=multi-user.target |
@ -0,0 +1,15 @@ |
|||
{% from 'sentry/common.jinja2' import sentry_bin_dir, sentry_cfg_dir, sentry_venv_dir -%} |
|||
[Unit] |
|||
Description=Sentry Background Worker |
|||
After=network.target |
|||
|
|||
[Service] |
|||
Type=simple |
|||
User=sentry |
|||
Group=sentry |
|||
WorkingDirectory={{ sentry_venv_dir }} |
|||
Environment=SENTRY_CONF={{ sentry_cfg_dir }} |
|||
ExecStart={{ sentry_bin_dir }}/sentry run worker |
|||
|
|||
[Install] |
|||
WantedBy=multi-user.target |
@ -0,0 +1,21 @@ |
|||
server { |
|||
listen 443 ssl http2; |
|||
listen [::]:443 ssl http2; |
|||
|
|||
{% for ip in pillar['developer_ips'] %} |
|||
allow {{ ip }}; |
|||
{% endfor %} |
|||
deny all; |
|||
|
|||
add_header Strict-Transport-Security "max-age={{ pillar['hsts_max_age'] }}; includeSubDomains; preload" always; |
|||
|
|||
server_name {{ pillar['sentry_server_name'] }}; |
|||
|
|||
location / { |
|||
proxy_set_header Host $host; |
|||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
|||
proxy_set_header X-Forwarded-Proto $scheme; |
|||
proxy_redirect off; |
|||
proxy_pass http://localhost:9000; |
|||
} |
|||
} |
@ -0,0 +1,135 @@ |
|||
# This file is just Python, with a touch of Django which means |
|||
# you can inherit and tweak settings to your hearts content. |
|||
from sentry.conf.server import * |
|||
|
|||
import os.path |
|||
|
|||
CONF_ROOT = os.path.dirname(__file__) |
|||
|
|||
DATABASES = { |
|||
'default': { |
|||
'ENGINE': 'sentry.db.postgres', |
|||
'NAME': 'sentry', |
|||
'USER': 'sentry', |
|||
'PASSWORD': '', |
|||
'HOST': '127.0.0.1', |
|||
'PORT': '', |
|||
'AUTOCOMMIT': True, |
|||
'ATOMIC_REQUESTS': False, |
|||
} |
|||
} |
|||
|
|||
# You should not change this setting after your database has been created |
|||
# unless you have altered all schemas first |
|||
SENTRY_USE_BIG_INTS = True |
|||
|
|||
# If you're expecting any kind of real traffic on Sentry, we highly recommend |
|||
# configuring the CACHES and Redis settings |
|||
|
|||
########### |
|||
# General # |
|||
########### |
|||
|
|||
# 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 = False |
|||
|
|||
######### |
|||
# Cache # |
|||
######### |
|||
|
|||
# Sentry currently utilizes two separate mechanisms. While CACHES is not a |
|||
# requirement, it will optimize several high throughput patterns. |
|||
|
|||
# If you wish to use memcached, install the dependencies and adjust the config |
|||
# as shown: |
|||
# |
|||
# pip install python-memcached |
|||
# |
|||
# CACHES = { |
|||
# 'default': { |
|||
# 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache', |
|||
# 'LOCATION': ['127.0.0.1:11211'], |
|||
# } |
|||
# } |
|||
|
|||
# A primary cache is required for things such as processing events |
|||
SENTRY_CACHE = 'sentry.cache.redis.RedisCache' |
|||
|
|||
######### |
|||
# Queue # |
|||
######### |
|||
|
|||
# See https://docs.sentry.io/on-premise/server/queue/ for more |
|||
# information on configuring your queue broker and workers. Sentry relies |
|||
# on a Python framework called Celery to manage queues. |
|||
|
|||
BROKER_URL = 'redis://localhost:6379' |
|||
|
|||
############### |
|||
# Rate Limits # |
|||
############### |
|||
|
|||
# Rate limits apply to notification handlers and are enforced per-project |
|||
# automatically. |
|||
|
|||
SENTRY_RATELIMITER = 'sentry.ratelimits.redis.RedisRateLimiter' |
|||
|
|||
################## |
|||
# Update Buffers # |
|||
################## |
|||
|
|||
# Buffers (combined with queueing) act as an intermediate layer between the |
|||
# database and the storage API. They will greatly improve efficiency on large |
|||
# numbers of the same events being sent to the API in a short amount of time. |
|||
# (read: if you send any kind of real data to Sentry, you should enable buffers) |
|||
|
|||
SENTRY_BUFFER = 'sentry.buffer.redis.RedisBuffer' |
|||
|
|||
########## |
|||
# Quotas # |
|||
########## |
|||
|
|||
# Quotas allow you to rate limit individual projects or the Sentry install as |
|||
# a whole. |
|||
|
|||
SENTRY_QUOTAS = 'sentry.quotas.redis.RedisQuota' |
|||
|
|||
######## |
|||
# TSDB # |
|||
######## |
|||
|
|||
# The TSDB is used for building charts as well as making things like per-rate |
|||
# alerts possible. |
|||
|
|||
SENTRY_TSDB = 'sentry.tsdb.redis.RedisTSDB' |
|||
|
|||
########### |
|||
# Digests # |
|||
########### |
|||
|
|||
# The digest backend powers notification summaries. |
|||
|
|||
SENTRY_DIGESTS = 'sentry.digests.backends.redis.RedisBackend' |
|||
|
|||
############## |
|||
# Web Server # |
|||
############## |
|||
|
|||
# If you're using a reverse SSL proxy, you should enable the X-Forwarded-Proto |
|||
# header and uncomment the following settings |
|||
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') |
|||
SESSION_COOKIE_SECURE = True |
|||
CSRF_COOKIE_SECURE = True |
|||
|
|||
# If you're not hosting at the root of your web server, |
|||
# you need to uncomment and set it to the path where Sentry is hosted. |
|||
#FORCE_SCRIPT_NAME = '/sentry' |
|||
|
|||
SENTRY_WEB_HOST = '0.0.0.0' |
|||
SENTRY_WEB_PORT = 9000 |
|||
SENTRY_WEB_OPTIONS = { |
|||
# 'workers': 3, # the number of web workers |
|||
# 'protocol': 'uwsgi', # Enable uwsgi protocol instead of http |
|||
} |
@ -0,0 +1,42 @@ |
|||
{% from 'common.jinja2' import app_dir, app_username, python_version %} |
|||
|
|||
{% set site_icons_venv_dir = '/opt/venvs/site-icons-spriter' %} |
|||
{% set site_icons_data_dir = '/var/lib/site-icons-spriter' %} |
|||
|
|||
# Salt seems to use the deprecated pyvenv script, manual for now |
|||
site-icons-venv-setup: |
|||
cmd.run: |
|||
- name: /usr/local/pyenv/versions/{{ python_version }}/bin/python -m venv {{ site_icons_venv_dir }} |
|||
- creates: {{ site_icons_venv_dir }} |
|||
- require: |
|||
- pkg: python3-venv |
|||
- pyenv: {{ python_version }} |
|||
|
|||
site-icons-pip-installs: |
|||
cmd.run: |
|||
- name: {{ site_icons_venv_dir }}/bin/pip install glue |
|||
- unless: ls {{ site_icons_venv_dir }}/lib/python3.6/site-packages/glue |
|||
|
|||
site-icons-output-placeholder: |
|||
file.managed: |
|||
- name: {{ site_icons_data_dir }}/output/site-icons.css |
|||
- contents: '' |
|||
- allow_empty: True |
|||
- makedirs: True |
|||
- user: {{ app_username }} |
|||
- group: {{ app_username }} |
|||
- unless: ls {{ site_icons_data_dir }}/output/site-icons.css |
|||
|
|||
site-icons-input-folder: |
|||
file.directory: |
|||
- name: {{ site_icons_data_dir }}/site-icons |
|||
- user: {{ app_username }} |
|||
- group: {{ app_username }} |
|||
|
|||
/usr/local/bin/generate-site-icons: |
|||
file.managed: |
|||
- source: salt://scripts/generate-site-icons.sh.jinja2 |
|||
- template: jinja |
|||
- user: root |
|||
- group: root |
|||
- mode: 755 |
@ -0,0 +1,40 @@ |
|||
base: |
|||
'dev or prod': |
|||
- gunicorn |
|||
- nginx |
|||
- nginx.site-config |
|||
- postgresql |
|||
- postgresql.site-db |
|||
- postgresql.pgbouncer |
|||
- python |
|||
- redis |
|||
- redis.modules.rebloom |
|||
- redis.modules.redis-cell |
|||
- rabbitmq |
|||
- scripts |
|||
- cmark-gfm |
|||
- prometheus.exporters.node_exporter |
|||
- prometheus.exporters.postgres_exporter |
|||
- prometheus.exporters.redis_exporter |
|||
- consumers |
|||
- site-icons-spriter |
|||
- boussole |
|||
- webassets |
|||
- cronjobs |
|||
- final-setup # keep this state file last |
|||
'dev': |
|||
- postgresql.test-db |
|||
- self-signed-cert |
|||
- development |
|||
- prometheus |
|||
'prod': |
|||
- nginx.static-sites-config |
|||
- raven |
|||
'monitoring': |
|||
- nginx |
|||
- self-signed-cert |
|||
- postgresql |
|||
- redis |
|||
- sentry |
|||
- grafana |
|||
- prometheus |
@ -0,0 +1,12 @@ |
|||
{% from 'common.jinja2' import app_dir, bin_dir -%} |
|||
[Unit] |
|||
Description=Webassets - auto-compile JS files on change |
|||
|
|||
[Service] |
|||
WorkingDirectory={{ app_dir }} |
|||
ExecStart={{ bin_dir }}/webassets -c webassets.yaml watch |
|||
Restart=always |
|||
RestartSec=5 |
|||
|
|||
[Install] |
|||
WantedBy=multi-user.target |
@ -0,0 +1,17 @@ |
|||
{% from 'common.jinja2' import app_dir, bin_dir %} |
|||
|
|||
/etc/systemd/system/webassets.service: |
|||
file.managed: |
|||
- source: salt://webassets.service.jinja2 |
|||
- template: jinja |
|||
- user: root |
|||
- group: root |
|||
- mode: 644 |
|||
- require_in: |
|||
- service: webassets.service |
|||
|
|||
webassets.service: |
|||
service.running: |
|||
- enable: True |
|||
- require: |
|||
- pip: pip-installs |
@ -0,0 +1,38 @@ |
|||
[alembic] |
|||
script_location = alembic |
|||
sqlalchemy.url = postgresql+psycopg2://tildes:@/tildes |
|||
|
|||
# Logging configuration |
|||
[loggers] |
|||
keys = root,sqlalchemy,alembic |
|||
|
|||
[handlers] |
|||
keys = console |
|||
|
|||
[formatters] |
|||
keys = generic |
|||
|
|||
[logger_root] |
|||
level = WARN |
|||
handlers = console |
|||
qualname = |
|||
|
|||
[logger_sqlalchemy] |
|||
level = WARN |
|||
handlers = |
|||
qualname = sqlalchemy.engine |
|||
|
|||
[logger_alembic] |
|||
level = INFO |
|||
handlers = |
|||
qualname = alembic |
|||
|
|||
[handler_console] |
|||
class = StreamHandler |
|||
args = (sys.stderr,) |
|||
level = NOTSET |
|||
formatter = generic |
|||
|
|||
[formatter_generic] |
|||
format = %(levelname)-5.5s [%(name)s] %(message)s |
|||
datefmt = %H:%M:%S |
@ -0,0 +1,80 @@ |
|||
from __future__ import with_statement |
|||
from alembic import context |
|||
from sqlalchemy import engine_from_config, pool |
|||
from logging.config import fileConfig |
|||
|
|||
# this is the Alembic Config object, which provides |
|||
# access to the values within the .ini file in use. |
|||
config = context.config |
|||
|
|||
# Interpret the config file for Python logging. |
|||
# This line sets up loggers basically. |
|||
fileConfig(config.config_file_name) |
|||
|
|||
# import all DatabaseModel subclasses here for autogenerate support |
|||
from tildes.models.comment import ( |
|||
Comment, |
|||
CommentNotification, |
|||
CommentTag, |
|||
CommentVote, |
|||
) |
|||
from tildes.models.group import Group, GroupSubscription |
|||
from tildes.models.log import Log |
|||
from tildes.models.message import MessageConversation, MessageReply |
|||
from tildes.models.topic import Topic, TopicVisit, TopicVote |
|||
from tildes.models.user import User, UserGroupSettings, UserInviteCode |
|||
|
|||
from tildes.models import DatabaseModel |
|||
target_metadata = DatabaseModel.metadata |
|||
|
|||
# other values from the config, defined by the needs of env.py, |
|||
# can be acquired: |
|||
# my_important_option = config.get_main_option("my_important_option") |
|||
# ... etc. |
|||
|
|||
|
|||
def run_migrations_offline(): |
|||
"""Run migrations in 'offline' mode. |
|||
|
|||
This configures the context with just a URL |
|||
and not an Engine, though an Engine is acceptable |
|||
here as well. By skipping the Engine creation |
|||
we don't even need a DBAPI to be available. |
|||
|
|||
Calls to context.execute() here emit the given string to the |
|||
script output. |
|||
|
|||
""" |
|||
url = config.get_main_option("sqlalchemy.url") |
|||
context.configure( |
|||
url=url, target_metadata=target_metadata, literal_binds=True) |
|||
|
|||
with context.begin_transaction(): |
|||
context.run_migrations() |
|||
|
|||
|
|||
def run_migrations_online(): |
|||
"""Run migrations in 'online' mode. |
|||
|
|||
In this scenario we need to create an Engine |
|||
and associate a connection with the context. |
|||
|
|||
""" |
|||
connectable = engine_from_config( |
|||
config.get_section(config.config_ini_section), |
|||
prefix='sqlalchemy.', |
|||
poolclass=pool.NullPool) |
|||
|
|||
with connectable.connect() as connection: |
|||
context.configure( |
|||
connection=connection, |
|||
target_metadata=target_metadata |
|||
) |
|||
|
|||
with context.begin_transaction(): |
|||
context.run_migrations() |
|||
|
|||
if context.is_offline_mode(): |
|||
run_migrations_offline() |
|||
else: |
|||
run_migrations_online() |
@ -0,0 +1,24 @@ |
|||
"""${message} |
|||
|
|||
Revision ID: ${up_revision} |
|||
Revises:${" " + down_revision if down_revision else "" | comma,n} |
|||
Create Date: ${create_date} |
|||
|
|||
""" |
|||
from alembic import op |
|||
import sqlalchemy as sa |
|||
${imports if imports else ""} |
|||
|
|||
# revision identifiers, used by Alembic. |
|||
revision = ${repr(up_revision)} |
|||
down_revision = ${repr(down_revision)} |
|||
branch_labels = ${repr(branch_labels)} |
|||
depends_on = ${repr(depends_on)} |
|||
|
|||
|
|||
def upgrade(): |
|||
${upgrades if upgrades else "pass"} |
|||
|
|||
|
|||
def downgrade(): |
|||
${downgrades if downgrades else "pass"} |
@ -0,0 +1,6 @@ |
|||
EXCLUDES: [] |
|||
LIBRARY_PATHS: [] |
|||
OUTPUT_STYLES: nested |
|||
SOURCES_PATH: scss/ |
|||
SOURCE_COMMENTS: false |
|||
TARGET_PATH: static/css/ |
@ -0,0 +1,80 @@ |
|||
"""Consumer that generates content_metadata for topics.""" |
|||
|
|||
from typing import Sequence |
|||
|
|||
from amqpy import Message |
|||
from html5lib import HTMLParser |
|||
import publicsuffix |
|||
|
|||
from tildes.lib.amqp import PgsqlQueueConsumer |
|||
from tildes.lib.string import simplify_string, truncate_string, word_count |
|||
from tildes.lib.url import get_domain_from_url |
|||
from tildes.models.topic import Topic |
|||
|
|||
|
|||
class TopicMetadataGenerator(PgsqlQueueConsumer): |
|||
"""Consumer that generates content_metadata for topics.""" |
|||
|
|||
def __init__(self, queue_name: str, routing_keys: Sequence[str]) -> None: |
|||
"""Initialize the consumer, including the public suffix list.""" |
|||
super().__init__(queue_name, routing_keys) |
|||
|
|||
# download the public suffix list (would be good to add caching here) |
|||
psl_file = publicsuffix.fetch() |
|||
self.public_suffix_list = publicsuffix.PublicSuffixList(psl_file) |
|||
|
|||
def run(self, msg: Message) -> None: |
|||
"""Process a delivered message.""" |
|||
topic = ( |
|||
self.db_session.query(Topic) |
|||
.filter_by(topic_id=msg.body['topic_id']) |
|||
.one() |
|||
) |
|||
|
|||
if topic.is_text_type: |
|||
self._generate_text_metadata(topic) |
|||
elif topic.is_link_type: |
|||
self._generate_link_metadata(topic) |
|||
|
|||
@staticmethod |
|||
def _generate_text_metadata(topic: Topic) -> None: |
|||
"""Generate metadata for a text topic (word count and excerpt).""" |
|||
html_tree = HTMLParser().parseFragment(topic.rendered_html) |
|||
|
|||
# extract the text from all of the HTML elements |
|||
extracted_text = ''.join( |
|||
[element_text for element_text in html_tree.itertext()]) |
|||
|
|||
# sanitize unicode, remove leading/trailing whitespace, etc. |
|||
extracted_text = simplify_string(extracted_text) |
|||
|
|||
# create a short excerpt by truncating the simplified string |
|||
excerpt = truncate_string( |
|||
extracted_text, |
|||
length=200, |
|||
truncate_at_chars=' ', |
|||
) |
|||
|
|||
topic.content_metadata = { |
|||
'word_count': word_count(extracted_text), |
|||
'excerpt': excerpt, |
|||
} |
|||
|
|||
def _generate_link_metadata(self, topic: Topic) -> None: |
|||
"""Generate metadata for a link topic (domain).""" |
|||
if not topic.link: |
|||
return |
|||
|
|||
parsed_domain = get_domain_from_url(topic.link) |
|||
domain = self.public_suffix_list.get_public_suffix(parsed_domain) |
|||
|
|||
topic.content_metadata = { |
|||
'domain': domain, |
|||
} |
|||
|
|||
|
|||
if __name__ == '__main__': |
|||
TopicMetadataGenerator( |
|||
queue_name='topic_metadata_generator.q', |
|||
routing_keys=['topic.created', 'topic.edited'], |
|||
).consume_queue() |
@ -0,0 +1,49 @@ |
|||
[DEFAULT] |
|||
# This setting is used to force the Pyramid app to generate urls using this |
|||
# port. This is necessary when using Vagrant for development so that the urls |
|||
# will include the correct port that's being forwarded from the host to the |
|||
# Vagrant box. This setting's value should match the port defined in the |
|||
# Vagrantfile that's being forwarded to port 443 on the guest. |
|||
# If not using Vagrant, this setting should probably be removed. |
|||
prefixmiddleware_force_port = 4443 |
|||
|
|||
[app:main] |
|||
use = egg:tildes |
|||
|
|||
pyramid.includes = pyramid_debugtoolbar |
|||
|
|||
pyramid.reload_templates = true |
|||
|
|||
redis.unix_socket_path = /run/redis/socket |
|||
|
|||
# Requests from the host machine through Vagrant will have their IP as |
|||
# 10.0.2.2 (which is an alias for the loopback interface) so we need |
|||
# to enable the debugtoolbar for that IP as well. |
|||
debugtoolbar.hosts = 127.0.0.1 ::1 10.0.2.2 |
|||
|
|||
# Exclude the metrics page from the debug toolbar, since Prometheus scrapes |
|||
# it constantly and we don't need to see that in the list of requests |
|||
debugtoolbar.exclude_prefixes = /metrics |
|||
|
|||
redis.sessions.secret = completely_insecure_secret |
|||
redis.sessions.unix_socket_path = %(redis.unix_socket_path)s |
|||
redis.sessions.prefix = session: |
|||
redis.sessions.cookie_secure = true |
|||
|
|||
# Set session timeout to 10 mins by default, we'll extend it when people log in |
|||
redis.sessions.timeout = 600 |
|||
|
|||
sqlalchemy.url = postgresql+psycopg2://tildes:@:6432/tildes |
|||
|
|||
webassets.auto_build = false |
|||
webassets.base_dir = %(here)s/static |
|||
webassets.base_url = / |
|||
webassets.cache = false |
|||
webassets.manifest = json |
|||
|
|||
[server:main] |
|||
use = egg:gunicorn#main |
|||
bind = unix:/run/gunicorn/socket |
|||
workers = 1 |
|||
pidfile = /run/gunicorn/pid |
|||
reload = true |
@ -0,0 +1,14 @@ |
|||
"""Configuration file for gunicorn.""" |
|||
|
|||
from prometheus_client import multiprocess |
|||
|
|||
|
|||
def child_exit(server, worker): # type: ignore |
|||
"""Mark worker processes as dead for Prometheus when the worker exits. |
|||
|
|||
Note that this uses the child_exit hook instead of worker_exit so that |
|||
it's handled by the master process (and will still be called if a worker |
|||
crashes). |
|||
""" |
|||
# pylint: disable=unused-argument |
|||
multiprocess.mark_process_dead(worker.pid) |
@ -0,0 +1,4 @@ |
|||
[mypy] |
|||
mypy_path = /opt/tildes/stubs/ |
|||
disallow_untyped_defs = true |
|||
ignore_missing_imports = true |
@ -0,0 +1,37 @@ |
|||
[DEFAULT] |
|||
|
|||
[app:main] |
|||
use = egg:tildes |
|||
|
|||
redis.unix_socket_path = /run/redis/socket |
|||
|
|||
redis.sessions.secret = SomeReallyLongSecret |
|||
redis.sessions.unix_socket_path = %(redis.unix_socket_path)s |
|||
redis.sessions.prefix = session: |
|||
redis.sessions.cookie_secure = true |
|||
redis.sessions.cookie_max_age = 31536000 |
|||
|
|||
# disable the python timeout management in pyramid-session-redis |
|||
redis.sessions.python_expires = false |
|||
redis.sessions.timeout_trigger = 0 |
|||
|
|||
# set session timeout to 1 hour by default, we'll extend it when people log in |
|||
redis.sessions.timeout = 3600 |
|||
|
|||
sqlalchemy.url = postgresql+psycopg2://tildes:@:6432/tildes |
|||
|
|||
stripe_api_key = sk_live_ActualKeyShouldGoHere |
|||
|
|||
tildes.welcome_message_sender = Deimos |
|||
|
|||
webassets.auto_build = false |
|||
webassets.base_dir = %(here)s/static |
|||
webassets.base_url = / |
|||
webassets.cache = false |
|||
webassets.manifest = json |
|||
|
|||
[server:main] |
|||
use = egg:gunicorn#main |
|||
bind = unix:/run/gunicorn/socket |
|||
workers = 8 |
|||
pidfile = /run/gunicorn/pid |
@ -0,0 +1,54 @@ |
|||
[pylama] |
|||
linters = mccabe,pycodestyle,pydocstyle,pyflakes,pylint |
|||
skip = alembic/* |
|||
|
|||
# ignored checks: |
|||
# - D203 - pydocstyle has two mutually exclusive checks (D203/D211) |
|||
# for whether a class docstring should have a blank line before |
|||
# it or not. I don't want a blank line, so D203 is disabled. |
|||
# - D213 - another pair of mutually exclusive pydocstyle checks, this |
|||
# time for whether a multi-line docstring's summary line should be |
|||
# on the first or second line. I want it to be on the first line, |
|||
# so D213 needs to be disabled. |
|||
ignore = D203,D213 |
|||
|
|||
[pylama:pylint] |
|||
enable = all |
|||
|
|||
# disabled pylint checks: |
|||
# - missing-docstring (already reported by pydocstyle) |
|||
# - too-few-public-methods (more annoying than helpful, especially early on) |
|||
# - too-many-instance-attributes (overly-picky when models need many) |
|||
# - locally-disabled (don't need a warning about things I disable) |
|||
# - locally-enabled (or when checks are (re-)enabled) |
|||
# - suppressed-message (...a different message when I disable one?) |
|||
disable = |
|||
missing-docstring, |
|||
too-few-public-methods, |
|||
too-many-instance-attributes, |
|||
locally-disabled, |
|||
locally-enabled, |
|||
suppressed-message |
|||
|
|||
# The APIv0 and venusian.AttachInfo classes need to be ignored because pylint |
|||
# can't recognize dynamically-added methods/attrs, so all of the functions in |
|||
# cornice.Service like .get(), .post(), etc. cause errors. |
|||
ignored-classes = APIv0, venusian.AttachInfo |
|||
|
|||
[pylama:tildes/schemas/*] |
|||
# ignored checks for schemas specifically: |
|||
# - R0201 - method could be a function (for @pre_load-type methods) |
|||
ignore = R0201 |
|||
|
|||
[pylama:tests/*] |
|||
# ignored checks for tests specifically: |
|||
# - D100 - missing module-level docstrings |
|||
# - C0103 - invalid function names (tests often have very long ones) |
|||
# - W0212 - access to protected member (useful/necessary for tests sometimes) |
|||
# - W0621 - redefining name from outer scope (that's how pytest fixtures work) |
|||
# - E1101 - <something> has no member (mocks add members this can't detect) |
|||
ignore = D100,C0103,W0212,W0621,E1101 |
|||
|
|||
[pylama:*/__init__.py] |
|||
# ignore "imported but unused" inside __init__.py files |
|||
ignore = W0611 |
@ -0,0 +1,3 @@ |
|||
[pytest] |
|||
testpaths = tests |
|||
addopts = -p no:cacheprovider |
@ -0,0 +1,38 @@ |
|||
ago |
|||
alembic |
|||
amqpy |
|||
argon2_cffi |
|||
astroid==1.5.3 # pylama has issues with pylint 1.8.1 |
|||
bleach |
|||
boussole |
|||
click==5.1 # boussole needs < 6.0 |
|||
cornice |
|||
freezegun |
|||
gunicorn |
|||
html5lib |
|||
ipython |
|||
mypy |
|||
mypy-extensions |
|||
prometheus-client |
|||
psycopg2 |
|||
publicsuffix2 |
|||
pydocstyle |
|||
pylama |
|||
pylama-pylint |
|||
pylint==1.7.5 # pylama has issues with 1.8.1 |
|||
pyramid |
|||
pyramid-debugtoolbar |
|||
pyramid-ipython |
|||
pyramid-jinja2 |
|||
pyramid-session-redis |
|||
pyramid-tm |
|||
pyramid-webassets |
|||
pytest |
|||
pytest-mock |
|||
SQLAlchemy |
|||
SQLAlchemy-Utils |
|||
stripe |
|||
testing.redis |
|||
webargs |
|||
webtest |
|||
zope.sqlalchemy |
@ -0,0 +1,105 @@ |
|||
ago==0.0.92 |
|||
alembic==1.0.0 |
|||
amqpy==0.13.1 |
|||
argh==0.26.2 |
|||
argon2-cffi==18.1.0 |
|||
astroid==1.5.3 |
|||
atomicwrites==1.1.5 |
|||
attrs==18.1.0 |
|||
backcall==0.1.0 |
|||
beautifulsoup4==4.6.0 |
|||
bleach==2.1.3 |
|||
boussole==1.2.3 |
|||
certifi==2018.4.16 |
|||
cffi==1.11.5 |
|||
chardet==3.0.4 |
|||
click==5.1 |
|||
colorama==0.3.9 |
|||
colorlog==3.1.4 |
|||
cornice==3.4.0 |
|||
decorator==4.3.0 |
|||
freezegun==0.3.10 |
|||
gunicorn==19.9.0 |
|||
html5lib==1.0.1 |
|||
hupper==1.3 |
|||
idna==2.7 |
|||
ipython==6.4.0 |
|||
ipython-genutils==0.2.0 |
|||
isort==4.3.4 |
|||
jedi==0.12.1 |
|||
Jinja2==2.10 |
|||
lazy-object-proxy==1.3.1 |
|||
libsass==0.14.5 |
|||
Mako==1.0.7 |
|||
MarkupSafe==1.0 |
|||
marshmallow==2.15.3 |
|||
mccabe==0.6.1 |
|||
more-itertools==4.2.0 |
|||
mypy==0.620 |
|||
mypy-extensions==0.3.0 |
|||
parso==0.3.1 |
|||
PasteDeploy==1.5.2 |
|||
pathtools==0.1.2 |
|||
pexpect==4.6.0 |
|||
pickleshare==0.7.4 |
|||
plaster==1.0 |
|||
plaster-pastedeploy==0.6 |
|||
pluggy==0.6.0 |
|||
prometheus-client==0.3.0 |
|||
prompt-toolkit==1.0.15 |
|||
psycopg2==2.7.5 |
|||
ptyprocess==0.6.0 |
|||
publicsuffix2==2.20160818 |
|||
py==1.5.4 |
|||
pyaml==17.12.1 |
|||
pycodestyle==2.4.0 |
|||
pycparser==2.18 |
|||
pydocstyle==2.1.1 |
|||
pyflakes==2.0.0 |
|||
Pygments==2.2.0 |
|||
pylama==7.4.3 |
|||
pylama-pylint==3.0.1 |
|||
pylint==1.7.5 |
|||
pyramid==1.9.2 |
|||
pyramid-debugtoolbar==4.4 |
|||
pyramid-ipython==0.2 |
|||
pyramid-jinja2==2.7 |
|||
pyramid-mako==1.0.2 |
|||
pyramid-session-redis==1.4.1 |
|||
pyramid-tm==2.2 |
|||
pyramid-webassets==0.9 |
|||
pytest==3.6.3 |
|||
pytest-mock==1.10.0 |
|||
python-dateutil==2.7.3 |
|||
python-editor==1.0.3 |
|||
PyYAML==3.13 |
|||
redis==2.10.6 |
|||
repoze.lru==0.7 |
|||
requests==2.19.1 |
|||
simplegeneric==0.8.1 |
|||
simplejson==3.16.0 |
|||
six==1.11.0 |
|||
snowballstemmer==1.2.1 |
|||
SQLAlchemy==1.2.10 |
|||
SQLAlchemy-Utils==0.33.3 |
|||
stripe==2.0.1 |
|||
testing.common.database==2.0.3 |
|||
testing.redis==1.1.1 |
|||
traitlets==4.3.2 |
|||
transaction==2.2.1 |
|||
translationstring==1.3 |
|||
typed-ast==1.1.0 |
|||
urllib3==1.23 |
|||
venusian==1.1.0 |
|||
waitress==1.1.0 |
|||
watchdog==0.8.3 |
|||
wcwidth==0.1.7 |
|||
webargs==4.0.0 |
|||
webassets==0.12.1 |
|||
webencodings==0.5.1 |
|||
WebOb==1.8.2 |
|||
WebTest==2.0.30 |
|||
wrapt==1.10.11 |
|||
zope.deprecation==4.3.0 |
|||
zope.interface==4.5.0 |
|||
zope.sqlalchemy==1.0 |
@ -0,0 +1 @@ |
|||
"""Contains standalone scripts that exist outside the app.""" |
@ -0,0 +1,177 @@ |
|||
"""Command-line tools for managing a breached-passwords bloom filter. |
|||
|
|||
This tool will help with creating and updating a bloom filter in Redis (using |
|||
ReBloom: https://github.com/RedisLabsModules/rebloom) to hold hashes for |
|||
passwords that have been revealed through data breaches (to prevent users from |
|||
using these passwords here). The dumps are likely primarily sourced from Troy |
|||
Hunt's "Pwned Passwords" files: |
|||
https://haveibeenpwned.com/Passwords |
|||
|
|||
Specifically, the commands in this tool allow building the bloom filter |
|||
somewhere else, then the RDB file can be transferred to the production server. |
|||
Note that it is expected that a separate redis server instance is running |
|||
solely for holding this bloom filter. Replacing the RDB file will result in all |
|||
other keys being lost. |
|||
|
|||
Expected usage of this tool should look something like: |
|||
|
|||
On the machine building the bloom filter: |
|||
python breached_passwords.py init --estimate 350000000 |
|||
python breached_passwords.py addhashes pwned-passwords-1.0.txt |
|||
python breached_passwords.py addhashes pwned-passwords-update-1.txt |
|||
|
|||
Then the RDB file can simply be transferred to the production server, |
|||
overwriting any previous RDB file. |
|||
|
|||
""" |
|||
|
|||
import subprocess |
|||
from typing import Any |
|||
|
|||
import click |
|||
from redis import ResponseError, StrictRedis |
|||
|
|||
from tildes.lib.password import ( |
|||
BREACHED_PASSWORDS_BF_KEY, |
|||
BREACHED_PASSWORDS_REDIS_SOCKET, |
|||
) |
|||
|
|||
|
|||
REDIS = StrictRedis(unix_socket_path=BREACHED_PASSWORDS_REDIS_SOCKET) |
|||
|
|||
|
|||
def generate_redis_protocol(*elements: Any) -> str: |
|||
"""Generate a command in the Redis protocol from the specified elements. |
|||
|
|||
Based on the example Ruby code from |
|||
https://redis.io/topics/mass-insert#generating-redis-protocol |
|||
""" |
|||
command = f'*{len(elements)}\r\n' |
|||
|
|||
for element in elements: |
|||
element = str(element) |
|||
command += f'${len(element)}\r\n{element}\r\n' |
|||
|
|||
return command |
|||
|
|||
|
|||
@click.group() |
|||
def cli() -> None: |
|||
"""Create a functionality-less command group to attach subcommands to.""" |
|||
pass |
|||
|
|||
|
|||
def validate_init_error_rate(ctx: Any, param: Any, value: Any) -> float: |
|||
"""Validate the --error-rate arg for the init command.""" |
|||
# pylint: disable=unused-argument |
|||
if not 0 < value < 1: |
|||
raise click.BadParameter('error rate must be a float between 0 and 1') |
|||
|
|||
return value |
|||
|
|||
|
|||
@cli.command(help='Initialize a new empty bloom filter') |
|||
@click.option( |
|||
'--estimate', |
|||
required=True, |
|||
type=int, |
|||
help='Expected number of passwords that will be added', |
|||
) |
|||
@click.option( |
|||
'--error-rate', |
|||
default=0.01, |
|||
show_default=True, |
|||
help='Bloom filter desired false positive ratio', |
|||
callback=validate_init_error_rate, |
|||
) |
|||
@click.confirmation_option( |
|||
prompt='Are you sure you want to clear any existing bloom filter?', |
|||
) |
|||
def init(estimate: int, error_rate: float) -> None: |
|||
"""Initialize a new bloom filter (destroying any existing one). |
|||
|
|||
It generally shouldn't be necessary to re-init a new bloom filter very |
|||
often with this command, only if the previous one was created with too low |
|||
of an estimate for number of passwords, or to change to a different false |
|||
positive rate. For choosing an estimate value, according to the ReBloom |
|||
documentation: "Performance will begin to degrade after adding more items |
|||
than this number. The actual degradation will depend on how far the limit |
|||
has been exceeded. Performance will degrade linearly as the number of |
|||
entries grow exponentially." |
|||
""" |
|||
REDIS.delete(BREACHED_PASSWORDS_BF_KEY) |
|||
|
|||
# BF.RESERVE {key} {error_rate} {size} |
|||
REDIS.execute_command( |
|||
'BF.RESERVE', |
|||
BREACHED_PASSWORDS_BF_KEY, |
|||
error_rate, |
|||
estimate, |
|||
) |
|||
|
|||
click.echo( |
|||
'Initialized bloom filter with expected size of {:,} and false ' |
|||
'positive rate of {}%' |
|||
.format(estimate, error_rate * 100) |
|||
) |
|||
|
|||
|
|||
@cli.command(help='Add hashes from a file to the bloom filter') |
|||
@click.argument('filename', type=click.Path(exists=True, dir_okay=False)) |
|||
def addhashes(filename: str) -> None: |
|||
"""Add all hashes from a file to the bloom filter. |
|||
|
|||
This uses the method of generating commands in Redis protocol and feeding |
|||
them into an instance of `redis-cli --pipe`, as recommended in |
|||
https://redis.io/topics/mass-insert |
|||
""" |
|||
# make sure the key exists and is a bloom filter |
|||
try: |
|||
REDIS.execute_command('BF.DEBUG', BREACHED_PASSWORDS_BF_KEY) |
|||
except ResponseError: |
|||
click.echo('Bloom filter is not set up properly - run init first.') |
|||
raise click.Abort |
|||
|
|||
# call wc to count the number of lines in the file for the progress bar |
|||
click.echo('Determining hash count...') |
|||
result = subprocess.run(['wc', '-l', filename], stdout=subprocess.PIPE) |
|||
line_count = int(result.stdout.split(b' ')[0]) |
|||
|
|||
progress_bar: Any = click.progressbar(length=line_count) |
|||
update_interval = 100_000 |
|||
|
|||
click.echo('Adding {:,} hashes to bloom filter...'.format(line_count)) |
|||
|
|||
redis_pipe = subprocess.Popen( |
|||
['redis-cli', '-s', BREACHED_PASSWORDS_REDIS_SOCKET, '--pipe'], |
|||
stdin=subprocess.PIPE, |
|||
stdout=subprocess.DEVNULL, |
|||
encoding='utf-8', |
|||
) |
|||
|
|||
for count, line in enumerate(open(filename), start=1): |
|||
hashval = line.strip().lower() |
|||
|
|||
# the Pwned Passwords hash lists now have a frequency count for each |
|||
# hash, which is separated from the hash with a colon, so we need to |
|||
# handle that if it's present |
|||
hashval = hashval.split(':')[0] |
|||
|
|||
command = generate_redis_protocol( |
|||
'BF.ADD', BREACHED_PASSWORDS_BF_KEY, hashval) |
|||
redis_pipe.stdin.write(command) |
|||
|
|||
if count % update_interval == 0: |
|||
progress_bar.update(update_interval) |
|||
|
|||
# call SAVE to update the RDB file |
|||
REDIS.save() |
|||
|
|||
# manually finish the progress bar so it shows 100% and renders properly |
|||
progress_bar.finish() |
|||
progress_bar.render_progress() |
|||
progress_bar.render_finish() |
|||
|
|||
|
|||
if __name__ == '__main__': |
|||
cli() |
@ -0,0 +1,124 @@ |
|||
"""Script for cleaning up private/deleted data. |
|||
|
|||
Other things that should probably be added here eventually: |
|||
- Delete individual votes on comments/topics after voting has been closed |
|||
- Delete which users tagged comments after tagging has been closed |
|||
- Delete old used invite codes (30 days after used?) |
|||
""" |
|||
|
|||
from datetime import datetime, timedelta |
|||
import logging |
|||
|
|||
from sqlalchemy.orm.session import Session |
|||
|
|||
from tildes.lib.database import get_session_from_config |
|||
from tildes.models.comment import Comment |
|||
from tildes.models.log import Log |
|||
from tildes.models.topic import Topic, TopicVisit |
|||
|
|||
|
|||
# sensitive data older than this should be removed |
|||
RETENTION_PERIOD = timedelta(days=30) |
|||
|
|||
|
|||
def clean_all_data(config_path: str) -> None: |
|||
"""Clean all private/deleted data. |
|||
|
|||
This should generally be the only function called in most cases, and will |
|||
initiate the full cleanup process. |
|||
""" |
|||
db_session = get_session_from_config(config_path) |
|||
|
|||
cleaner = DataCleaner(db_session, RETENTION_PERIOD) |
|||
cleaner.clean_all() |
|||
|
|||
|
|||
class DataCleaner(): |
|||
"""Container class for all methods related to cleaning up old data.""" |
|||
|
|||
def __init__( |
|||
self, |
|||
db_session: Session, |
|||
retention_period: timedelta, |
|||
) -> None: |
|||
"""Create a new DataCleaner.""" |
|||
self.db_session = db_session |
|||
self.retention_cutoff = datetime.now() - retention_period |
|||
|
|||
def clean_all(self) -> None: |
|||
"""Call all the cleanup functions.""" |
|||
logging.info( |
|||
f'Cleaning up all data (retention cutoff {self.retention_cutoff})') |
|||
|
|||
self.delete_old_log_entries() |
|||
self.delete_old_topic_visits() |
|||
|
|||
self.clean_old_deleted_comments() |
|||
self.clean_old_deleted_topics() |
|||
|
|||
def delete_old_log_entries(self) -> None: |
|||
"""Delete all log entries older than the retention cutoff. |
|||
|
|||
Note that this will also delete all entries from the child tables that |
|||
inherit from Log (LogTopics, etc.). |
|||
""" |
|||
deleted = ( |
|||
self.db_session.query(Log) |
|||
.filter(Log.event_time <= self.retention_cutoff) |
|||
.delete(synchronize_session=False) |
|||
) |
|||
self.db_session.commit() |
|||
logging.info(f'Deleted {deleted} old log entries.') |
|||
|
|||
def delete_old_topic_visits(self) -> None: |
|||
"""Delete all topic visits older than the retention cutoff.""" |
|||
deleted = ( |
|||
self.db_session.query(TopicVisit) |
|||
.filter(TopicVisit.visit_time <= self.retention_cutoff) |
|||
.delete(synchronize_session=False) |
|||
) |
|||
self.db_session.commit() |
|||
logging.info(f'Deleted {deleted} old topic visits.') |
|||
|
|||
def clean_old_deleted_comments(self) -> None: |
|||
"""Clean the data of old deleted comments. |
|||
|
|||
Change the comment's author to the "unknown user" (id 0), and delete |
|||
its contents. |
|||
""" |
|||
updated = ( |
|||
self.db_session.query(Comment) |
|||
.filter( |
|||
Comment.deleted_time <= self.retention_cutoff) # type: ignore |
|||
.update({ |
|||
'user_id': 0, |
|||
'markdown': '', |
|||
'rendered_html': '', |
|||
}, synchronize_session=False) |
|||
) |
|||
self.db_session.commit() |
|||
logging.info(f'Cleaned {updated} old deleted comments.') |
|||
|
|||
def clean_old_deleted_topics(self) -> None: |
|||
"""Clean the data of old deleted topics. |
|||
|
|||
Change the topic's author to the "unknown user" (id 0), and delete its |
|||
title, contents, tags, and metadata. |
|||
""" |
|||
updated = ( |
|||
self.db_session.query(Topic) |
|||
.filter( |
|||
Topic.deleted_time <= self.retention_cutoff) # type: ignore |
|||
.update({ |
|||
'user_id': 0, |
|||
'title': '', |
|||
'topic_type': 'TEXT', |
|||
'markdown': None, |
|||
'rendered_html': None, |
|||
'link': None, |
|||
'content_metadata': None, |
|||
'_tags': [], |
|||
}, synchronize_session=False) |
|||
) |
|||
self.db_session.commit() |
|||
logging.info(f'Cleaned {updated} old deleted topics.') |
@ -0,0 +1,81 @@ |
|||
"""Script for doing the initial setup of database tables.""" |
|||
|
|||
import os |
|||
import subprocess |
|||
from typing import Optional |
|||
|
|||
from alembic import command |
|||
from alembic.config import Config |
|||
from sqlalchemy.engine import Connectable, Engine |
|||
|
|||
from tildes.lib.database import get_session_from_config |
|||
from tildes.models import DatabaseModel |
|||
from tildes.models.group import Group |
|||
from tildes.models.log import Log |
|||
from tildes.models.user import User |
|||
|
|||
|
|||
def initialize_db( |
|||
config_path: str, |
|||
alembic_config_path: Optional[str] = None, |
|||
) -> None: |
|||
"""Load the app config and create the database tables.""" |
|||
db_session = get_session_from_config(config_path) |
|||
engine = db_session.bind |
|||
|
|||
create_tables(engine) |
|||
|
|||
run_sql_scripts_in_dir('sql/init/', engine) |
|||
|
|||
# if an Alembic config file wasn't specified, assume it's alembic.ini in |
|||
# the same directory |
|||
if not alembic_config_path: |
|||
path = os.path.split(config_path)[0] |
|||
alembic_config_path = os.path.join(path, 'alembic.ini') |
|||
|
|||
# mark current Alembic revision in db so migrations start from this point |
|||
alembic_cfg = Config(alembic_config_path) |
|||
command.stamp(alembic_cfg, 'head') |
|||
|
|||
|
|||
def create_tables(connectable: Connectable) -> None: |
|||
"""Create the database tables.""" |
|||
# tables to skip (due to inheritance or other need to create manually) |
|||
excluded_tables = Log.INHERITED_TABLES |
|||
|
|||
tables = [ |
|||
table for table in DatabaseModel.metadata.tables.values() |
|||
if table.name not in excluded_tables |
|||
] |
|||
DatabaseModel.metadata.create_all(connectable, tables=tables) |
|||
|
|||
|
|||
def run_sql_scripts_in_dir(path: str, engine: Engine) -> None: |
|||
"""Run all sql scripts in a directory.""" |
|||
for root, _, files in os.walk(path): |
|||
sql_files = [ |
|||
filename for filename in files |
|||
if filename.endswith('.sql') |
|||
] |
|||
for sql_file in sql_files: |
|||
subprocess.call([ |
|||
'psql', |
|||
'-U', engine.url.username, |
|||
'-f', os.path.join(root, sql_file), |
|||
engine.url.database, |
|||
]) |
|||
|
|||
|
|||
def insert_dev_data(config_path: str) -> None: |
|||
"""Load the app config and insert some "starter" data for a dev version.""" |
|||
session = get_session_from_config(config_path) |
|||
|
|||
session.add_all([ |
|||
User('TestUser', 'password'), |
|||
Group( |
|||
'testing', |
|||
'An automatically created group to use for testing purposes', |
|||
), |
|||
]) |
|||
|
|||
session.commit() |
@ -0,0 +1,22 @@ |
|||
{% for r, ratio in ratios.items() %} |
|||
{% if ratio.ratio == 1.0 %} |
|||
.topic-icon { |
|||
background-image: url('/images/{{ ratio.sprite_path }}?{{ hash }}'); |
|||
background-size: 0 0; |
|||
} |
|||
{% else %} |
|||
@media screen and (min-device-pixel-ratio: {{ ratio.ratio }}), screen and (min-resolution: {{ ratio.ratio }}dppx) { |
|||
.topic-icon { |
|||
background-image: url('/images/{{ ratio.sprite_path }}?{{ hash }}'); |
|||
} |
|||
} |
|||
{% endif %} |
|||
{% endfor %} |
|||
|
|||
{% for image in images %} |
|||
.topic-icon-{{ image.label }} { |
|||
background-position: {{ image.x ~ ('px' if image.x) }} {{ image.y ~ ('px' if image.y) }}; |
|||
background-size: {{ width }}px {{ height }}px; |
|||
border: 0; |
|||
} |
|||
{% endfor %} |
Some files were not shown because too many files changed in this diff
Write
Preview
Loading…
Cancel
Save
Reference in new issue