Skip to content

Commit c872f2d

Browse files
ticoombsdessalines
andauthored
feat: v1.5.0 (#237)
* chore: postgres v16 - pictrs latest * fix: compose v2 * feat: nginx cache * feat: nginx cache support * chore: add warning about the need to ensure a matching SHM * feat: parametise postgres shared memory * fix: parametise shm * feat: autoexplain * feat: dedicated lemmy_web_port * chore: example of lemmy_web_port * chore: show the newer uri for database connections * fix: quote it * chore: move all upgrading docs to a specific file as the readme should look c l e a n * fix: .md * Create UPGRADING.md * fix: prettier * chore: update picrts to latest * Update README.md * Update hosts * Update vars.yml * Update lemmy.yml * Update config.hjson * Fixing prettier. * Fixing prettier 2. * Cleaning up upgrade instructions. * Some typos. * fix: override cache key to ensure json is not returned * fix: docker pictrs defaults * feat: 0.19.4 * fix: also update almalinux playbook * fix: re-add tags --------- Co-authored-by: Dessalines <[email protected]> Co-authored-by: Dessalines <[email protected]>
1 parent 8c5337f commit c872f2d

11 files changed

+195
-125
lines changed

README.md

+4-100
Original file line numberDiff line numberDiff line change
@@ -89,107 +89,11 @@ If you wish to see another distribution on the list, please test on the latest c
8989

9090
## Upgrading
9191

92-
Since version `1.1.0` we no longer default to using `main` but use tags to make sure deployments are versioned.
93-
With every new release all migration steps shall be written below so make sure you check out the [Lemmy Releases Changelog](https://github.com/LemmyNet/lemmy/blob/main/RELEASES.md) to see if there are any config changes with the releases since your last read.
94-
95-
### Upgrading to 1.4.0 (Lemmy 0.19.3 & Pict-rs 0.5.4)
96-
97-
This is a semi-major release which upgrades pict-rs to 0.5 which has support for postgres as a backend. This configuration is **not supported** by lemmy-ansible for the moment.
98-
99-
#### Steps
100-
101-
- `git pull && git checkout 1.4.0`
102-
- Read [Pictrs' Configuration Changes](https://git.asonix.dog/asonix/pict-rs/#configuration-updates)
103-
- Amend your `vars.yml` file to respect the new changes
104-
- Optional: Add: `PICTRS__UPGRADE__CONCURRENCY` with a value between 32 and 512 depending on how much RAM/CPU you want to dedicate to the upgrade process. A value of 32 used about 2.5GB of RAM for the migration.
105-
- Optional: Curl `/internal/prepare_upgrade` to minimise downtime while upgrading. See [the instructions below](https://github.com/LemmyNet/lemmy-ansible#update-your-pict-rs-sled-database-optional) or the official documentation [here](https://git.asonix.dog/asonix/pict-rs/releases#user-content-upgrade-preparation-endpoint)
106-
- Run your regular deployment. Example: `ansible-playbook -i inventory/hosts lemmy.yml --become`
107-
108-
### Upgrading to 1.3.1 (Lemmy 0.19.1)
109-
110-
This is a very minor release but fixes issues relating to federation as part of the Lemmy update.
111-
112-
#### Steps
113-
114-
- `git pull && git checkout 1.3.1`
115-
- Run your regular deployment. Example: `ansible-playbook -i inventory/hosts lemmy.yml --become`
116-
117-
### Upgrading to 1.3.0 (Lemmy 0.19.0 & Pict-rs 0.4.7)
118-
119-
This is a major change and has required reading! tl;dr
120-
121-
- Lemmy has been upgraded to 0.19.0
122-
- pict-rs has been upgraded to 0.4.7
123-
- pict-rs has not been integrated with postgres yet
124-
- "Optional Modules" are now available to be added to your lemmy install as provided by the community.
125-
- The first being pictrs-safety
126-
127-
#### Steps
128-
129-
- Prepare to have downtime as the database needs to perform migrations!
130-
- Run `git pull && git checkout 1.3.0`
131-
- Run your regular deployment. Example: `ansible-playbook -i inventory/hosts lemmy.yml --become`
132-
- Lemmy will now be down! In testing this takes from 20 to 60 minutes.
133-
- If you are bored you can ssh into your server, and check the logs on postgres for updates
134-
- `docker compose logs -f postgres` while ssh'd and in your Lemmy directory
135-
136-
#### Update your pict-rs sled-database (Optional)
137-
138-
If you are happy for pict-rs to be down _for a while_ ~go straight to our `1.3.1` git tag which updates pictrs to 0.5.0~. Otherwise keep reading.
139-
Starting with 0.5.0 your database will automatically upgrade to the latest version, which will cause downtime for your users.
140-
As such there is an intermediary step where you can upgrade your database in the background to prepare for 0.5 (Reference documentation)[https://git.asonix.dog/asonix/pict-rs/releases#user-content-upgrade-preparation-endpoint]. This ensure no-one is caught out by unforseen downtime of multiple services.
141-
142-
Once you have deployed lemmy-ansible `1.3.0` tag, please continue (if you want):
92+
Please see the dedicated [UPGRADING](UPGRADING.md) document for all upgrade processess
14393

144-
- Take note of what your pict-rs API Key is under `vars.yml`
145-
- Take note of what your docker network name is. (It's normally the domain without any extra characters)
146-
- You should be able to find it via: `docker network ls | grep _default` if in doubt.
147-
- Run the following command replacing `api-key` with the pict-rs api key, & `youdomain` with the network name.
148-
- `docker run --network yourdomain_default --rm curlimages/curl:8.5.0 --silent -XPOST -H'X-Api-Token: api-key' 'http://pictrs:8080/internal/prepare_upgrade'`
149-
- This will start the background process updating your database from 0.4 to 0.5 compatible.
150-
151-
This is only Optional, and takes a shorter amount of time than the Lemmy database upgrade, but on huge installations it may take a lot longer.
152-
153-
#### Optional Module(s)
154-
155-
Our first optional module is [pictrs-safety](https://github.com/db0/pictrs-safety). See the repo linked for more information, especially for integration with pictrs (which is what it is for) Thanks to @db0 for their contribution.
156-
See the `pictrs_safety_env_vars` under `examples/vars.yml` for relevant options (and the two password variables)
157-
To enable this module to be used you must ADD `pictrs_safety: true` to your `vars.yml`.
158-
159-
### Upgrading to 1.2.1 (Lemmy 0.18.5)
160-
161-
This is a minor change which fixes the issue with the Postgres container not using the `customPostgres.conf` file.
162-
163-
#### Steps
164-
165-
- Please regenerate your `customPostgres.conf` from `examples/customPostgres.conf`
166-
- **OR**
167-
- Add the following block to your current customPostgres file.
168-
169-
```
170-
# Listen beyond localhost
171-
listen_addresses = '*'
172-
```
173-
174-
### Upgrading to 1.2.0 (Lemmy 0.18.5)
175-
176-
Major changes:
177-
178-
- All variables are not under a singular file so you will not need to modify anything: `inventory/host_vars/{{ domain }}/vars.yml`
179-
- `--become` is now optional instead of forced on
180-
181-
#### Steps
182-
183-
- Run `git pull && git checkout 1.2.0`
184-
- When upgrading from older versions of these playbooks, you will need to do the following:
185-
- Rename `inventory/host_vars/{{ domain }}/passwords/postgres` file to `inventory/host_vars/{{ domain }}/passwords/postgres.psk`
186-
- Copy the `examples/vars.yml` file to `inventory/host_vars/{{ domain }}/vars.yml`
187-
- Edit your variables as desired
188-
- Run your regular deployment. Example: `ansible-playbook -i inventory/hosts lemmy.yml --become`
189-
190-
### Upgrading to 1.1.0 (Lemmy 0.18.3)
191-
192-
- No major changes should be required
94+
Since version `1.1.0` we no longer default to using `main` but use tags to make sure deployments are versioned.
95+
With every new release all migration steps shall be written in the [UPGRADING](UPGRADING.md) document.
96+
When updating please make sure you check out the [Lemmy Releases Changelog](https://github.com/LemmyNet/lemmy/blob/main/RELEASES.md) to see if there are any config changes with the releases since your last read.
19397

19498
## Migrating your existing install to use this deploy
19599

UPGRADING.md

+156
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
# Upgrading
2+
3+
This file shows all steps in how to upgrade between "versions" of the lemmy-ansible repository.
4+
5+
While we specify a version of Lemmy, pict-rs, postgres, etc. at the point in time we make a release, it does not mean that you cannot mix-and-match versions. (ie; you can run pictrs 0.5.10 with Lemmy 0.19.3).
6+
7+
While you are not forced into running the specific versions, we do not go through thorough testing on all version compatibility matrices, so please make your best judgement and always backup before performing updates.
8+
9+
### Upgrading to 1.5.0 (Lemmy 0.19.4, Pict-rs 0.5, postgres 16)
10+
11+
> **DO NOT RUN IT WITHOUT READING THIS WHOLE SECTION**
12+
13+
This is a major release which requires you to update postgres to v16, and pictrs to v0.5. Once that is done proceed with your regular deployments.
14+
15+
#### Postgres Upgrade from v15 to v16
16+
17+
You need to migrate from postgres v15 to v16. A helper script is provided, that dumps your database, swaps postgres container versions, starts them, and then imports the backup into the new container.
18+
19+
There will be downtime, and it is a little scary as it will be deleting the `volumes/postgres` folder. The only backup you have during this time will be the `15_16_dump.sql`, created by the helper script.
20+
21+
On my reference instance (4 CPU, 8GB Memory, 30GB volumes/postgres), it took 10 minutes to dump the backup, and another 20 minutes to import it again. The biggest time sink when importing is when it recreates the indexes.
22+
If you have a faster system and no noisy neighbours you could get the dump and import to be below 20 minutes, but I'd aim for a 60 minute maintenace window.
23+
24+
- The script you need to download and push onto your server: [postgres_15_to_16_upgrade.sh](https://github.com/LemmyNet/lemmy/blob/main/scripts/postgres_15_to_16_upgrade.sh).
25+
26+
```
27+
# Go to your lemmy directory with the docker-compose.yml
28+
cd /srv/lemmy/{my_lemmy_domain}/
29+
30+
# Download the upgrade script
31+
sudo wget -O postgres_15_to_16_upgrade.sh "https://raw.githubusercontent.com/LemmyNet/lemmy/main/scripts/postgres_15_to_16_upgrade.sh"
32+
33+
# Run the script. Be aware that it may take > 20 minutes
34+
sudo sh postgres_15_to_16_upgrade.sh
35+
```
36+
37+
- This also creates a backup file of your old database, called `15_16_dump.sql`. **Do not delete this file** until you are sure that everything is working correctly, for at least a few days.
38+
39+
#### Pictrs 0.4 -> 0.5 Upgrade
40+
41+
`0.19.4` also adds functionality only supported by pictrs version `0.5`. Follow the [v0.4 -> v0.5 migration guide](https://git.asonix.dog/asonix/pict-rs.git#0-4-to-0-5-migration-guide) to make sure that your pictrs env vars in `vars.yml` are correct.
42+
43+
There are more detailed pictrs upgrade instructions below.
44+
45+
#### Steps
46+
47+
- `git checkout main && git pull && git checkout 1.5.0`
48+
- Check the diff between the two versions to see the changes our examples:
49+
- examples/customPostgresql.conf: We added a new autoexplain & stats feature, & enabled jit after v16 upgrade. \
50+
- On low memory systems, you might want to disable jit still: `jit=0`
51+
- examples/hosts: Add `lemmy_web_port` to have a dedicated port
52+
- examples/vars.yml: Add `postgres_shm` to have the correct shared memory for postgres
53+
- Confirm you are already running Postgres v16
54+
- Run your regular deployment. Example: `ansible-playbook -i inventory/hosts lemmy.yml --become`
55+
56+
### Upgrading to 1.4.0 (Lemmy 0.19.3 & Pict-rs 0.5.4)
57+
58+
This is a semi-major release which upgrades pict-rs to 0.5 which has support for postgres as a backend. This configuration is **not supported** by lemmy-ansible for the moment.
59+
60+
#### Steps
61+
62+
- `git pull && git checkout 1.4.0`
63+
- Read [Pictrs' Configuration Changes](https://git.asonix.dog/asonix/pict-rs/#configuration-updates)
64+
- Amend your `vars.yml` file to respect the new changes
65+
- Optional: Add: `PICTRS__UPGRADE__CONCURRENCY` with a value between 32 and 512 depending on how much RAM/CPU you want to dedicate to the upgrade process. A value of 32 used about 2.5GB of RAM for the migration.
66+
- Optional: Curl `/internal/prepare_upgrade` to minimise downtime while upgrading. See [the instructions below](https://github.com/LemmyNet/lemmy-ansible#update-your-pict-rs-sled-database-optional) or the official documentation [here](https://git.asonix.dog/asonix/pict-rs/releases#user-content-upgrade-preparation-endpoint)
67+
- Run your regular deployment. Example: `ansible-playbook -i inventory/hosts lemmy.yml --become`
68+
69+
### Upgrading to 1.3.1 (Lemmy 0.19.1)
70+
71+
This is a very minor release but fixes issues relating to federation as part of the Lemmy update.
72+
73+
#### Steps
74+
75+
- `git pull && git checkout 1.3.1`
76+
- Run your regular deployment. Example: `ansible-playbook -i inventory/hosts lemmy.yml --become`
77+
78+
### Upgrading to 1.3.0 (Lemmy 0.19.0 & Pict-rs 0.4.7)
79+
80+
This is a major change and has required reading! tl;dr
81+
82+
- Lemmy has been upgraded to 0.19.0
83+
- pict-rs has been upgraded to 0.4.7
84+
- pict-rs has not been integrated with postgres yet
85+
- "Optional Modules" are now available to be added to your lemmy install as provided by the community.
86+
- The first being pictrs-safety
87+
88+
#### Steps
89+
90+
- Prepare to have downtime as the database needs to perform migrations!
91+
- Run `git pull && git checkout 1.3.0`
92+
- Run your regular deployment. Example: `ansible-playbook -i inventory/hosts lemmy.yml --become`
93+
- Lemmy will now be down! In testing this takes from 20 to 60 minutes.
94+
- If you are bored you can ssh into your server, and check the logs on postgres for updates
95+
- `docker compose logs -f postgres` while ssh'd and in your Lemmy directory
96+
97+
#### Update your pict-rs sled-database (Optional)
98+
99+
If you are happy for pict-rs to be down _for a while_ ~go straight to our `1.3.1` git tag which updates pictrs to 0.5.0~. Otherwise keep reading.
100+
Starting with 0.5.0 your database will automatically upgrade to the latest version, which will cause downtime for your users.
101+
As such there is an intermediary step where you can upgrade your database in the background to prepare for 0.5 (Reference documentation)[https://git.asonix.dog/asonix/pict-rs/releases#user-content-upgrade-preparation-endpoint]. This ensure no-one is caught out by unforseen downtime of multiple services.
102+
103+
Once you have deployed lemmy-ansible `1.3.0` tag, please continue (if you want):
104+
105+
- Take note of what your pict-rs API Key is under `vars.yml`
106+
- Take note of what your docker network name is. (It's normally the domain without any extra characters)
107+
- You should be able to find it via: `docker network ls | grep _default` if in doubt.
108+
- Run the following command replacing `api-key` with the pict-rs api key, & `youdomain` with the network name.
109+
- `docker run --network yourdomain_default --rm curlimages/curl:8.5.0 --silent -XPOST -H'X-Api-Token: api-key' 'http://pictrs:8080/internal/prepare_upgrade'`
110+
- This will start the background process updating your database from 0.4 to 0.5 compatible.
111+
112+
This is only Optional, and takes a shorter amount of time than the Lemmy database upgrade, but on huge installations it may take a lot longer.
113+
114+
#### Optional Module(s)
115+
116+
Our first optional module is [pictrs-safety](https://github.com/db0/pictrs-safety). See the repo linked for more information, especially for integration with pictrs (which is what it is for) Thanks to @db0 for their contribution.
117+
See the `pictrs_safety_env_vars` under `examples/vars.yml` for relevant options (and the two password variables)
118+
To enable this module to be used you must ADD `pictrs_safety: true` to your `vars.yml`.
119+
120+
### Upgrading to 1.2.1 (Lemmy 0.18.5)
121+
122+
This is a minor change which fixes the issue with the Postgres container not using the `customPostgres.conf` file.
123+
124+
#### Steps
125+
126+
- Please regenerate your `customPostgres.conf` from `examples/customPostgres.conf`
127+
- **OR**
128+
- Add the following block to your current customPostgres file.
129+
130+
```
131+
132+
# Listen beyond localhost
133+
134+
listen_addresses = '\*'
135+
136+
```
137+
138+
### Upgrading to 1.2.0 (Lemmy 0.18.5)
139+
140+
Major changes:
141+
142+
- All variables are not under a singular file so you will not need to modify anything: `inventory/host_vars/{{ domain }}/vars.yml`
143+
- `--become` is now optional instead of forced on
144+
145+
#### Steps
146+
147+
- Run `git pull && git checkout 1.2.0`
148+
- When upgrading from older versions of these playbooks, you will need to do the following:
149+
- Rename `inventory/host_vars/{{ domain }}/passwords/postgres` file to `inventory/host_vars/{{ domain }}/passwords/postgres.psk`
150+
- Copy the `examples/vars.yml` file to `inventory/host_vars/{{ domain }}/vars.yml`
151+
- Edit your variables as desired
152+
- Run your regular deployment. Example: `ansible-playbook -i inventory/hosts lemmy.yml --become`
153+
154+
### Upgrading to 1.1.0 (Lemmy 0.18.3)
155+
156+
- No major changes should be required

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.19.3
1+
0.19.4

examples/config.hjson

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
database: {
66
host: postgres
77
password: "{{ postgres_password }}"
8+
# Alternative way:
9+
#uri: "postgresql://lemmy:{{ postgres_password }}@postgres/lemmy"
810
}
911
hostname: "{{ domain }}"
1012
pictrs: {

examples/customPostgresql.conf

+7-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
# Data Storage: ssd
77

88
max_connections = 200
9-
shared_buffers = 2GB
9+
# This needs to match your shm_size in docker-compose.yml
10+
shared_buffers = 2GB
1011
effective_cache_size = 6GB
1112
maintenance_work_mem = 512MB
1213
checkpoint_completion_target = 0.9
@@ -33,4 +34,8 @@ listen_addresses = '*'
3334

3435
# Fix a memory leak issue with postgres 15
3536
# https://github.com/LemmyNet/lemmy/issues/4406
36-
jit = 0
37+
#jit = 0
38+
39+
# Autoexplain and take stats by default
40+
shared_preload_libraries = 'auto_explain,pg_stat_statements'
41+
auto_explain.log_min_duration = 5000ms

examples/hosts

+5-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99
# if you are upgrading from a previous version, set this to `/lemmy`
1010
# - `lemmy_version`: <Optional> The back end version.
1111
# - `lemmy_ui_version`: <Optional> overrides the front end version.
12-
# - `pictrs_safety`: <Optional> If true, a docker container for pictrs-safety will be deployed and pict-rs will be configured to validate images through it. You will also need to set up a fedi-safety worker to validate the images.
13-
example.com ansible_user=root domain=example.com letsencrypt_contact_email[email protected] lemmy_base_dir=/srv/lemmy pictrs_safety=false
12+
# - `pictrs_safety`: <Optional> If true, a docker container for pictrs-safety will be deployed and pict-rs
13+
# will be configured to validate images through it. You will also need to set up a
14+
# fedi-safety worker to validate the images.
15+
# - `lemmy_web_port`: <Optional> Sets the host->docker nginx upstream port to allow a static host nginx configuration
16+
example.com ansible_user=root domain=example.com letsencrypt_contact_email[email protected] lemmy_base_dir=/srv/lemmy pictrs_safety=false lemmy_web_port=9633
1417

1518
[all:vars]
1619
ansible_connection=ssh

examples/vars.yml

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ postgres_env_vars:
3535
- POSTGRES_PASSWORD: "{{ postgres_password }}"
3636
- POSTGRES_DB: lemmy
3737

38+
postgres_shm: 2g
39+
3840
lemmy_env_vars:
3941
- RUST_LOG: warn
4042

lemmy-almalinux.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,14 @@
173173
owner: "root"
174174
- path: "{{ lemmy_base_dir }}/{{ domain }}/volumes/pictrs/"
175175
owner: "991" # Matches docker-compose UID in docker-compose.yml
176+
- path: "/var/cache/lemmy/{{ domain }}/"
177+
owner: "www-data"
176178
tags:
177179
- directories
178180

179181
- name: Set lemmy_port fact
180182
ansible.builtin.set_fact:
181-
lemmy_port: "{{ 32767 | random(start=1024) }}"
183+
lemmy_port: "{{ lemmy_web_port | default(32767 | random(start=1024)) }}"
182184
tags:
183185
- always
184186

lemmy.yml

+3-10
Original file line numberDiff line numberDiff line change
@@ -205,16 +205,16 @@
205205
owner: "root"
206206
- path: "{{ lemmy_base_dir }}/{{ domain }}/volumes/pictrs/"
207207
owner: "991"
208+
- path: "/var/cache/lemmy/{{ domain }}/"
209+
owner: "www-data"
208210
tags:
209211
- directories
210212

211213
- name: Deploy configuration files
212214
block:
213215
- name: Generate random port for lemmy service
214216
ansible.builtin.set_fact:
215-
lemmy_port: "{{ 32767 | random(start=1024) }}"
216-
tags:
217-
- always
217+
lemmy_port: "{{ lemmy_web_port | default(32767 | random(start=1024)) }}"
218218

219219
- name: Distribute nginx proxy_params configuration
220220
ansible.builtin.copy:
@@ -304,13 +304,6 @@
304304
tags:
305305
- docker
306306

307-
# - name: Change the working directory to /opt
308-
# ansible.builtin.shell:
309-
# cmd: find . # To list files under /opt directory
310-
# chdir: /opt # changes to /opt directory
311-
# register: shell_output
312-
# - debug: var=shell_output
313-
314307
- name: Start docker-compose
315308
community.docker.docker_compose_v2:
316309
project_src: "{{ lemmy_base_dir }}/{{ domain }}"

0 commit comments

Comments
 (0)