-
Notifications
You must be signed in to change notification settings - Fork 23
Deploys the library-org service from a pre-built upstream docker container #490
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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: |
| 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 |
| 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 | ||||||
|
|
||||||
| - 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: | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
||||||
| 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. | ||||||
| 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 }} |
This file was deleted.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.