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",
|
||||
"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 crypto from "crypto";
|
||||
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 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
|
||||
let allSet: boolean = true;
|
||||
let missingConfigs: env_config[] = [];
|
||||
if (fs.existsSync(".env")) {
|
||||
dotenv.config();
|
||||
for (const key of config.requiredKeys) {
|
||||
if (!process.env[key]) {
|
||||
allSet = false;
|
||||
break;
|
||||
for (const setting of config.requiredKeys) {
|
||||
if (!process.env[setting.name]) {
|
||||
missingConfigs.push(setting);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
allSet = false;
|
||||
}
|
||||
|
||||
if (allSet) {
|
||||
if (missingConfigs.length < 1) {
|
||||
// if it`s all set abort the installation
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
// getting user input for the PostgreSQL username and password
|
||||
console.log("generrating .env file");
|
||||
const postgresUser: string = readlineSync.question(
|
||||
"Enter the PostgreSQL username (default: postgres): ",
|
||||
{ defaultInput: "postgres" }
|
||||
);
|
||||
let postgresPassword: string = "";
|
||||
while (!postgresPassword) {
|
||||
postgresPassword = readlineSync.question("Enter the PostgreSQL password: ", {
|
||||
hideEchoBack: true, // Hides the characters
|
||||
});
|
||||
!postgresPassword && console.log("Password cannot be empty");
|
||||
for (const setting of missingConfigs) {
|
||||
if (!setting.generated) {
|
||||
let input: string = "";
|
||||
do {
|
||||
input = readlineSync.question(
|
||||
`Enter the ${setting.name} ${setting.default ? `(${setting.default})` : ""}: `,
|
||||
{ defaultInput: setting.default, hideEchoBack: setting.hide }
|
||||
);
|
||||
} while (!input);
|
||||
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
|
||||
const jwtSecret: string = crypto.randomBytes(32).toString("hex"); // 64 Zeichen
|
||||
const env: string = `DATABASE_URL="postgresql://${postgresUser}:${postgresPassword}@localhost:5432/prisma"
|
||||
TOKEN_SECRET="${jwtSecret}"
|
||||
DB_USER="${postgresUser}"
|
||||
DB_PASSWORD="${postgresPassword}"`;
|
||||
let env: string = `DATABASE_URL="postgresql://${process.env["DB_USER"]}:${process.env["DB_PASSWORD"]}@localhost:5432/prisma"\n`;
|
||||
for (const setting of config.requiredKeys) {
|
||||
if (setting.name != "DATABASE_URL") {
|
||||
env += `${setting.name}="${process.env[setting.name]}"\n`;
|
||||
}
|
||||
}
|
||||
|
||||
// writing the .env file
|
||||
try {
|
||||
fs.writeFileSync(".env", env);
|
||||
console.log("File has been written successfully.");
|
||||
} catch (err) {
|
||||
console.error("Error writing to file:", err);
|
||||
}
|
||||
|
||||
// running the commands from the JSON file
|
||||
// The commands are executed in the order they are defined in the JSON file
|
||||
(async () => {
|
||||
|
|
|
@ -11,5 +11,19 @@ services:
|
|||
volumes:
|
||||
- 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:
|
||||
pgdata:
|
||||
minio-data:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue