From cc73e4214a123cad4c07d871dc9eb39a28dcc871 Mon Sep 17 00:00:00 2001 From: Thomas MALGOUYRES Date: Thu, 30 Jul 2026 11:47:24 +0000 Subject: [PATCH] deploiement de snowshare --- inventory/hosts.ini | 4 + playbooks/create-lxc.yml | 23 +++++ playbooks/deploy-snowshare.yml | 118 ++++++++++++++++++++++++++ services/snowshare/docker-compose.yml | 51 +++++++++++ 4 files changed, 196 insertions(+) create mode 100644 playbooks/deploy-snowshare.yml create mode 100644 services/snowshare/docker-compose.yml diff --git a/inventory/hosts.ini b/inventory/hosts.ini index 94c7bcb..656102d 100644 --- a/inventory/hosts.ini +++ b/inventory/hosts.ini @@ -26,3 +26,7 @@ passwordpusher ansible_host=10.100.5.104 ansible_user=ansible ansible_python_int [immich_servers] immich ansible_host=10.100.5.111 ansible_user=ansible ansible_python_interpreter=/usr/bin/python3 # END ANSIBLE MANAGED immich +# BEGIN ANSIBLE MANAGED snowshare +[snowshare_servers] +snowshare ansible_host=10.100.5.112 ansible_user=ansible ansible_python_interpreter=/usr/bin/python3 +# END ANSIBLE MANAGED snowshare diff --git a/playbooks/create-lxc.yml b/playbooks/create-lxc.yml index f3b5f8c..cae161c 100644 --- a/playbooks/create-lxc.yml +++ b/playbooks/create-lxc.yml @@ -218,6 +218,29 @@ delegate_to: localhost become: false + - name: Supprimer l ancienne cle SSH connue + known_hosts: + name: "{{ lxc_ip_address }}" + state: absent + delegate_to: localhost + become: false + + - name: Scanner la nouvelle cle SSH du LXC + command: ssh-keyscan -H {{ lxc_ip_address }} + register: lxc_ssh_keyscan + changed_when: false + delegate_to: localhost + become: false + + - name: Ajouter la nouvelle cle SSH du LXC dans known_hosts + known_hosts: + name: "{{ lxc_ip_address }}" + key: "{{ item }}" + state: present + loop: "{{ lxc_ssh_keyscan.stdout_lines }}" + delegate_to: localhost + become: false + # Ajout automatique du nouveau LXC dans inventory/hosts.ini. # # blockinfile evite les doublons: diff --git a/playbooks/deploy-snowshare.yml b/playbooks/deploy-snowshare.yml new file mode 100644 index 0000000..267a55b --- /dev/null +++ b/playbooks/deploy-snowshare.yml @@ -0,0 +1,118 @@ +--- +# Playbook: deploy-snowshare.yml +# +# But: +# - Deployer Snowshare dans le LXC snowshare +# - Copier le docker-compose.yml depuis Git +# - Generer .env.runtime si absent +# - Creer un lien .env pour Docker Compose +# - Demarrer la stack Docker Compose +# - Verifier que le port 3000 repond +# +# Important: +# - Les secrets ne doivent pas etre dans Git +# - Le fichier .env.runtime reste sur le LXC + +- name: Deployer Snowshare + hosts: snowshare_servers + become: true + gather_facts: false + + vars: + stack_name: snowshare + stack_path: /opt/stacks/snowshare + compose_source: "{{ playbook_dir }}/../services/snowshare/docker-compose.yml" + snowshare_domain: snowshare.thomasmlg.fr + + tasks: + - name: Verifier que Docker est installe + command: docker --version + changed_when: false + + - name: Verifier que Docker Compose est installe + command: docker compose version + changed_when: false + + - name: Creer le dossier de la stack + file: + path: "{{ stack_path }}" + state: directory + owner: root + group: root + mode: "0750" + + - name: Generer le fichier env runtime si absent + shell: | + set -e + umask 077 + + if [ ! -f "{{ stack_path }}/.env.runtime" ]; then + POSTGRES_PASSWORD="$(openssl rand -hex 32)" + NEXTAUTH_SECRET="$(openssl rand -hex 32)" + + { + printf 'POSTGRES_USER=snowshare\n' + printf 'POSTGRES_PASSWORD=%s\n' "$POSTGRES_PASSWORD" + printf 'POSTGRES_DB=snowshare\n' + printf 'DATABASE_URL=postgres://snowshare:%s@db:5432/snowshare\n' "$POSTGRES_PASSWORD" + printf 'NEXTAUTH_URL=https://{{ snowshare_domain }}\n' + printf 'NEXTAUTH_SECRET=%s\n' "$NEXTAUTH_SECRET" + printf 'ALLOW_SIGNUP=true\n' + } > "{{ stack_path }}/.env.runtime" + fi + + chown root:root "{{ stack_path }}/.env.runtime" + chmod 600 "{{ stack_path }}/.env.runtime" + args: + executable: /bin/bash + no_log: true + changed_when: true + + - name: Creer le lien env pour Docker Compose + file: + src: "{{ stack_path }}/.env.runtime" + dest: "{{ stack_path }}/.env" + state: link + owner: root + group: root + + - name: Copier le fichier Docker Compose + copy: + src: "{{ compose_source }}" + dest: "{{ stack_path }}/docker-compose.yml" + owner: root + group: root + mode: "0644" + + - name: Valider la configuration Docker Compose + command: docker compose config + args: + chdir: "{{ stack_path }}" + changed_when: false + + - name: Telecharger les images Docker + command: docker compose pull + args: + chdir: "{{ stack_path }}" + + - name: Demarrer la stack Snowshare + command: docker compose up -d + args: + chdir: "{{ stack_path }}" + + - name: Attendre le port Snowshare + wait_for: + host: 127.0.0.1 + port: 3000 + timeout: 180 + + - name: Afficher les conteneurs de la stack + command: docker compose ps + args: + chdir: "{{ stack_path }}" + register: compose_ps + changed_when: false + + - name: Afficher le statut Docker Compose + debug: + var: compose_ps.stdout_lines \ No newline at end of file diff --git a/services/snowshare/docker-compose.yml b/services/snowshare/docker-compose.yml new file mode 100644 index 0000000..cd69b92 --- /dev/null +++ b/services/snowshare/docker-compose.yml @@ -0,0 +1,51 @@ +--- +services: + db: + image: postgres:16-alpine + container_name: snowshare-db + restart: unless-stopped + + env_file: + - .env.runtime + + environment: + POSTGRES_USER: ${POSTGRES_USER} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} + POSTGRES_DB: ${POSTGRES_DB} + + volumes: + - db-data:/var/lib/postgresql/data + + healthcheck: + test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"] + interval: 5s + timeout: 5s + retries: 10 + + app: + image: turodev/snowshare:latest + container_name: snowshare-app + restart: unless-stopped + + depends_on: + db: + condition: service_healthy + + env_file: + - .env.runtime + + environment: + DATABASE_URL: ${DATABASE_URL} + NEXTAUTH_URL: ${NEXTAUTH_URL} + NEXTAUTH_SECRET: ${NEXTAUTH_SECRET} + ALLOW_SIGNUP: ${ALLOW_SIGNUP} + + ports: + - "3000:3000" + + volumes: + - uploads:/app/uploads + +volumes: + db-data: + uploads: \ No newline at end of file