-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify the setup script, capture only what is absolutely needed #576 #591
Changes from 3 commits
d35fe3a
2cf26e0
f5777ba
8994c1e
b607552
c88eecc
a20b816
f52e013
aa17e22
b34dced
1fbd978
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,17 @@ | ||
import inquirer from 'inquirer'; | ||
import * as fs from 'fs/promises'; | ||
import * as dotenv from 'dotenv'; | ||
import * as fs from 'fs/promises'; | ||
import { exit } from 'process'; | ||
import os from 'os'; | ||
|
||
/** | ||
* Load ENV, templates first, then override with actual ENV values | ||
* Load ENV, template first, then override with actual ENV values | ||
* if there are any. | ||
*/ | ||
|
||
// Top level | ||
dotenv.config({ path: '/usr/praise/.env.template', override: true }); | ||
dotenv.config({ path: '/usr/praise/.env', override: true }); | ||
|
||
// API | ||
dotenv.config({ | ||
path: '/usr/praise/packages/api/.env.template', | ||
override: true, | ||
}); | ||
dotenv.config({ path: '/usr/praise/packages/api/.env', override: true }); | ||
|
||
// Discord Bot | ||
dotenv.config({ | ||
path: '/usr/praise/packages/discord-bot/.env.template', | ||
override: true, | ||
}); | ||
dotenv.config({ | ||
path: '/usr/praise/packages/discord-bot/.env', | ||
override: true, | ||
}); | ||
|
||
// Frontend | ||
dotenv.config({ | ||
path: '/usr/praise/packages/frontend/.env.template', | ||
override: true, | ||
}); | ||
dotenv.config({ path: '/usr/praise/packages/frontend/.env', override: true }); | ||
dotenv.config({ path: '/usr/praise/.env.template', override: false }); | ||
dotenv.config({ path: '/usr/praise/.env', override: false }); | ||
|
||
/** | ||
* Welcome message | ||
|
@@ -65,48 +41,12 @@ const questions = [ | |
choices: ['production', 'development'], | ||
default: process.env.NODE_ENV, | ||
}, | ||
{ | ||
type: 'string', | ||
name: 'MONGO_INITDB_ROOT_USERNAME', | ||
message: 'MongoDB Root Username', | ||
default: process.env.MONGO_INITDB_ROOT_USERNAME, | ||
}, | ||
{ | ||
type: 'password', | ||
name: 'MONGO_INITDB_ROOT_PASSWORD', | ||
message: 'MongoDB Root Password', | ||
default: process.env.MONGO_INITDB_ROOT_PASSWORD, | ||
}, | ||
{ | ||
type: 'string', | ||
name: 'MONGO_USERNAME', | ||
message: 'MongoDB Praise Username', | ||
default: process.env.MONGO_USERNAME, | ||
}, | ||
{ | ||
type: 'password', | ||
name: 'MONGO_PASSWORD', | ||
message: 'MongoDB Praise Password', | ||
default: process.env.MONGO_PASSWORD, | ||
}, | ||
{ | ||
type: 'string', | ||
name: 'HOST', | ||
message: 'Server hostname', | ||
default: process.env.HOST, | ||
}, | ||
{ | ||
type: 'string', | ||
name: 'API_PORT', | ||
message: 'API port number', | ||
default: process.env.API_PORT, | ||
}, | ||
{ | ||
type: 'string', | ||
name: 'PORT', | ||
message: 'Frontend port number (Only used for development)', | ||
default: process.env.PORT, | ||
}, | ||
{ | ||
type: 'string', | ||
name: 'ADMINS', | ||
|
@@ -165,65 +105,39 @@ const run = async (): Promise<void> => { | |
const rootEnv = { | ||
NODE_ENV: answers.NODE_ENV, | ||
HOST: answers.HOST, | ||
API_PORT: answers.API_PORT, | ||
API_PORT: process.env.API_PORT, | ||
SERVER_URL: | ||
answers.NODE_ENV === 'production' | ||
? `https://${answers.HOST as string}` | ||
: `http://${answers.HOST as string}:${answers.API_PORT as string}`, | ||
: `http://${answers.HOST as string}:${process.env.API_PORT as string}`, | ||
FRONTEND_URL: | ||
answers.NODE_ENV === 'production' | ||
? `https://${answers.HOST as string}` | ||
: `http://${answers.HOST as string}:${answers.PORT as string}`, | ||
: `http://${answers.HOST as string}:${process.env.PORT as string}`, | ||
MONGO_HOST: answers.NODE_ENV === 'production' ? 'mongodb' : 'localhost', | ||
MONGO_INITDB_ROOT_USERNAME: answers.MONGO_INITDB_ROOT_USERNAME, | ||
MONGO_INITDB_ROOT_PASSWORD: answers.MONGO_INITDB_ROOT_PASSWORD, | ||
MONGO_USERNAME: answers.MONGO_USERNAME, | ||
MONGO_PASSWORD: answers.MONGO_PASSWORD, | ||
}; | ||
await setupAndWriteEnv( | ||
'/usr/praise/.env.template', | ||
'/usr/praise/.env', | ||
rootEnv | ||
); | ||
|
||
const apiEnv = { | ||
MONGO_INITDB_ROOT_USERNAME: randomString(12), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't generate random usernames for root username and username. Use the ones specified in |
||
MONGO_INITDB_ROOT_PASSWORD: randomString(12), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Passwords should not be regenerated on each run |
||
MONGO_USERNAME: randomString(12), | ||
MONGO_PASSWORD: randomString(12), | ||
ADMINS: answers.ADMINS, | ||
JWT_SECRET: process.env.JWT_SECRET || randomString(), | ||
DISCORD_TOKEN: answers.DISCORD_TOKEN, | ||
DISCORD_GUILD_ID: answers.DISCORD_GUILD_ID, | ||
}; | ||
await setupAndWriteEnv( | ||
'/usr/praise/packages/api/.env.template', | ||
'/usr/praise/packages/api/.env', | ||
apiEnv | ||
); | ||
|
||
const discordBotEnv = { | ||
DISCORD_TOKEN: answers.DISCORD_TOKEN, | ||
DISCORD_CLIENT_ID: answers.DISCORD_CLIENT_ID, | ||
DISCORD_GUILD_ID: answers.DISCORD_GUILD_ID, | ||
}; | ||
await setupAndWriteEnv( | ||
'/usr/praise/packages/discord-bot/.env.template', | ||
'/usr/praise/packages/discord-bot/.env', | ||
discordBotEnv | ||
); | ||
|
||
const frontendEnv = { | ||
REACT_APP_SERVER_URL: | ||
answers.NODE_ENV === 'production' | ||
? `https://${answers.HOST as string}` | ||
: `http://${answers.HOST as string}:${answers.API_PORT as string}`, | ||
PORT: answers.PORT, | ||
: `http://${answers.HOST as string}:${process.env.API_PORT as string}`, | ||
PORT: process.env.PORT, | ||
}; | ||
await setupAndWriteEnv( | ||
'/usr/praise/packages/frontend/.env.template', | ||
'/usr/praise/packages/frontend/.env', | ||
frontendEnv | ||
'/usr/praise/.env.template', | ||
'/usr/praise/.env', | ||
rootEnv | ||
); | ||
|
||
console.log('\n'); | ||
console.log('🙏 ENV files have been created.'); | ||
console.log('🙏 ENV file has been created.'); | ||
|
||
exit(); | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Override should be
true
, right? The template should override any pre-existing env settings. And the "real".env
should override the template.