Skip to content

Commit 587c1f7

Browse files
authored
Fix deployment on Debian 13 (#63)
2 parents c389d5c + 04cdec3 commit 587c1f7

4 files changed

Lines changed: 113 additions & 20 deletions

File tree

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22

33
All changes that impact users of this module are documented in this file, in the [Common Changelog](https://common-changelog.org) format with some additional specifications defined in the CONTRIBUTING file. This codebase adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
44

5+
## Unreleased [patch]
6+
7+
> Development of this release was supported by [Reset Tech](https://www.reset.tech).
8+
9+
### Fixed
10+
11+
- Replace NodeSource repository with native Node.js packages on Debian >= 13 to fix deployment failure caused by NodeSource GPG key using SHA-1, [rejected by apt since 2026-02-01](https://github.com/nodesource/distributions/issues/1908)
12+
13+
### Added
14+
15+
- Add `migrate` playbook for one-time changes on existing servers; run `ansible-playbook opentermsarchive.deployment.migrate` before `deploy` when upgrading
16+
517
## 3.0.0 - 2025-12-19
618

719
_Full changeset and discussions: [#58](https://github.com/OpenTermsArchive/deployment/pull/58)._

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,14 @@ ansible-playbook playbook.yml --vault-password-file vault.key
137137

138138
Please note that encrypted files will be decrypted and stored in plaintext on the deployment server. Always protect access to your production server.
139139

140+
## Migrations
141+
142+
Some updates require changes on existing servers before deploying. Run the `migrate` playbook before `deploy` when needed:
143+
144+
```sh
145+
ansible-playbook opentermsarchive.deployment.migrate
146+
```
147+
140148
## Playbook execution refinement
141149

142150
Use [tags](https://docs.ansible.com/ansible/latest/user_guide/playbooks_tags.html) to refine playbook execution. Example commands:

playbooks/migrate.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
- name: Run migrations
3+
hosts: all
4+
tasks:
5+
# Stop PM2 processes running in the default home (~/.pm2)
6+
# since v3 uses a per-collection home (~/.pm2-{collection_id})
7+
- name: Stop PM2 processes in default home
8+
ansible.builtin.shell: pm2 kill 2>/dev/null || true
9+
environment:
10+
PM2_HOME: /home/{{ ansible_user }}/.pm2
11+
12+
- name: Remove PM2 startup script
13+
ansible.builtin.shell: pm2 unstartup systemd 2>/dev/null || true
14+
become: true
15+
16+
- name: Remove default PM2 home
17+
ansible.builtin.file:
18+
path: /home/{{ ansible_user }}/.pm2
19+
state: absent
20+
21+
# Remove old nginx config (v2 used a single ota.conf,
22+
# v3 uses ota-global.conf and per-app ota-rate-limit-{app_id}.conf)
23+
- name: Remove old nginx config
24+
ansible.builtin.file:
25+
path: "{{ item }}"
26+
state: absent
27+
become: true
28+
loop:
29+
- /etc/nginx/conf.d/ota.conf
30+
- /etc/nginx/sites-enabled/ota
31+
- /etc/nginx/sites-available/ota
32+
33+
# See https://github.com/nodesource/distributions/issues/1908
34+
- name: Remove NodeSource repository on Debian >= 13
35+
when: ansible_distribution == 'Debian' and ansible_distribution_major_version | int >= 13
36+
become: true
37+
block:
38+
- name: Remove NodeSource APT repository
39+
ansible.builtin.file:
40+
path: /etc/apt/sources.list.d/nodesource.list
41+
state: absent
42+
43+
- name: Remove NodeSource GPG key
44+
ansible.builtin.file:
45+
path: /etc/apt/keyrings/nodesource.gpg
46+
state: absent
47+
48+
- name: Remove NodeSource Node.js package
49+
ansible.builtin.apt:
50+
name: nodejs
51+
state: absent
52+
purge: true

roles/node/tasks/main.yml

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,46 @@
11
---
2-
- name: Create keyrings directory
3-
ansible.builtin.file:
4-
path: /etc/apt/keyrings
5-
state: directory
6-
mode: "0755"
2+
# On Debian >= 13, use native Node.js packages since the NodeSource GPG key
3+
# uses SHA-1, rejected by apt. See https://github.com/nodesource/distributions/issues/1908
4+
# On older versions, use NodeSource to provide Node.js >= 20 as required by the engine.
75

8-
- name: Download and import the Nodesource GPG key
9-
ansible.builtin.shell: set -o pipefail && curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --yes --dearmor -o /etc/apt/keyrings/nodesource.gpg
10-
args:
11-
executable: /bin/bash
6+
- name: Install Node.js and NPM on Debian >= 13
7+
when: ansible_distribution == 'Debian' and ansible_distribution_major_version | int >= 13
8+
block:
9+
- name: Install Node.js and NPM
10+
ansible.builtin.apt:
11+
name:
12+
- nodejs
13+
- npm
14+
state: present
15+
update_cache: true
1216

13-
- name: Create deb repository
14-
ansible.builtin.shell: set -o pipefail && echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list # Remember to update the major version of NPM when updating the major version of Node
15-
args:
16-
executable: /bin/bash
17+
- name: Install NPM to latest version 10
18+
ansible.builtin.command: npm install -g npm@10
1719

18-
- name: Install NodeJS and NPM
19-
ansible.builtin.apt:
20-
name: nodejs
21-
update_cache: true
22-
state: latest # The major version of NodeJS is provided by the NodeSource repository defined in the task above
20+
- name: Install Node.js and NPM on Debian < 13
21+
when: ansible_distribution != 'Debian' or ansible_distribution_major_version | int < 13
22+
block:
23+
- name: Create keyrings directory
24+
ansible.builtin.file:
25+
path: /etc/apt/keyrings
26+
state: directory
27+
mode: "755"
2328

24-
- name: Update NPM to latest version 10
25-
ansible.builtin.command: npm install -g npm@10
29+
- name: Download and import the NodeSource GPG key
30+
ansible.builtin.shell: set -o pipefail && curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --yes --dearmor -o /etc/apt/keyrings/nodesource.gpg
31+
args:
32+
executable: /bin/bash
33+
34+
- name: Add NodeSource APT repository
35+
ansible.builtin.shell: set -o pipefail && echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list # Remember to update the major version of NPM when updating the major version of Node
36+
args:
37+
executable: /bin/bash
38+
39+
- name: Install Node.js
40+
ansible.builtin.apt:
41+
name: nodejs
42+
update_cache: true
43+
state: latest # The major version of NodeJS is provided by the NodeSource repository defined in the task above
44+
45+
- name: Install NPM 10
46+
ansible.builtin.command: npm install -g npm@10

0 commit comments

Comments
 (0)