fix: refactor and add docker tests
This commit is contained in:
parent
0c9c5ca39f
commit
57dc12725f
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
.vscode
|
||||
|
||||
inventory
|
||||
inventory.yml
|
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -1,3 +0,0 @@
|
||||
{
|
||||
"ansible.python.interpreterPath": "/bin/python3.10"
|
||||
}
|
89
README.md
89
README.md
@ -1,4 +1,4 @@
|
||||
ansible-simplex-chat-server
|
||||
ansible-role-simplex-chat-server
|
||||
=========
|
||||
|
||||
Spin up a SimpleX SMP/XFTP server, optionally hosted/proxied with Tor
|
||||
@ -6,55 +6,78 @@ Spin up a SimpleX SMP/XFTP server, optionally hosted/proxied with Tor
|
||||
Requirements
|
||||
------------
|
||||
|
||||
Docker
|
||||
None.
|
||||
|
||||
Role Variables
|
||||
--------------
|
||||
```yaml
|
||||
########################################################
|
||||
|
||||
########################################################
|
||||
DOCKER_DIR: /opt/docker
|
||||
########################################################
|
||||
DOCKER_DIR: /opt/docker
|
||||
|
||||
########################################################
|
||||
SIMPLEX_UID: 1000
|
||||
SIMPLEX_GID: 1000
|
||||
########################################################
|
||||
|
||||
SIMPLEX_SMP_SERVER_ENABLED: true
|
||||
SIMPLEX_SMP_IMAGE: simplexchat/smp-server:latest
|
||||
SIMPLEX_SMP_PORT: 5223
|
||||
SIMPLEX_SMP_ADDR: changeme.internal
|
||||
SIMPLEX_SMP_PASSWORD:
|
||||
SIMPLEX_UID: 1000
|
||||
SIMPLEX_GID: 1000
|
||||
|
||||
SIMPLEX_XFTP_SERVER_ENABLED: true
|
||||
SIMPLEX_XFTP_IMAGE: simplexchat/xftp-server:latest
|
||||
SIMPLEX_XFTP_PORT: 5233
|
||||
SIMPLEX_XFTP_QUOTA: 150gb
|
||||
SIMPLEX_XFTP_ADDR: changeme.internal
|
||||
SIMPLEX_XFTP_EXPIRE_FILE_HOURS: 48
|
||||
########################################################
|
||||
SIMPLEX_SMP_SERVER_ENABLED: true
|
||||
SIMPLEX_SMP_IMAGE: simplexchat/smp-server:latest
|
||||
SIMPLEX_SMP_PORT: 5223
|
||||
SIMPLEX_SMP_ADDR: changeme.internal
|
||||
SIMPLEX_SMP_PASSWORD:
|
||||
|
||||
########################################################
|
||||
TOR_ENABLED: true
|
||||
TOR_PROXY_ENABLED: true
|
||||
TOR_SINGLE_HOP_MODE_ENABLED: true
|
||||
TOR_NON_ANONYMOUS_MODE_ENABLED: true
|
||||
########################################################
|
||||
SIMPLEX_XFTP_SERVER_ENABLED: true
|
||||
SIMPLEX_XFTP_IMAGE: simplexchat/xftp-server:latest
|
||||
SIMPLEX_XFTP_PORT: 5233
|
||||
SIMPLEX_XFTP_QUOTA: 150gb
|
||||
SIMPLEX_XFTP_ADDR: changeme.internal
|
||||
SIMPLEX_XFTP_EXPIRE_FILE_HOURS: 48
|
||||
|
||||
########################################################
|
||||
WATCHTOWER_ENABLED: true
|
||||
########################################################
|
||||
########################################################
|
||||
|
||||
TOR_ENABLED: true
|
||||
TOR_PROXY_ENABLED: false
|
||||
TOR_SINGLE_HOP_MODE_ENABLED: true
|
||||
TOR_NON_ANONYMOUS_MODE_ENABLED: true
|
||||
|
||||
########################################################
|
||||
|
||||
WATCHTOWER_ENABLED: true
|
||||
|
||||
########################################################
|
||||
```
|
||||
|
||||
Dependencies
|
||||
------------
|
||||
|
||||
- geerlingguy.docker
|
||||
```yaml
|
||||
collections:
|
||||
- name: community.docker
|
||||
roles:
|
||||
- src: geerlingguy.docker
|
||||
```
|
||||
|
||||
Example Playbook
|
||||
----------------
|
||||
- hosts: server
|
||||
roles:
|
||||
- ansible-simplex-chat-server
|
||||
```yaml
|
||||
---
|
||||
|
||||
- hosts: vps
|
||||
become: yes
|
||||
gather_facts: true
|
||||
|
||||
pre_tasks:
|
||||
- ansible.builtin.include_tasks: tasks/docker-check.yml
|
||||
|
||||
roles:
|
||||
- role: ansible-simplex-chat-server
|
||||
vars:
|
||||
SIMPLEX_UID: 5000
|
||||
SIMPLEX_GID: 5000
|
||||
SIMPLEX_XFTP_QUOTA: 1gb
|
||||
SIMPLEX_SMP_ADDR: example.org
|
||||
SIMPLEX_XFTP_ADDR: example.org
|
||||
```
|
||||
|
||||
License
|
||||
-------
|
||||
|
@ -1,11 +1,10 @@
|
||||
---
|
||||
# defaults file for ansible-simplex-chat-server
|
||||
|
||||
########################################################
|
||||
|
||||
DOCKER_DIR: /opt/docker
|
||||
########################################################
|
||||
|
||||
########################################################
|
||||
|
||||
SIMPLEX_UID: 1000
|
||||
SIMPLEX_GID: 1000
|
||||
|
||||
@ -21,15 +20,16 @@ SIMPLEX_XFTP_PORT: 5233
|
||||
SIMPLEX_XFTP_QUOTA: 150gb
|
||||
SIMPLEX_XFTP_ADDR: changeme.internal
|
||||
SIMPLEX_XFTP_EXPIRE_FILE_HOURS: 48
|
||||
########################################################
|
||||
|
||||
########################################################
|
||||
|
||||
TOR_ENABLED: true
|
||||
TOR_PROXY_ENABLED: true
|
||||
TOR_PROXY_ENABLED: false
|
||||
TOR_SINGLE_HOP_MODE_ENABLED: true
|
||||
TOR_NON_ANONYMOUS_MODE_ENABLED: true
|
||||
########################################################
|
||||
|
||||
########################################################
|
||||
|
||||
WATCHTOWER_ENABLED: true
|
||||
|
||||
########################################################
|
@ -1,51 +1,39 @@
|
||||
---
|
||||
dependencies:
|
||||
- role: geerlingguy.docker
|
||||
when: docker_installed is false or docker_compose_installed is false
|
||||
|
||||
galaxy_info:
|
||||
author: your name
|
||||
description: your role description
|
||||
company: your company (optional)
|
||||
|
||||
# If the issue tracker for your role is not on github, uncomment the
|
||||
# next line and provide a value
|
||||
# issue_tracker_url: http://example.com/issue/tracker
|
||||
|
||||
# Choose a valid license ID from https://spdx.org - some suggested licenses:
|
||||
# - BSD-3-Clause (default)
|
||||
# - MIT
|
||||
# - GPL-2.0-or-later
|
||||
# - GPL-3.0-only
|
||||
# - Apache-2.0
|
||||
# - CC-BY-4.0
|
||||
license: GPL-3.0-or-later
|
||||
|
||||
min_ansible_version: 2.1
|
||||
|
||||
# If this a Container Enabled role, provide the minimum Ansible Container version.
|
||||
# min_ansible_container_version:
|
||||
|
||||
#
|
||||
# Provide a list of supported platforms, and for each platform a list of versions.
|
||||
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
|
||||
# To view available platforms and versions (or releases), visit:
|
||||
# https://galaxy.ansible.com/api/v1/platforms/
|
||||
#
|
||||
# platforms:
|
||||
# - name: Fedora
|
||||
# versions:
|
||||
# - all
|
||||
# - 25
|
||||
# - name: SomePlatform
|
||||
# versions:
|
||||
# - all
|
||||
# - 1.0
|
||||
# - 7
|
||||
# - 99.99
|
||||
|
||||
galaxy_tags: []
|
||||
# List tags for your role here, one per line. A tag is a keyword that describes
|
||||
# and categorizes the role. Users find roles by searching for tags. Be sure to
|
||||
# remove the '[]' above, if you add tags to this list.
|
||||
#
|
||||
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
|
||||
# Maximum 20 tags per role.
|
||||
|
||||
dependencies: []
|
||||
# - community.docker
|
||||
author: BrazenWillow
|
||||
description: Spin up a SimpleX SMP/XFTP server, optionally hosted/proxied with Tor
|
||||
company: ""
|
||||
issue_tracker_url: https://codeberg.org/BrazenWillow/ansible-role-simplex-chat-server/issues
|
||||
license: AGPL-3.0-or-later
|
||||
min_ansible_version: "2.10"
|
||||
platforms:
|
||||
- name: Fedora
|
||||
versions:
|
||||
- all
|
||||
- name: Debian
|
||||
versions:
|
||||
- buster
|
||||
- bullseye
|
||||
- bookworm
|
||||
- name: Ubuntu
|
||||
versions:
|
||||
- bionic
|
||||
- focal
|
||||
- jammy
|
||||
- noble
|
||||
- name: Alpine
|
||||
version:
|
||||
- all
|
||||
- name: ArchLinux
|
||||
versions:
|
||||
- all
|
||||
galaxy_tags:
|
||||
- simplex
|
||||
- simplex-chat
|
||||
- simplex-chat-smp
|
||||
- simplex-chat-xftp
|
||||
- simplex-chat-server
|
@ -1,7 +0,0 @@
|
||||
---
|
||||
|
||||
- hosts: localhost
|
||||
become: yes
|
||||
gather_facts: true
|
||||
roles:
|
||||
- ansible-simplex-chat-server
|
5
requirements.yml
Normal file
5
requirements.yml
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
collections:
|
||||
- name: community.docker
|
||||
roles:
|
||||
- src: geerlingguy.docker
|
@ -1 +0,0 @@
|
||||
Subproject commit ae17f0641b9de1eaded93302da5bfcf513b3543d
|
@ -13,7 +13,7 @@
|
||||
ansible.builtin.shell:
|
||||
cmd: "git clone https://github.com/simplex-chat/simplexmq"
|
||||
chdir: "{{ DOCKER_DIR }}/simplex/"
|
||||
when: simplex_repo_stat.exists is false
|
||||
when: simplex_repo_stat.stat.exists is false
|
||||
|
||||
- name: Checkout stable branch of SimpleX chat repo
|
||||
ansible.builtin.shell:
|
||||
@ -24,7 +24,7 @@
|
||||
ansible.builtin.shell:
|
||||
cmd: "git pull"
|
||||
chdir: "{{ DOCKER_DIR }}/simplex/simplexmq"
|
||||
when: simplex_repo_stat.exists is true
|
||||
when: simplex_repo_stat.stat.exists is true
|
||||
|
||||
- name: Build SimpleX Chat SMP server image
|
||||
community.docker.docker_image_build:
|
||||
|
15
tasks/docker-check.yml
Normal file
15
tasks/docker-check.yml
Normal file
@ -0,0 +1,15 @@
|
||||
---
|
||||
|
||||
- name: Check if Docker is installed
|
||||
shell: "docker --version"
|
||||
ignore_errors: true
|
||||
register: docker_installed_check
|
||||
|
||||
- name: Check if Docker Compose is installed
|
||||
shell: "docker compose version"
|
||||
ignore_errors: true
|
||||
register: docker_compose_installed_check
|
||||
|
||||
- ansible.builtin.set_fact:
|
||||
docker_installed: "{{ docker_installed_check.failed is false }}"
|
||||
docker_compose_installed: "{{ docker_compose_installed_check.failed is false }}"
|
@ -1,15 +0,0 @@
|
||||
---
|
||||
- name: Check if Docker is installed
|
||||
shell: "docker --version"
|
||||
ignore_errors: true
|
||||
register: docker_installed
|
||||
|
||||
- name: Check if Docker Compose is installed
|
||||
shell: "docker compose version"
|
||||
ignore_errors: true
|
||||
register: docker_compose_installed
|
||||
|
||||
- name: geerlingguy
|
||||
ansible.builtin.include_role:
|
||||
name: ansible-role-docker
|
||||
when: docker_installed.failed or docker_compose_installed.failed
|
142
tasks/main.yml
142
tasks/main.yml
@ -1,32 +1,27 @@
|
||||
---
|
||||
# tasks file for ansible-simplex-chat-server
|
||||
|
||||
# - ansible.builtin.set_fact:
|
||||
# TEST: ''
|
||||
|
||||
# - debug:
|
||||
# msg: "{{ ',' + TEST if TEST | default('') | length > 1 else '' }}"
|
||||
|
||||
# - meta: end_play
|
||||
|
||||
- include_tasks: install-docker.yml
|
||||
|
||||
- block:
|
||||
- include_tasks: build-images.yml
|
||||
|
||||
- ansible.builtin.set_fact:
|
||||
SIMPLEX_SMP_IMAGE: local/smp-server
|
||||
SIMPLEX_XFTP_IMAGE: local/xftp-server
|
||||
simplex_image_source: local
|
||||
|
||||
when: ansible_architecture != 'x86_64'
|
||||
|
||||
- name: Ensure Docker Working Directory Exists
|
||||
ansible.builtin.file:
|
||||
path: "{{ DOCKER_DIR }}"
|
||||
state: directory
|
||||
mode: "0755"
|
||||
|
||||
- name: Create SimpleX directory for docker config
|
||||
ansible.builtin.file:
|
||||
path: "{{ DOCKER_DIR }}/simplex/"
|
||||
state: directory
|
||||
|
||||
- name: Check if images need to be built manually
|
||||
block:
|
||||
- ansible.builtin.include_tasks: build-images.yml
|
||||
|
||||
- name: Store updated variables after building
|
||||
ansible.builtin.set_fact:
|
||||
SIMPLEX_SMP_IMAGE: local/smp-server
|
||||
SIMPLEX_XFTP_IMAGE: local/xftp-server
|
||||
simplex_image_source: local
|
||||
|
||||
when: ansible_architecture != 'x86_64'
|
||||
|
||||
- name: Create docker storage for SimpleX containers
|
||||
ansible.builtin.file:
|
||||
path: "{{ DOCKER_DIR }}/simplex/{{ item }}"
|
||||
@ -50,7 +45,7 @@
|
||||
- "smp"
|
||||
- "xftp"
|
||||
|
||||
- name: Generate env file for SimpleX Docker
|
||||
- name: Generate .env file for SimpleX Docker
|
||||
ansible.builtin.template:
|
||||
src: "env.j2"
|
||||
dest: "{{ DOCKER_DIR }}/simplex/.env"
|
||||
@ -62,7 +57,7 @@
|
||||
dest: "{{ DOCKER_DIR }}/simplex/docker-compose.yaml"
|
||||
mode: "0755"
|
||||
|
||||
- name: Add Tor hosting option for SimpleX Server
|
||||
- name: Add Tor hosting option for SimpleX SMP/XFTP Server
|
||||
block:
|
||||
- name: Create tor-data directories for tor docker container
|
||||
ansible.builtin.file:
|
||||
@ -92,7 +87,7 @@
|
||||
|
||||
when: TOR_ENABLED is true
|
||||
|
||||
- name: Add Tor proxy option for SimpleX Server
|
||||
- name: Add Tor proxy option for SimpleX SMP Server
|
||||
block:
|
||||
- name: Create tor-proxy directories for tor docker container
|
||||
ansible.builtin.file:
|
||||
@ -132,57 +127,75 @@
|
||||
cmd: docker compose up -d
|
||||
chdir: "{{ DOCKER_DIR }}/simplex"
|
||||
|
||||
- name: Wait for SMP server to generate fingerprint
|
||||
ansible.builtin.wait_for:
|
||||
path: "{{ DOCKER_DIR }}/simplex/smp/config/fingerprint"
|
||||
timeout: 30
|
||||
|
||||
- name: Wait for XFTP server to generate fingerprint
|
||||
ansible.builtin.wait_for:
|
||||
path: "{{ DOCKER_DIR }}/simplex/xftp/config/fingerprint"
|
||||
timeout: 30
|
||||
|
||||
- block:
|
||||
- name: Read SimpleX SMP fingerprint
|
||||
ansible.builtin.set_fact:
|
||||
smp_fingerprint: "{{ lookup('file', DOCKER_DIR + '/simplex/smp/config/fingerprint') }}"
|
||||
|
||||
- name: Wait for tor to generate onion for SMP server
|
||||
- name: Gather SMP server info
|
||||
block:
|
||||
- name: Wait for SMP server to generate fingerprint
|
||||
ansible.builtin.wait_for:
|
||||
path: "{{ DOCKER_DIR }}/simplex/tor-data/simplex-smp/hostname"
|
||||
path: "{{ DOCKER_DIR }}/simplex/smp/config/fingerprint"
|
||||
timeout: 30
|
||||
|
||||
- ansible.builtin.shell:
|
||||
cmd: "cat {{ DOCKER_DIR }}/simplex/tor-data/simplex-smp/hostname"
|
||||
register: smp_onion_cmd
|
||||
- name: cat SMP fingerprint
|
||||
ansible.builtin.shell:
|
||||
cmd: "cat {{ DOCKER_DIR }}/simplex/smp/config/fingerprint"
|
||||
register: smp_fingerprint_cmd
|
||||
|
||||
- name: Read SimpleX SMP onion hostname
|
||||
- name: Gather SimpleX SMP fingerprint
|
||||
ansible.builtin.set_fact:
|
||||
smp_onion: "{{ smp_onion_cmd.stdout }}"
|
||||
smp_fingerprint: "{{ smp_fingerprint_cmd.stdout }}"
|
||||
|
||||
- name: Gather onion info for SMP server
|
||||
block:
|
||||
- name: Wait for tor to generate onion for SMP server
|
||||
ansible.builtin.wait_for:
|
||||
path: "{{ DOCKER_DIR }}/simplex/tor-data/simplex-smp/hostname"
|
||||
timeout: 30
|
||||
|
||||
- name: cat XFTP fingerprint
|
||||
ansible.builtin.shell:
|
||||
cmd: "cat {{ DOCKER_DIR }}/simplex/tor-data/simplex-smp/hostname"
|
||||
register: smp_onion_cmd
|
||||
|
||||
- name: Gather SimpleX SMP onion hostname
|
||||
ansible.builtin.set_fact:
|
||||
smp_onion: "{{ smp_onion_cmd.stdout }}"
|
||||
when: TOR_ENABLED is true
|
||||
|
||||
- name: Display SimpleX SMP URL
|
||||
- name: Gather SimpleX SMP URL
|
||||
ansible.builtin.set_fact:
|
||||
smp_server: "smp://{{ smp_fingerprint }}@{{ SIMPLEX_SMP_ADDR }}{{ ',' + smp_onion if smp_onion | default ('') | length > 1 }}:{{ SIMPLEX_SMP_PORT }}"
|
||||
|
||||
when: SIMPLEX_SMP_SERVER_ENABLED is true
|
||||
|
||||
- block:
|
||||
- name: Read SimpleX XFTP fingerprint
|
||||
- name: Gather XFTP server info
|
||||
block:
|
||||
- name: Wait for XFTP server to generate fingerprint
|
||||
ansible.builtin.wait_for:
|
||||
path: "{{ DOCKER_DIR }}/simplex/xftp/config/fingerprint"
|
||||
timeout: 30
|
||||
|
||||
- name: cat XFTP fingerprint
|
||||
ansible.builtin.shell:
|
||||
cmd: "cat {{ DOCKER_DIR }}/simplex/xftp/config/fingerprint"
|
||||
register: xftp_fingerprint_cmd
|
||||
|
||||
- name: Gather SimpleX XFTP fingerprint
|
||||
ansible.builtin.set_fact:
|
||||
xftp_fingerprint: "{{ lookup('file', DOCKER_DIR + '/simplex/xftp/config/fingerprint') }}"
|
||||
xftp_fingerprint: "{{ xftp_fingerprint_cmd.stdout }}"
|
||||
|
||||
- ansible.builtin.shell:
|
||||
cmd: "cat {{ DOCKER_DIR }}/simplex/tor-data/simplex-xftp/hostname"
|
||||
register: xftp_onion_cmd
|
||||
- name: Gather onion info for XFTP server
|
||||
block:
|
||||
- name: cat XFTP .onion hostname
|
||||
ansible.builtin.shell:
|
||||
cmd: "cat {{ DOCKER_DIR }}/simplex/tor-data/simplex-xftp/hostname"
|
||||
register: xftp_onion_cmd
|
||||
when: TOR_ENABLED is true
|
||||
|
||||
- name: Gather SimpleX XFTP onion hostname
|
||||
ansible.builtin.set_fact:
|
||||
xftp_onion: "{{ xftp_onion_cmd.stdout }}"
|
||||
when: TOR_ENABLED is true
|
||||
|
||||
- name: Read SimpleX XFTP onion hostname
|
||||
ansible.builtin.set_fact:
|
||||
xftp_onion: "{{ xftp_onion_cmd.stdout }}"
|
||||
when: TOR_ENABLED is true
|
||||
|
||||
- name: Display SimpleX XFTP URL
|
||||
- name: Gather SimpleX XFTP URL
|
||||
ansible.builtin.set_fact:
|
||||
xftp_server: "xftp://{{ xftp_fingerprint }}@{{ SIMPLEX_XFTP_ADDR }}{{',' + xftp_onion if xftp_onion | default('') | length > 1 }}:{{ SIMPLEX_XFTP_PORT }}"
|
||||
|
||||
@ -190,9 +203,12 @@
|
||||
|
||||
- name: Configure socks_proxy in smp-server.ini
|
||||
ansible.builtin.include_tasks: configure-tor-proxy-conf.yml
|
||||
when: TOR_PROXY_ENABLED is defined
|
||||
|
||||
- debug:
|
||||
- name: Display server URLs
|
||||
debug:
|
||||
msg: "{{ item }}"
|
||||
loop:
|
||||
- "{{ xftp_server }}"
|
||||
- "{{ smp_server }}"
|
||||
- "{{ smp_server | default ('') }}"
|
||||
- "{{ xftp_server | default ('') }}"
|
||||
when: item
|
||||
|
@ -1,2 +0,0 @@
|
||||
localhost
|
||||
|
@ -1,5 +0,0 @@
|
||||
---
|
||||
- hosts: localhost
|
||||
remote_user: root
|
||||
roles:
|
||||
- ansible-simplex-chat-server
|
Loading…
Reference in New Issue
Block a user