Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kingfisher Process Docker app deploy #418

Merged
merged 86 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
dacae26
pelican: Add configuration for Pelican Docker apps
jpmckinney Mar 25, 2023
bc8c99f
kingfisher-process: Switch to Docker app
jpmckinney Mar 25, 2023
fd2bdd0
docs: PostgreSQL 12+ uses postgresql.conf instead of recovery.conf
jpmckinney May 25, 2023
5f99131
Merge branch 'main' into kingfisher-process-deploy
jpmckinney May 25, 2023
1951287
kingfisher: Upgrade to PostgreSQL 15
jpmckinney May 25, 2023
45dda4f
Merge branch 'main' into kingfisher-process-deploy
jpmckinney May 26, 2023
d763c32
Merge branch 'main' into kingfisher-process-deploy
jpmckinney May 26, 2023
bf60c34
kingfisher: Make updates for latest versions of Collect and Summarize
jpmckinney May 26, 2023
8ed6131
Merge branch 'main' into kingfisher-process-deploy
jpmckinney May 26, 2023
0e12b8a
Merge branch 'main' into kingfisher-process-deploy
jpmckinney May 26, 2023
2bf807c
kingfisher: Remove Process from rsyslog/logrotate and prevent Summari…
jpmckinney May 26, 2023
9ec9329
Merge branch 'main' into kingfisher-process-deploy
jpmckinney May 27, 2023
39e87b6
kingfisher: Remove process states and files or merge into summarize.
jpmckinney May 27, 2023
b0c57d2
Merge branch 'main' into kingfisher-process-deploy
jpmckinney May 27, 2023
696dd13
kingfisher: Rename roster entry from kingfisher-process to kingfisher…
jpmckinney May 27, 2023
8524f62
Merge branch 'main' into kingfisher-process-deploy
jpmckinney May 31, 2023
ac830b4
Merge main into kingfisher-process-deploy
jpmckinney Jun 1, 2023
a5b3c6b
feat: update to ocp23 server
Jun 7, 2023
91ae1df
docs: add kingfisher server specific steps
Jun 7, 2023
6b6426b
docs: reset firewall for docker
Jun 7, 2023
246dbd4
feat: update docker compose
Jun 7, 2023
e1b57ff
feat: update tinyproxy kingfisher ips
Jun 7, 2023
a003003
feat: add firewall_reset.sh
Jun 7, 2023
51341be
fix: .pgpass syntax error
Jun 7, 2023
881d303
docs: update ocp23 comments
Jun 7, 2023
9929eb6
chore: correct firewall_reset.sh formatting
Jun 7, 2023
6c822e5
docs: Tidy punctuation
jpmckinney Jun 7, 2023
6f55660
feat: variable command paths
Jun 8, 2023
5d05c92
feat: flush ipv6 nat table
Jun 8, 2023
fc3c452
refactor: prometheus names match salt roster
Jun 8, 2023
4656b76
Merge branch 'kingfisher-process-deploy' of github.com:open-contracti…
Jun 8, 2023
ba6171d
chore(style): Normalize include: indentation
jpmckinney Jun 8, 2023
1906a1b
python_apps: Make inclusion of uwsgi and apache conditional
jpmckinney Jun 8, 2023
945926c
Merge branch 'main' into kingfisher-process-deploy
jpmckinney Jun 8, 2023
ed83846
kingfisher: Fix Apache site name to match Docker Compose file
jpmckinney Jun 8, 2023
bc4b22f
chore(style): Update Jinja style guide to reduce if+for usage. Prefer…
jpmckinney Jun 8, 2023
9fca6f3
fix: correct docker-compose version
Jun 9, 2023
69b972a
fix: disable sensor monitoring
Jun 9, 2023
77e78a8
docs: Update commands for Compose V2 #369
jpmckinney Jun 9, 2023
e3af772
kingfisher: Use upgrade-jsonschema of kingfisher-collect, until ocp04…
jpmckinney Jun 9, 2023
ae3627a
postgres: Create schemas based on Pillar data
jpmckinney Jun 9, 2023
9045cc5
Merge main into kingfisher-process-deploy
jpmckinney Jun 9, 2023
f99ebc7
lib: Set remove_groups: False to not cause output on deployer group s…
jpmckinney Jun 9, 2023
a951196
docs: Update Hetzner URLs
jpmckinney Jun 10, 2023
273003d
docs(firewall): Update Hetzner instructions for updated interface
jpmckinney Jun 10, 2023
ad8b87b
kingfisher: Set PosgreSQL to public access for Docker connections
jpmckinney Jun 10, 2023
250f638
kingfisher-collect: Disable cron until jobs transferred from ocp04
jpmckinney Jun 10, 2023
8f677db
Merge main into kingfisher-process-deploy
jpmckinney Jun 10, 2023
4e3b670
kingfisher-collect: Re-enable cron
jpmckinney Jun 10, 2023
2c53f2d
docs(data-support): Fill in migration steps
jpmckinney Jun 10, 2023
c1520c8
kingfisher-collect: Allow authorized_keys for incremental user, to ea…
jpmckinney Jun 10, 2023
669fd10
pelican-backend: Fix owner of objects created by migrations. Change e…
jpmckinney Jun 10, 2023
26449d7
docs(data-support): Copy the incremental logs
jpmckinney Jun 10, 2023
67a80d9
docs(data-support): Add steps for Docker & apps
jpmckinney Jun 10, 2023
42c914f
docs(data-support): Remove incompleteness note
jpmckinney Jun 10, 2023
02417db
feat: disable running_procs test on docker server
Jun 12, 2023
6a2bd7d
feat: use aptkey location for rabbitmq repo
Jun 12, 2023
33e53f1
Merge branch 'kingfisher-process-deploy' of github.com:open-contracti…
Jun 12, 2023
1332186
feat: disable backups
Jun 12, 2023
737832a
fix: reference schema state
Jun 12, 2023
6956350
docs(data-support): Add a couple steps for a new replica server
jpmckinney Jun 12, 2023
7b3613e
docs(data-support): Split out instruction for dependent services
jpmckinney Jun 12, 2023
9b043dd
postgres: Add _sql_group and _sql_database suffixes to state
jpmckinney Jun 12, 2023
664ff85
feat: Revert changes to the replica server (ocp05 will remain online)
jpmckinney Jun 12, 2023
65d3f03
docs(data-support): Add step for replica server
jpmckinney Jun 12, 2023
6313ce7
chore: Use common order for file.managed keys
jpmckinney Jun 12, 2023
7c58fc3
postgres: Install postgresqltuner
jpmckinney Jun 12, 2023
c9dc617
kingfisher-main: Set nr_hugepages according to postgresqltuner
jpmckinney Jun 12, 2023
52861dc
rabbitmq: Add proxy for management interface. Fix proxy for pelican f…
jpmckinney Jun 13, 2023
62998ee
rabbitmq: Add logic for individual unprivileged users
jpmckinney Jun 13, 2023
2bf5a11
pelican-frontend: Fix htpasswd file name
jpmckinney Jun 13, 2023
8f9dac6
kingfisher: Add ripgrep for faster grepping of large JSON files
jpmckinney Jun 13, 2023
9180bc9
postgres: Move pgbadger to main SLS file #181
jpmckinney Jun 13, 2023
3baaa0e
kingfisher-summarize: Fix KINGFISHER_SUMMARIZE_DATABASE_URL to use th…
jpmckinney Jun 14, 2023
8384645
docs(kingfisher-summarize): Add "Summarize collections"
jpmckinney Jun 14, 2023
0bec835
docs(use/databases): Remove mention of replica
jpmckinney Jun 14, 2023
65e3729
docs(pelican): Add page for Pelican, and section for RabbitMQ
jpmckinney Jun 14, 2023
a0c2a9c
docs(bash): Add reminders to close tmux sessions
jpmckinney Jun 14, 2023
b82b289
docs(use/databases): Mention short psql command
jpmckinney Jun 14, 2023
ff01f59
docs(use/kingfisher-process): Document load, collectionstatus, delete…
jpmckinney Jun 14, 2023
fea872c
feat: stop firewall_reset.sh on error
Jun 14, 2023
0d12af7
feat: enable pgbackrest backups
Jun 14, 2023
274b2da
feat: remove kingfisher_common.sls
Jun 14, 2023
740e5f3
docs: Add notes for pgbackrest grep
jpmckinney Jun 14, 2023
f75bf6c
top: Remove kingfisher_common files from Pillar top
jpmckinney Jun 14, 2023
9572e14
docs: Add comments to explain directory permissions
jpmckinney Jun 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
r'^https://(?:account|dcc)\.godaddy\.com',
r'^https://(?:crm|redash)\.open-contracting\.org',
r'^https://(?:docs\.google\.com/(?:document|spreadsheets)/d|drive\.google\.com/drive/folders)/',
r'^https://(?:ocp-library\.herokuapp|robot\.your-server|us-east-1\.console\.aws\.amazon)\.com',
r'^https://(?:ocp-library\.herokuapp|robot\.hetzner|us-east-1\.console\.aws\.amazon)\.com',
r'^https://(?:postmaster|search)\.google\.com',
r'^https://app\.(dmarcanalyzer|usefathom)\.com',
r'^https://github\.com/open-contracting/[^/]+/issues/new',
Expand Down
14 changes: 5 additions & 9 deletions docs/deploy/create_server.rst
Original file line number Diff line number Diff line change
Expand Up @@ -281,19 +281,15 @@ Some IDs might fail (`#156 <https://github.com/open-contracting/deploy/issues/15
#. If the server runs a database like PostgreSQL (``pg_dump``), MySQL (``mysqldump``) or Elasticsearch, copy the database
#. If the server runs a web server like Apache or application server like uWSGI, optionally copy the log files

Django applications
Data support server
~~~~~~~~~~~~~~~~~~~

#. Copy the ``media`` directory and the ``db.sqlite3`` file from the app's directory
See :doc:`data-support`.

Kingfisher
~~~~~~~~~~

.. note::

Instructions are incomplete.
Django applications
~~~~~~~~~~~~~~~~~~~

#. Update the IP addresses in the ``pillar/tinyproxy.sls`` file, and deploy the ``docs`` service
#. Copy the ``media`` directory and the ``db.sqlite3`` file from the app's directory

OCDS documentation
~~~~~~~~~~~~~~~~~~
Expand Down
157 changes: 157 additions & 0 deletions docs/deploy/data-support.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
Data support tasks
==================

#. Notify RBC Group of the new domain name for the new PostgreSQL server
#. Add or update the [Redash data source](https://redash.open-contracting.org/data_sources) for the new PostgreSQL server

Create a data support replica server
------------------------------------

#. Update ``postgres.replica_ipv4`` (and ``postgres.replica_ipv6``, if applicable) in the ``pillar/kingfisher_main.sls`` file.

Create a data support main server
---------------------------------

#. Adjust reserved disk space to 1% for large disks:

.. code-block:: bash

tune2fs -m 1 /dev/md2

Dependent services
~~~~~~~~~~~~~~~~~~

#. Update the allowed IP addresses in the ``pillar/tinyproxy.sls`` file
#. Deploy the ``docs`` service, when ready

If applicable:

#. Update the allowed IP addresses and hostname in the ``pillar/kingfisher_replica.sls`` file
#. Deploy the ``kingfisher-replica`` service, when ready

Docker
~~~~~~

#. Check that ``docker.uid`` in the ``pillar/kingfisher_main.sls`` file matches the entry in the ``/etc/passwd`` file.

Docker apps
~~~~~~~~~~~

#. Run migrations for :doc:`Docker apps<docker>` as the ``deployer`` user:

.. code-block:: bash

su - deployer

cd /data/deploy/kingfisher-process/
docker compose run --rm web python manage.py migrate

cd /data/deploy/pelican-frontend/
docker compose run --rm web python manage.py migrate

#. :doc:`Pull new images and start new containers for each Docker app<docker>`.

Pelican backend
~~~~~~~~~~~~~~~

.. warning::

A cron job updates the ``exchange_rates`` table every 12 hours. Complete this step before the next run.

The initial migrations for Pelican backend are run by Salt.

#. Connect to the old server, and dump the ``exchange_rates`` table:

.. code-block:: bash

sudo -i -u postgres psql -c '\copy exchange_rates (valid_on, rates, created, modified) to stdout' pelican_backend > exchange_rates.csv

#. Copy the database dump to your local machine. For example:

.. code-block:: bash

rsync -avz root@ocp13.open-contracting.org:~/exchange_rates.csv .

#. Copy the database dump to the new server. For example:

.. code-block:: bash

rsync -avz exchange_rates.sql root@ocp23.open-contracting.org:~/

#. Populate the ``exchange_rates`` table:

.. code-block:: bash

psql -U pelican_backend -h localhost -c "\copy exchange_rates (valid_on, rates, created, modified) from 'exchange_rates.csv';" pelican_backend

Kingfisher Collect
~~~~~~~~~~~~~~~~~~

#. Connect to the new server, switch to the ``incremental`` user, generate an SSH key pair, and get the public SSH key:

.. code-block:: bash

su - incremental
ssh-keygen -t rsa -b 4096 -C "incremental"
cat ~/.ssh/id_rsa.pub

#. Add the public SSH key to the ``ssh.incremental`` list in the ``pillar/kingfisher_main.sls`` file:

.. code-block:: yaml

ssh:
incremental:
- ssh-rsa AAAB3N...

#. Change ``cron.present`` to ``cron.absent`` in the ``salt/kingfisher/collect/incremental.sls`` file.
#. :doc:`Deploy the old server and the new server<deploy>`.
#. Connect to the old server:

#. Switch to the ``incremental`` user:

.. code-block:: bash

su - incremental

#. Stop any processes started by the cron jobs.
#. Dump the ``kingfisher_collect`` database:

.. code-block:: bash

pg_dump -U kingfisher_collect -h localhost -f kingfisher_collect.sql kingfisher_collect

#. Connect to the new server:

#. Switch to the ``incremental`` user:

.. code-block:: bash

su - incremental

#. Copy the database dump from the old server. For example:

.. code-block:: bash

rsync -avz incremental@ocp04.open-contracting.org:~/kingfisher_collect.sql .

#. Load the database dump:

.. code-block:: bash

psql -U kingfisher_collect -h localhost -f kingfisher_collect.sql kingfisher_collect

#. Copy the ``data`` directory from the old server. For example:

.. code-block:: bash

rsync -avz incremental@ocp04.open-contracting.org:/home/incremental/data/ /home/incremental/data/

#. Copy the ``logs`` directory from the old server. For example:

.. code-block:: bash

rsync -avz incremental@ocp04.open-contracting.org:/home/incremental/logs/ /home/incremental/logs/

#. Remove the public SSH key from the ``ssh.incremental`` list in the ``pillar/kingfisher_main.sls`` file.
#. Change ``cron.absent`` to ``cron.present`` in the ``salt/kingfisher/collect/incremental.sls`` file.
#. :doc:`Deploy the new server<deploy>`.
2 changes: 1 addition & 1 deletion docs/deploy/deploy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ To `run a specific SLS ID <https://docs.saltproject.io/en/latest/ref/modules/all

.. code-block:: bash

./run.py --state-output=changes 'kingfisher-process' state.sls postgres,postgres.backup,kingfisher.collect.database,kingfisher.process.database
./run.py --state-output=changes 'kingfisher-main' state.sls postgres,postgres.backup

2. Check Salt output
--------------------
Expand Down
14 changes: 9 additions & 5 deletions docs/deploy/docker.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Docker tasks
============

.. note::

The commands assume Compose V2, which uses ``docker compose``. For Compose V1, use ``docker-compose`` (with hyphen).

Change to the application's directory, replacing ``APP``:

.. code-block:: bash
Expand All @@ -11,20 +15,20 @@ Change to the application's directory, replacing ``APP``:

.. code-block:: bash

docker-compose pull
docker-compose up -d
docker compose pull
docker compose up -d

Create a superuser:

.. code-block:: bash

docker-compose run --rm web python manage.py createsuperuser
docker compose run --rm web python manage.py createsuperuser

Migrate the database:

.. code-block:: bash

docker-compose run --rm web python manage.py migrate
docker compose run --rm web python manage.py migrate

.. note::

Expand All @@ -39,7 +43,7 @@ For example:

.. code-block:: bash

psql -c 'SET ROLE pelican_backend' -c "\copy exchange_rates (valid_on, rates, created, modified) from '/opt/pelican-backend/exchange_rates.csv' delimiter ',' csv header;" pelican_backend
psql -U pelican_backend -h localhost -c "\copy exchange_rates (valid_on, rates, created, modified) from 'exchange_rates.csv';" pelican_backend

Check that the ID sequence is correct:

Expand Down
2 changes: 1 addition & 1 deletion docs/deploy/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Deployment Guides
docker.rst
docs.rst
prometheus.rst
kingfisher.rst
data-support.rst
redash.rst
redmine.rst

Expand Down
86 changes: 0 additions & 86 deletions docs/deploy/kingfisher.rst

This file was deleted.

7 changes: 1 addition & 6 deletions docs/deploy/redash.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Load the new server's database

.. code-block:: bash

sudo -u postgres psql -f redash.sql redash
sudo -i -u postgres psql -f redash.sql redash

#. Change to the non-root user and Redash directory:

Expand Down Expand Up @@ -129,8 +129,3 @@ Upgrade the Redash service
docker-compose up -d

#. Check that the new version is running by viewing the `System Status <https://redash.open-contracting.org/admin/status>`__ page and reading the *Version*. You may need to log in to Redash to access this page.

Troubleshoot
~~~~~~~~~~~~

To troubleshoot ``docker-compose`` commands, add the ``--verbose`` option.
4 changes: 1 addition & 3 deletions docs/deploy/setup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,10 @@ Ensure you have the correct versions of dependencies. Activate your virtual envi

.. code-block:: bash

for i in root ocdskfp; do echo $i; su $i -c "tmux ls"; done
for i in root $(ls -1 /home); do echo $i; su $i -c "tmux ls"; done

#. If the ``postgres`` service would be restarted by the deployment (for example, due to a configuration change or a package upgrade), check if any :ref:`long-running queries<pg-stat-activity>` are running. If there are queries with a ``state`` of ``active`` and a ``time`` greater than an hour, don't deploy without the consent of the data support managers, who should be identified by the ``usename``, ``client_addr`` or comment at the start of ``query``.

If you must deploy while spiders are running, see how to :ref:`deploy Kingfisher Process without losing Scrapy requests<deploy-kingfisher-process>`.

4. Get deploy token
~~~~~~~~~~~~~~~~~~~

Expand Down
4 changes: 2 additions & 2 deletions docs/develop/get_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ You must first have access to three private repositories. Contact an owner of th

.. tip::

To generate new SSH keys (if they do not already exist):
To generate an SSH key pair (if they do not already exist):

.. code-block:: bash

Expand Down Expand Up @@ -88,6 +88,6 @@ This overwrites the files:

On macOS, you might need to move ``Saltfile`` to ``~/.salt/Saltfile``.

This script assumes your SSH keys are ``~/.ssh/id_rsa.pub`` and ``~/.ssh/id_rsa``.
This script assumes your SSH key pair is ``~/.ssh/id_rsa.pub`` and ``~/.ssh/id_rsa``.

You're now ready to :doc:`../deploy/deploy`.
Loading