From 2ce3eafb790c93e8f64a9902d230adc39125b73d Mon Sep 17 00:00:00 2001 From: Kerboul Date: Wed, 23 Apr 2025 23:47:36 +0200 Subject: [PATCH] =?UTF-8?q?Refactor=20le=20workflow=20de=20d=C3=A9ploiemen?= =?UTF-8?q?t=20et=20simplifie=20la=20connexion=20=C3=A0=20la=20base=20de?= =?UTF-8?q?=20donn=C3=A9es=20PostgreSQL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/deploy.yml | 49 ++++++++++--------------------------- db.js | 34 ++++++++++++------------- devlock.js | 5 ---- docker-compose.yml | 21 ++++++++++++---- 4 files changed, 44 insertions(+), 65 deletions(-) delete mode 100644 devlock.js diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index 3bc4ca4..22689de 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -1,45 +1,22 @@ +name: SSH Hello + on: push: branches: - - main # Déclenche l'action pour la branche principale + - main jobs: - system-deploy: - runs-on: ubuntu-latest # Utilisation de l'image Ubuntu pour l'environnement de job + ssh-hello: + runs-on: ubuntu-latest + steps: - # Étape 1: Setup SSH - - name: Setup SSH and Add Private Key + - name: Write SSH Key run: | - # Créez un dossier pour stocker les clés SSH - mkdir -p ~/.ssh + echo "$SSH_PRIVATE_KEY" > id_rsa + chmod 600 id_rsa + env: + SSH_PRIVATE_KEY: ${{ vars.SSH_PRIVATE_KEY }} - # Ajoutez la clé privée stockée dans le secret à un fichier id_rsa - echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa - - # Protéger les permissions du fichier de la clé privée - chmod 600 ~/.ssh/id_rsa - - # Ajoutez l'hôte distant à known_hosts pour éviter les erreurs de vérification de l'host - ssh-keyscan -H 192.168.1.87 >> ~/.ssh/known_hosts - - # Vérifiez les permissions du fichier id_rsa (optionnel, juste pour être sûr) - ls -l ~/.ssh/id_rsa - - # Étape 2: Test SSH Connection - - name: Test SSH connection + - name: Run SSH Hello run: | - # Testez la connexion SSH avec l'hôte distant - ssh -v kerboul@192.168.1.87 "echo 'Connection successful!'" - - # Étape 3: Ajouter une action qui utilise la connexion SSH - - name: Run remote command - run: | - # Exemple de commande distante exécutée sur le serveur distant via SSH - ssh kerboul@192.168.1.87 "cd /home/kerboul/scripts/timelapse && ./update_timelapse.sh" - - # Étape 4: Nettoyage (optionnel) - - name: Clean up SSH keys - run: | - # Supprimer la clé privée pour des raisons de sécurité (optionnel) - rm -f ~/.ssh/id_rsa - rm -f ~/.ssh/known_hosts \ No newline at end of file + ssh -i id_rsa -o StrictHostKeyChecking=no ${{ vars.SSH_USER }}@${{ vars.SSH_HOST }} "echo 'Hello from Gitea Action!'" diff --git a/db.js b/db.js index 9e77f2e..a0992f5 100644 --- a/db.js +++ b/db.js @@ -1,33 +1,29 @@ const { Client } = require('pg'); -const devlock = require('./devlock.js'); -let dev = devlock.is_dev; -console.log('[INFO] Environment:', dev ? 'Development Local' : 'Development Remote'); - -let client = new Client({ - host: '192.168.192.2', +const client = new Client({ + host: 'timelapse-db', port: 5432, - user: 'timelapse', - password: 'timelapse', + user: 'postgres', + password: 'postgres', database: 'timelapse' }); -if (dev) { - client = new Client({ - host: 'mikoshi', - port: 54322, - user: 'timelapse', - password: 'timelapse', - database: 'timelapse_dev' - }); -} - +let isConnecting = false; function init_database() { + if (isConnecting) { + console.log('[DB] Connection attempt already in progress, skipping...'); + return; + } + console.log('[DB] Initialisation de la base de données PostgreSQL...'); + isConnecting = true; + client.connect(err => { + isConnecting = false; + if (err) { - console.error('Erreur de connexion à la base de données:', err); + console.error('[DB] Erreur de connexion à la base de données:', err); setTimeout(init_database, 3000); } else { console.log('[DB] Connecté à la base de données PostgreSQL.'); diff --git a/devlock.js b/devlock.js deleted file mode 100644 index e485dac..0000000 --- a/devlock.js +++ /dev/null @@ -1,5 +0,0 @@ -let is_dev = false; // Set to true for development mode - -module.exports = { - is_dev -} \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index a38151d..3c1d381 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,8 +1,8 @@ services: timelapse-api: build: - context: . # Chemin vers le répertoire contenant le Dockerfile - dockerfile: Dockerfile # Nom du Dockerfile, par défaut c'est "Dockerfile" + context: . + dockerfile: Dockerfile container_name: timelapse-api ports: - "8053:3000" @@ -17,13 +17,24 @@ services: restart: always networks: - bridge - - timelapse_network + timelapse-db: + image: postgres:14 + container_name: timelapse-db + ports: + - "5432:5432" + volumes: + - /home/timelapse/db:/var/lib/postgresql/data + environment: + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=postgres + - POSTGRES_DB=timelapse + restart: always + networks: + - bridge networks: bridge: driver: bridge - timelapse_network: - driver: bridge volumes: node_modules: \ No newline at end of file