From b265c96673c4123f1758dee0c328d1e7e6605a0e Mon Sep 17 00:00:00 2001
From: Maxime Princelle <maxime@princelle.org>
Date: Mon, 29 Nov 2021 21:27:49 +0100
Subject: [PATCH] =?UTF-8?q?=F0=9F=91=B7=20adapt=20CI=20scripts?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .dockerignore      |   5 ++
 .drone.yml         | 120 +++++++++++++++++++++++++++++++++++++++++++++
 .env.model         |   2 +
 .gitignore         |   1 +
 docker-compose.yml |  11 ++++-
 5 files changed, 137 insertions(+), 2 deletions(-)
 create mode 100644 .dockerignore
 create mode 100644 .drone.yml
 create mode 100644 .env.model

diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 0000000..1bcf75a
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1,5 @@
+docker-compose.yml
+Dockerfile
+.gitignore
+README.md
+.drone.yml
\ No newline at end of file
diff --git a/.drone.yml b/.drone.yml
new file mode 100644
index 0000000..8f771e9
--- /dev/null
+++ b/.drone.yml
@@ -0,0 +1,120 @@
+kind: pipeline
+type: docker
+name: deploy
+
+clone:
+  disable: true
+
+steps:
+- name: notif build start
+  image: appleboy/drone-discord
+  settings:
+    webhook_id:
+      from_secret: discord_webhook_id
+    webhook_token:
+      from_secret: discord_webhook_token
+    username: "Drone Princelle (ERP: student)"
+    avatar_url: https://s3.princelle.org/share/drone-ci.png
+    message: >
+      🚀 Starting deployment of **{{ repo.name }}** repo (*ERP*)...
+
+      
+      **Commit from {{commit.author}} on {{commit.branch}}:** 
+      
+      {{commit.message}}
+
+      {{ build.link }}
+
+
+- name: pull
+  image: appleboy/drone-ssh
+  settings:
+    host: flash.princelle.org
+    username: mprincelle
+    port: 22
+    key:
+      from_secret: ci_key
+    script:
+      - cd /app/uni/erp/student
+      - git fetch --all
+      - git reset --hard origin/main
+      - git checkout {{commit.branch}}
+      - git pull
+
+- name: configure
+  image: appleboy/drone-ssh
+  settings:
+    host: flash.princelle.org
+    username: mprincelle
+    port: 22
+    key:
+      from_secret: ci_key
+    script:
+      - cd /app/uni/erp/student
+      - echo -e "DB_PORT=2005" > .env
+      - echo -e "SERVER_PORT=2003" >> .env
+
+- name: build
+  image: appleboy/drone-ssh
+  settings:
+    host: flash.princelle.org
+    username: mprincelle
+    port: 22
+    key:
+      from_secret: ci_key
+    script:
+      - cd /app/uni/erp/student
+      - docker-compose up -d --build
+
+
+- name: notif deploy done
+  image: appleboy/drone-discord
+  settings:
+    webhook_id:
+      from_secret: discord_webhook_id
+    webhook_token:
+      from_secret: discord_webhook_token
+    username: "Drone Princelle (ERP: student)"
+    avatar_url: https://s3.princelle.org/share/drone-ci.png
+    message: >
+      ✅ Successfully deployed **{{ repo.name }}** repo (*ERP*) on Princelle Cloud!
+
+      
+      **Commit from {{commit.author}} on {{commit.branch}}:** 
+      
+      {{commit.message}}
+
+      **APP URL:** https://student.erp.uni.princelle.org/ 
+
+      {{ build.link }}
+  when:
+    status:
+    - success
+
+- name: notif deploy failure
+  image: appleboy/drone-discord
+  settings:
+    webhook_id:
+      from_secret: discord_webhook_id
+    webhook_token:
+      from_secret: discord_webhook_token
+    username: "Drone Princelle (ERP: student)"
+    avatar_url: https://s3.princelle.org/share/drone-ci.png
+    message: >
+        ⚠️ Error on deploying **{{ repo.name }}** repo (*ERP*) on Princelle Cloud...
+
+        
+        **Commit from {{commit.author}} on {{commit.branch}}:** 
+        
+        {{commit.message}}
+
+        {{ build.link }}
+  when:
+    status:
+    - failure
+
+
+trigger:
+  branch:
+  - main
+  - feature/docker-env
diff --git a/.env.model b/.env.model
new file mode 100644
index 0000000..a8472f7
--- /dev/null
+++ b/.env.model
@@ -0,0 +1,2 @@
+SERVER_PORT=27017
+APP_PORT=8005
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index aba02a1..8ea5b1e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
 .idea/
+.env
\ No newline at end of file
diff --git a/docker-compose.yml b/docker-compose.yml
index 4b9aa12..c234c8c 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -2,19 +2,26 @@ version: '3'
 services:
   mongodb:
     image: mongo
+    container_name: "student_db"
+    volumes:
+      - student_db_data:/data/db
     ports:
-      - "27017:27017"
+      - "${DB_PORT:-27017}:27017"
 
   server:
     build: .
     depends_on:
       - "mongodb"
     command: "npm run start:prod"
+    container_name: "student_app"
     ports:
-      - "8005:8005"
+      - "${SERVER_PORT:-8005}:8005"
     environment:
       - CHOKIDAR_USEPOLLING=true
       - CI=true
       - NODE_ENV=production
       - PORT=8005
       - MONGO_NAME=mongodb
+
+volumes:
+  student_db_data:
\ No newline at end of file
-- 
GitLab