118 lines
3.3 KiB
YAML
118 lines
3.3 KiB
YAML
---
|
|
# 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 |