mirror of
https://github.com/bubblecup-12/VogelSocialMedia.git
synced 2025-07-06 15:18:48 +00:00
changed installscript and docker-compose to install minIO
This commit is contained in:
parent
84612cdc3c
commit
38e796ca22
3 changed files with 83 additions and 27 deletions
|
@ -8,5 +8,30 @@
|
||||||
"echo migrating database",
|
"echo migrating database",
|
||||||
"yarn prisma migrate dev --name init"
|
"yarn prisma migrate dev --name init"
|
||||||
],
|
],
|
||||||
"requiredKeys": ["DATABASE_URL", "TOKEN_SECRET", "DB_USER", "DB_PASSWORD"]
|
"requiredKeys": [
|
||||||
|
{ "name": "DATABASE_URL", "generated": true },
|
||||||
|
{ "name": "TOKEN_SECRET", "generated": true },
|
||||||
|
{
|
||||||
|
"name": "DB_USER",
|
||||||
|
"generated": false,
|
||||||
|
"default": "postgres",
|
||||||
|
"hide": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "DB_PASSWORD",
|
||||||
|
"generated": false,
|
||||||
|
"hide": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "MINIO_USER",
|
||||||
|
"generated": false,
|
||||||
|
"default": "minIO",
|
||||||
|
"hide": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "MINIO_PASSWORD",
|
||||||
|
"generated": false,
|
||||||
|
"hide": true
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,55 +6,72 @@ import fs, { read } from "fs";
|
||||||
import readlineSync from "readline-sync";
|
import readlineSync from "readline-sync";
|
||||||
import crypto from "crypto";
|
import crypto from "crypto";
|
||||||
import dotenv from "dotenv";
|
import dotenv from "dotenv";
|
||||||
import { boolean } from "zod";
|
|
||||||
|
type env_config = {
|
||||||
|
name: string;
|
||||||
|
generated: boolean;
|
||||||
|
input?: string;
|
||||||
|
default?: string;
|
||||||
|
hide?: boolean;
|
||||||
|
};
|
||||||
|
type json_config = {
|
||||||
|
commands: string[];
|
||||||
|
requiredKeys: env_config[];
|
||||||
|
};
|
||||||
|
|
||||||
const json_path: string = "scripts/install.json"; // Path to the JSON file
|
const json_path: string = "scripts/install.json"; // Path to the JSON file
|
||||||
const raw = fs.readFileSync(json_path, "utf8");
|
const raw = fs.readFileSync(json_path, "utf8");
|
||||||
const config = JSON.parse(raw); // Parse the JSON file
|
const config: json_config = JSON.parse(raw); // Parse the JSON file
|
||||||
|
|
||||||
//check if there is a .env and if it has the correct settings
|
//check if there is a .env and if it has the correct settings
|
||||||
let allSet: boolean = true;
|
let missingConfigs: env_config[] = [];
|
||||||
if (fs.existsSync(".env")) {
|
if (fs.existsSync(".env")) {
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
for (const key of config.requiredKeys) {
|
for (const setting of config.requiredKeys) {
|
||||||
if (!process.env[key]) {
|
if (!process.env[setting.name]) {
|
||||||
allSet = false;
|
missingConfigs.push(setting);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
allSet = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (allSet) {
|
if (missingConfigs.length < 1) {
|
||||||
// if it`s all set abort the installation
|
// if it`s all set abort the installation
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// getting user input for the PostgreSQL username and password
|
// getting user input for the PostgreSQL username and password
|
||||||
console.log("generrating .env file");
|
console.log("generrating .env file");
|
||||||
const postgresUser: string = readlineSync.question(
|
for (const setting of missingConfigs) {
|
||||||
"Enter the PostgreSQL username (default: postgres): ",
|
if (!setting.generated) {
|
||||||
{ defaultInput: "postgres" }
|
let input: string = "";
|
||||||
);
|
do {
|
||||||
let postgresPassword: string = "";
|
input = readlineSync.question(
|
||||||
while (!postgresPassword) {
|
`Enter the ${setting.name} ${setting.default ? `(${setting.default})` : ""}: `,
|
||||||
postgresPassword = readlineSync.question("Enter the PostgreSQL password: ", {
|
{ defaultInput: setting.default, hideEchoBack: setting.hide }
|
||||||
hideEchoBack: true, // Hides the characters
|
);
|
||||||
});
|
} while (!input);
|
||||||
!postgresPassword && console.log("Password cannot be empty");
|
process.env[setting.name] = input;
|
||||||
|
} else if (setting.name === "TOKEN_SECRET") {
|
||||||
|
// generating a random JWT secret
|
||||||
|
const jwtSecret: string = crypto.randomBytes(32).toString("hex"); // 64 Zeichen
|
||||||
|
process.env[setting.name] = jwtSecret;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// generating a random JWT secret
|
let env: string = `DATABASE_URL="postgresql://${process.env["DB_USER"]}:${process.env["DB_PASSWORD"]}@localhost:5432/prisma"\n`;
|
||||||
const jwtSecret: string = crypto.randomBytes(32).toString("hex"); // 64 Zeichen
|
for (const setting of config.requiredKeys) {
|
||||||
const env: string = `DATABASE_URL="postgresql://${postgresUser}:${postgresPassword}@localhost:5432/prisma"
|
if (setting.name != "DATABASE_URL") {
|
||||||
TOKEN_SECRET="${jwtSecret}"
|
env += `${setting.name}="${process.env[setting.name]}"\n`;
|
||||||
DB_USER="${postgresUser}"
|
}
|
||||||
DB_PASSWORD="${postgresPassword}"`;
|
}
|
||||||
|
|
||||||
|
// writing the .env file
|
||||||
try {
|
try {
|
||||||
fs.writeFileSync(".env", env);
|
fs.writeFileSync(".env", env);
|
||||||
console.log("File has been written successfully.");
|
console.log("File has been written successfully.");
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Error writing to file:", err);
|
console.error("Error writing to file:", err);
|
||||||
}
|
}
|
||||||
|
|
||||||
// running the commands from the JSON file
|
// running the commands from the JSON file
|
||||||
// The commands are executed in the order they are defined in the JSON file
|
// The commands are executed in the order they are defined in the JSON file
|
||||||
(async () => {
|
(async () => {
|
||||||
|
|
|
@ -11,5 +11,19 @@ services:
|
||||||
volumes:
|
volumes:
|
||||||
- pgdata:/var/lib/postgresql/data
|
- pgdata:/var/lib/postgresql/data
|
||||||
|
|
||||||
|
minio:
|
||||||
|
image: quay.io/minio/minio
|
||||||
|
container_name: minio
|
||||||
|
ports:
|
||||||
|
- "9000:9000" # API
|
||||||
|
- "9001:9001" # Web GUI
|
||||||
|
environment:
|
||||||
|
MINIO_ROOT_USER: ${MINIO_USER}
|
||||||
|
MINIO_ROOT_PASSWORD: ${MINIO_PASSWORD}
|
||||||
|
command: server /data --console-address ":9001"
|
||||||
|
volumes:
|
||||||
|
- minio-data:/data
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
pgdata:
|
pgdata:
|
||||||
|
minio-data:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue