Skip to content

Commit

Permalink
Merge pull request #420 from openstad/codeimprovements/better-setup-a…
Browse files Browse the repository at this point in the history
…nd-seeds

Codeimprovements/better setup and seeds
  • Loading branch information
nlsvgtr authored May 23, 2024
2 parents 84385c1 + 3bee45f commit 625a65c
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 115 deletions.
101 changes: 68 additions & 33 deletions apps/api-server/seeds/development.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion apps/image-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node ./server.js",
"dev": "nodemon ./server.js"
"dev": "nodemon ./server.js",
"init-images": "node ./scripts/init-images.js"
},
"dependencies": {
"aws-sdk": "^2.1003.0",
Expand Down
50 changes: 0 additions & 50 deletions apps/image-server/scripts/init-database.js

This file was deleted.

29 changes: 29 additions & 0 deletions apps/image-server/scripts/init-images.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require('dotenv').config();
const fs = require('fs').promises;

(async () => {

try {

console.log('Init default images...');

try {

let files = await fs.readdir(`seeds/lorem-images`);
let targetDir = `${process.env.PWD}${process.env.IMAGES_DIR || '/images'}`;
for (let file of files) {
console.log(` ${file}`);
await fs.copyFile( `seeds/lorem-images/${file}`, `${targetDir}/${file}` );
}

} catch(err) {
console.log(err);
}

} catch (err) {
console.log(err);
} finally {
process.exit();
}

})();
18 changes: 0 additions & 18 deletions apps/image-server/scripts/migrate-database.js

This file was deleted.

3 changes: 0 additions & 3 deletions apps/image-server/scripts/predev.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
#!/bin/bash
if [ ! -f "./init/done" ]; then
npm run init-database && touch ./init/done;
fi
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ services:
restart: unless-stopped
environment:
- PORT=${CMS_PORT}
- OVERWRITE_URL=${CMS_URL}
- OVERWRITE_URL=${CMS_OVERWRITE_URL}
- MONGODB_URI=${CMS_MONGODB_URI}
- MESSAGESTREAMING_REDIS_URL=${MESSAGESTREAMING_REDIS_URL}
- MESSAGESTREAMING_POSTFIX=${MESSAGESTREAMING_POSTFIX}
Expand Down
18 changes: 10 additions & 8 deletions scripts/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ async function setupEnvVars() {
let BASIC_AUTH_USER = process.env.BASIC_AUTH_USER = process.env.BASIC_AUTH_USER || 'openstad';
let BASIC_AUTH_PASSWORD = process.env.BASIC_AUTH_PASSWORD = process.env.BASIC_AUTH_PASSWORD || 'openstad';

process.env.FORCE_HTTP = process.env.FORCE_HTTP || '';
let COOKIE_SECURE_OFF = process.env.FORCE_HTTP ? 'yes' : '';

process.env.BASE_DOMAIN = process.env.BASE_DOMAIN || 'localhost'

process.env.DB_HOST = process.env.DB_HOST || ''
process.env.DB_USERNAME = process.env.DB_USERNAME || 'openstad';
process.env.DB_PASSWORD = process.env.DB_PASSWORD || generateRandomToken({ length: 32 });
process.env.DB_BASE_NAME = process.env.DB_BASE_NAME || ''

process.env.MESSAGESTREAMING_REDIS_URL = process.env.MESSAGESTREAMING_REDIS_URL || '';

Expand Down Expand Up @@ -67,12 +70,12 @@ async function setupEnvVars() {
process.env.API_DB_NAME = process.env.API_DB_NAME || ( process.env.DB_BASE_NAME ? process.env.DB_BASE_NAME + '-api' : 'openstad-api' );
process.env.API_DB_DIALECT = process.env.API_DB_DIALECT || process.env.DB_DIALECT || 'mariadb';

process.env.API_FROM_EMAIL_ADDRESS = process.env.API_FROM_EMAIL_ADDRESS || process.env.FROM_EMAIL_ADDRESS;
process.env.API_FROM_EMAIL_ADDRESS = process.env.API_FROM_EMAIL_ADDRESS || process.env.FROM_EMAIL_ADDRESS || '';
process.env.API_SMTP_SECURE = process.env.API_SMTP_SECURE || process.env.SMTP_SECURE || false;
process.env.API_SMTP_PORT = process.env.API_SMTP_PORT || process.env.SMTP_PORT;
process.env.API_SMTP_HOST = process.env.API_SMTP_HOST || process.env.SMTP_HOST;
process.env.API_SMTP_USERNAME = process.env.API_SMTP_USERNAME || process.env.SMTP_USERNAME;
process.env.API_SMTP_PASSWORD = process.env.API_SMTP_PASSWORD || process.env.SMTP_PASSWORD;
process.env.API_SMTP_PORT = process.env.API_SMTP_PORT || process.env.SMTP_PORT || '';
process.env.API_SMTP_HOST = process.env.API_SMTP_HOST || process.env.SMTP_HOST || '';
process.env.API_SMTP_USERNAME = process.env.API_SMTP_USERNAME || process.env.SMTP_USERNAME || '';
process.env.API_SMTP_PASSWORD = process.env.API_SMTP_PASSWORD || process.env.SMTP_PASSWORD || '';

process.env.FROM_EMAIL_ADDRESS = process.env.FROM_EMAIL_ADDRESS || process.env.API_FROM_EMAIL_ADDRESS;
process.env.SMTP_SECURE = process.env.SMTP_SECURE || process.env.API_SMTP_SECURE || false;
Expand Down Expand Up @@ -117,9 +120,8 @@ async function setupEnvVars() {
process.env.AUTH_FIRST_CLIENT_SECRET = AUTH_FIRST_CLIENT_SECRET;
process.env.AUTH_FIRST_LOGIN_CODE = process.env.AUTH_FIRST_LOGIN_CODE || generateRandomToken({ length: 32 });


// KPN_CLIENT_ID=
// KPN_CLIENT_SECRET=
process.env.KPN_CLIENT_ID=process.env.KPN_CLIENT_ID || '';
process.env.KPN_CLIENT_SECRET=process.env.KPN_CLIENT_SECRET || '';

// image server
process.env.IMAGE_DOMAIN = IMAGE_DOMAIN || '';
Expand Down
1 change: 1 addition & 0 deletions scripts/setup-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ async function init() {
'create config': true,
'npm install': true,
'init database': true,
'init images': true,
'create certs': true,
'build': true,
}
Expand Down
9 changes: 8 additions & 1 deletion scripts/setup-image.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ APP_URL=${process.env.IMAGE_APP_URL}
PORT_API=${process.env.IMAGE_PORT_API}
PORT_IMAGE_SERVER=${process.env.IMAGE_PORT_IMAGE_SERVER}
IMAGES_DIR=${process.env.IMAGE_IMAGES_DIR || 'images'}
IMAGES_DIR=${process.env.IMAGE_IMAGES_DIR || '/images'}
IMAGE_VERIFICATION_TOKEN=${process.env.IMAGE_VERIFICATION_TOKEN}
THROTTLE=${process.env.IMAGE_THROTTLE}
THROTTLE_CC_PROCESSORS=${process.env.IMAGE_THROTTLE_CC_PROCESSORS}
Expand All @@ -36,6 +36,13 @@ THROTTLE_CC_REQUESTS=${process.env.IMAGE_THROTTLE_CC_REQUESTS}
console.log('Execute `npm i`');
await execute('npm', ['i'], { cwd: './apps/image-server' });
}

// init db
if (actions['init images']) {
console.log('------------------------------');
console.log('Init default images');
await execute('npm', ['run', 'init-images'], { cwd: './apps/image-server' });
}

} catch(err) {
console.log('------------------------------');
Expand Down

0 comments on commit 625a65c

Please sign in to comment.