Browse Source

Merge branch 'feature/v8-5758-gestion_env_files' into feature/V8-5674-recette--refactoring-du-site-log

Olivier Massot 1 year ago
parent
commit
23bae3210e

+ 0 - 0
.env.docker → env/.env.docker


+ 0 - 0
.env.prod → env/.env.prod


+ 0 - 0
.env.test → env/.env.test


+ 6 - 0
env/.env.test1

@@ -0,0 +1,6 @@
+NUXT_ENV=test
+NUXT_DEBUG=1
+DEBUG=1
+
+NUXT_API_BASE_URL=https://api.test1.opentalent.fr
+NUXT_PUBLIC_API_BASE_URL=https://api.test1.opentalent.fr

+ 6 - 0
env/.env.test2

@@ -0,0 +1,6 @@
+NUXT_ENV=test
+NUXT_DEBUG=1
+DEBUG=1
+
+NUXT_API_BASE_URL=https://api.test2.opentalent.fr
+NUXT_PUBLIC_API_BASE_URL=https://api.test2.opentalent.fr

+ 6 - 0
env/.env.test3

@@ -0,0 +1,6 @@
+NUXT_ENV=test
+NUXT_DEBUG=1
+DEBUG=1
+
+NUXT_API_BASE_URL=https://api.test3.opentalent.fr
+NUXT_PUBLIC_API_BASE_URL=https://api.test3.opentalent.fr

+ 6 - 0
env/.env.test4

@@ -0,0 +1,6 @@
+NUXT_ENV=test
+NUXT_DEBUG=1
+DEBUG=1
+
+NUXT_API_BASE_URL=https://api.test4.opentalent.fr
+NUXT_PUBLIC_API_BASE_URL=https://api.test4.opentalent.fr

+ 6 - 0
env/.env.test5

@@ -0,0 +1,6 @@
+NUXT_ENV=test
+NUXT_DEBUG=1
+DEBUG=1
+
+NUXT_API_BASE_URL=https://api.test5.opentalent.fr
+NUXT_PUBLIC_API_BASE_URL=https://api.test5.opentalent.fr

+ 0 - 0
local.portail_v2.opentalent.fr.crt → env/local.portail_v2.opentalent.fr.crt


+ 0 - 0
local.portail_v2.opentalent.fr.key → env/local.portail_v2.opentalent.fr.key


+ 57 - 0
env/setupEnv.mjs

@@ -0,0 +1,57 @@
+/**
+ * Post install script: create or replace the symlink .env
+ * to the .env file matching the current environment
+ *
+ * To force a hostname, define an env variable named HOST :
+ *
+ *     HOST=ci node ./env/setupEnv.mjs
+ *
+ */
+import os from "os";
+import fs from "fs";
+import {fileURLToPath} from "node:url";
+import path from 'path';
+
+
+const projectDir = path.join(path.dirname(fileURLToPath(import.meta.url)), '..')
+
+const hostname = process.env.HOST ?? os.hostname()
+
+const environments = {
+  'portail_v2': '.env.docker',
+  'prod-v2': '.env.prod',
+  'test-v2': '.env.test',
+  'test1': '.env.test1',
+  'test2': '.env.test2',
+  'test3': '.env.test3',
+  'test4': '.env.test4',
+  'test5': '.env.test5',
+  'ci': '.env.ci',
+}
+
+if (!environments.hasOwnProperty(hostname)) {
+  throw Error("Critical : unknown environment [" + hostname + "]")
+}
+
+const targetEnvFile = path.join(projectDir, 'env', environments[hostname])
+const mainEnvFile = path.join(projectDir, '.env')
+
+fs.unlink(mainEnvFile, (err) => {
+  // 'ENOENT' is the error code for "no such file or directory", we ignore this one
+  if (err && err.code !== 'ENOENT') {
+    throw err
+  }
+  console.log(`${mainEnvFile} was deleted`);
+});
+
+fs.symlink(
+  targetEnvFile,
+  '.env',
+  'file',
+  (err) => {
+    if (err) {
+      throw (err);
+    }
+    console.log(`Symlink created : ${mainEnvFile} -> ${targetEnvFile}`)
+  }
+)

+ 2 - 2
nuxt.config.ts

@@ -12,8 +12,8 @@ if (!process.env.NUXT_ENV) {
 
 if (process.env.NUXT_ENV === 'dev') {
   https = {
-    key: fs.readFileSync('local.portail_v2.opentalent.fr.key'),
-    cert: fs.readFileSync('local.portail_v2.opentalent.fr.crt'),
+    key: fs.readFileSync('env/local.portail_v2.opentalent.fr.key'),
+    cert: fs.readFileSync('env/local.portail_v2.opentalent.fr.crt'),
   }
 } else {
   transpile.push('lodash')

+ 1 - 0
package.json

@@ -7,6 +7,7 @@
     "node": "18.19.0"
   },
   "scripts": {
+    "postinstall": "node ./env/setupEnv.mjs",
     "dev": "nuxt dev",
     "generate": "nuxt generate",
     "dev:local": "yarn dev --dotenv .env.local",