Skip to content
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

459 add definitions for important env variables to readme #469

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: update config to different .env files
DeboraSerra committed Jan 6, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 5d6736b4f25d34d63991a0f5f28da6b2ac51b9f1
63 changes: 43 additions & 20 deletions backend/config/config.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,54 @@
require("dotenv").config();
const dotenv = require('dotenv');
const envSuffix = process.env.NODE_ENV && process.env.NODE_ENV !== 'development' ? `.${process.env.NODE_ENV}` : '';
const env = `.env${envSuffix}`;

dotenv.config({ path: `./${env}` });

const {
DEV_DB_HOST,
DEV_DB_NAME,
DEV_DB_PASSWORD,
DEV_DB_PORT,
DEV_DB_USERNAME,
TEST_DB_HOST,
TEST_DB_NAME,
TEST_DB_PASSWORD,
TEST_DB_PORT,
TEST_DB_USERNAME,
PROD_DB_HOST,
PROD_DB_NAME,
PROD_DB_PASSWORD,
PROD_DB_PORT,
PROD_DB_USERNAME,
} = process.env;

module.exports = {
defaultTeamName: "My Organisation",
defaultTeamName: 'My Organisation',
development: {
username: process.env.DEV_DB_USERNAME,
password: process.env.DEV_DB_PASSWORD,
database: process.env.DEV_DB_NAME,
host: process.env.DEV_DB_HOST,
dialect: "postgres",
port: process.env.DEV_DB_PORT,
username: DEV_DB_USERNAME,
password: DEV_DB_PASSWORD,
database: DEV_DB_NAME,
host: DEV_DB_HOST,
dialect: 'postgres',
port: DEV_DB_PORT,
logging: false,
},
test: {
username: process.env.TEST_DB_USERNAME,
password: process.env.TEST_DB_PASSWORD,
database: process.env.TEST_DB_NAME,
host: process.env.TEST_DB_HOST,
dialect: "postgres",
port: process.env.TEST_DB_PORT,
username: TEST_DB_USERNAME,
password: TEST_DB_PASSWORD,
database: TEST_DB_NAME,
host: TEST_DB_HOST,
dialect: 'postgres',
port: TEST_DB_PORT,
logging: false,
},
production: {
username: process.env.PROD_DB_USERNAME,
password: process.env.PROD_DB_PASSWORD,
database: process.env.PROD_DB_NAME,
host: process.env.PROD_DB_HOST,
dialect: "postgres",
port: process.env.PROD_DB_PORT,
username: PROD_DB_USERNAME,
password: PROD_DB_PASSWORD,
database: PROD_DB_NAME,
host: PROD_DB_HOST,
dialect: 'postgres',
port: PROD_DB_PORT,
logging: false,
},
};
4 changes: 2 additions & 2 deletions backend/package.json
Original file line number Diff line number Diff line change
@@ -5,8 +5,8 @@
"main": "index.js",
"scripts": {
"start": "node index.js",
"pretest": "NODE_ENV=test docker rm -f test-postgres || true && docker run --name test-postgres --env-file .env.test -p 5432:5432 -d postgres && npx wait-on tcp:5432 && npx sequelize-cli db:create --env test || true && npx sequelize-cli db:migrate --env test",
"posttest": "docker stop test-postgres && docker rm test-postgres",
"pretest": "bash pretest-script.sh",
"posttest": "bash posttest-script.sh",
"test": "NODE_ENV=test nyc mocha --extension js,mjs 'src/test/**/*.test.*'",
"test:e2e": "npm run pretest && NODE_ENV=test mocha 'src/test/e2e/**/*.test.mjs'",
"test:unit": "NODE_ENV=test mocha 'src/test/unit/**/*.test.js' --watch",
14 changes: 14 additions & 0 deletions backend/posttest-script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

# stop container
docker stop test-postgres

# remove container
docker rm -f test-postgres

# reset NODE_ENV to default
if [[ "$OSTYPE" == "msys" ]]; then
set NODE_ENV=development
else
export NODE_ENV=development
fi
27 changes: 27 additions & 0 deletions backend/pretest-script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

# set node env to test, if windows use set instead of export
if [[ "$OSTYPE" == "msys" ]]; then
set NODE_ENV=test
else
export NODE_ENV=test
fi

# remove test-postgres container if it exists
if [[ "$(docker ps -a -q -f name=test-postgres)" ]]; then
docker rm -f test-postgres
fi

# run test-postgres container
docker run --name test-postgres --env-file .env.test -p 5432:5432 -d postgres

# wait for postgres to start
npx wait-on tcp:5432

# create test database if it doesn't exist
if [[ ! "$(psql -U postgres -lqt | cut -d \| -f 1 | grep -w test_db)" ]]; then
npx sequelize-cli db:create --env test
fi

# run migrations
npx sequelize-cli db:migrate --env test