Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 5 additions & 1 deletion roles/library-org/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
---
library_org_version: v2.0.1
library_org_version: "2.0.1"
# Path the legacy systemd-based deployment used; only read from for sqlite seed.
library_org_legacy_src_path: /srv/library-org
library_org_path: /srv/library.noisebridge.net
library_org_port: 5000
library_org_config:
secrets:
app_secret_key: nope
Expand Down
14 changes: 14 additions & 0 deletions roles/library-org/files/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
services:
library-org:
container_name: library-org
image: ghcr.io/noisebridge/library-org:${LIBRARY_ORG_VERSION}
restart: unless-stopped
ports:
- "127.0.0.1:${LIBRARY_ORG_PORT}:5000"
volumes:
- ./library.cfg:/app/library.cfg:ro
- library-org-database:/app/database

volumes:
library-org-database:
5 changes: 2 additions & 3 deletions roles/library-org/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
- name: restart library-org
become: true
systemd:
daemon_reload: true
name: library-org.service
community.docker.docker_compose_v2:
project_src: "{{ library_org_deploy_path }}"
state: restarted
149 changes: 98 additions & 51 deletions roles/library-org/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,69 +1,116 @@
---
- name: install packages

- name: install docker engine
apt:
package:
- python3-pip
- python3-setuptools
- python3-virtualenv

- name: create group
group:
name: library-org
system: true
name: docker.io
state: present
update_cache: true
when: library_org_docker_check.rc != 0

- name: install docker compose plugin
apt:
name: docker-compose-v2
state: present
update_cache: true
when: library_org_compose_check.rc != 0

- name: install python docker module
apt:
name: python3-docker
state: present
update_cache: true
when: library_org_pydocker_check.rc != 0
Comment on lines +3 to +22

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can simplify this:

Also, I would prefer to use Podman for our setup. Functions the same, but lighter weight (no daemon).

Suggested change
- name: install docker engine
apt:
name: docker.io
state: present
update_cache: true
when: library_org_docker_check.rc != 0
- name: install docker compose plugin
apt:
name: docker-compose-v2
state: present
update_cache: true
when: library_org_compose_check.rc != 0
- name: install python docker module
apt:
package:
- python3-pip
- python3-setuptools
- python3-virtualenv
- name: create group
group:
name: library-org
system: true
name: python3-docker
state: present
update_cache: true
when: library_org_pydocker_check.rc != 0
- name: install podman container engine
ansible.builtin.package:
name:
- podman
- podman-compose
- python3-podman
state: present
update_cache: true

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha I was just thinking the same thing re podman.


- name: stop and disable legacy systemd service
systemd:
name: library-org.service
state: stopped
enabled: false
failed_when: false

- name: remove legacy systemd unit
file:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do fully-qualified Ansible names for all of these. Eventually I would like to crank up the Ansible Lint level.

Suggested change
file:
ansible.builtin.file:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright let me take a closer look. I'm migrating this to use podman entirely rather than relying on docker compose. Any objections?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, there's also a podman compose.

path: /etc/systemd/system/library-org.service
state: absent

- name: create deploy directory
file:
path: "{{ library_org_deploy_path }}"
state: directory
mode: '0755'

- name: check for legacy sqlite database
stat:
path: "{{ library_org_legacy_src_path }}/database/books.sqlite"
register: library_org_legacy_db

- name: preserve legacy sqlite database as seed
copy:
src: "{{ library_org_legacy_src_path }}/database/books.sqlite"
dest: "{{ library_org_deploy_path }}/seed-books.sqlite"
remote_src: true
force: false
mode: '0644'
when: library_org_legacy_db.stat.exists

- name: create user
user:
name: library-org
system: true
shell: /sbin/nologin
group: library-org
createhome: false
home: /srv/library-org

- name: extract library code
git:
dest: /srv/library-org
repo: https://github.com/noisebridge/library-org.git
version: "{{ library_org_version }}"
- name: install docker-compose.yml
copy:
src: docker-compose.yml
dest: "{{ library_org_deploy_path }}/docker-compose.yml"
mode: '0644'
notify:
- restart library-org

- name: configure library-org
- name: render .env file
template:
src: library.cfg.j2
dest: /srv/library-org/library.cfg
mode: 0644
src: env.j2
dest: "{{ library_org_deploy_path }}/.env"
mode: '0644'
notify:
- restart library-org

- name: setup virtual env
pip:
requirements: /srv/library-org/requirements.txt
virtualenv: /srv/library-org/venv
- name: render library.cfg
template:
src: library.cfg.j2
dest: "{{ library_org_deploy_path }}/library.cfg"
mode: '0644'
notify:
- restart library-org

- name: setup database file
file:
path: /srv/library-org/database/books.sqlite
owner: library-org
group: library-org
mode: '0644'
- name: deploy library-org with docker compose
community.docker.docker_compose_v2:
project_src: "{{ library_org_deploy_path }}"
state: present

- name: create systemd service unit
template:
src: library-org.service.j2
dest: /etc/systemd/system/library-org.service
owner: root
group: root
mode: '0644'
- name: check whether container database is populated
command: docker exec library-org test -s /app/database/books.sqlite
register: library_org_container_db_check
changed_when: false
failed_when: false

- name: seed container database from legacy file
when:
- library_org_legacy_db.stat.exists
- library_org_container_db_check.rc != 0
block:
- name: copy seed sqlite into container
command: >-
docker cp
{{ library_org_deploy_path }}/seed-books.sqlite
library-org:/app/database/books.sqlite

- name: fix seeded database ownership
- name: install podman container engine
ansible.builtin.package:
name:
- podman
- podman-compose
- python3-podman
state: present
update_cache: true
command: docker exec -u root library-org chown nobody:nogroup /app/database/books.sqlite

Check failure on line 111 in roles/library-org/tasks/main.yml

View workflow job for this annotation

GitHub Actions / ansible-lint

syntax-check[specific]

YAML parsing failed: Mapping values are not allowed in this context.

Check warning on line 111 in roles/library-org/tasks/main.yml

View workflow job for this annotation

GitHub Actions / ansible-lint

load-failure[yaml]

Failed to load YAML file
notify:
- restart library-org

- name: ensure library-org service is started and enabled
systemd:
daemon_reload: true
name: library-org.service
state: started
enabled: true
# TODO: defaults/main.yml has `wtf_csrv_secret_key` (typo) but library.cfg.j2
# references `wtf_csrf_secret_key`. Reconcile against the vaulted secrets.
2 changes: 2 additions & 0 deletions roles/library-org/templates/env.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
LIBRARY_ORG_PORT={{ library_org_port }}
LIBRARY_ORG_VERSION={{ library_org_version }}
11 changes: 0 additions & 11 deletions roles/library-org/templates/library-org.service.j2

This file was deleted.

Loading