Skip to content

Commit

Permalink
fixed more build things - added a precheck to check env and migration…
Browse files Browse the repository at this point in the history
…s. renamed pm2.json to ecosystem.config.js
  • Loading branch information
kamiyo committed Aug 9, 2022
1 parent e8ec771 commit bc020d6
Show file tree
Hide file tree
Showing 65 changed files with 1,075 additions and 196 deletions.
629 changes: 523 additions & 106 deletions .pnp.cjs

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
8 changes: 8 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,11 @@ supportedArchitectures:
- win32

yarnPath: .yarn/releases/yarn-3.2.2.cjs

packageExtensions:
stylelint-config-recommended-scss@*:
peerDependencies:
postcss: "*"
stylelint-config-standard-scss@*:
peerDependencies:
postcss: "*"
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ STRIPE_PUBLIC_KEY=<from stripe dashboard, only for dev to build app>
STRIPE_WEBHOOK_KEY=<from stripe dashboard>
PRODUCTS_DIR=<absolute path to emailable assets>
SEED_DATA_DIR=<absolute path to seeding data, only for first run of database>
IMAGE_ASSETS_DIR=<absolute path to image assets folder>
MUSIC_ASSETS_DIR=<absolute path to music assets folder>
IMAGE_ASSETS_DIR=<absolute path to image assets folder, only for dev>
MUSIC_ASSETS_DIR=<absolute path to music assets folder, only for dev>
SMTP_HOST=<smtp server>
SMTP_PORT=<465, 587, or 25>
SMTP_USERNAME=<smtp user>
Expand Down
13 changes: 13 additions & 0 deletions ecosystem.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
apps: [
{
name: "sycpiano",
script: "yarn",
args: "start",
env: {
NODE_ENV: "production",
},
log_date_format: "YYYY-MM-DD HH:mm Z"
}
]
}
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"license": "MIT",
"author": "Sean Chen, Andrew Chen, and Jason Chen",
"scripts": {
"build": "yarn buildServer && yarn buildApp",
"build": "trash server/build && yarn buildServer && yarn buildApp",
"buildApp": "webpack --config webpack.prod.config.js",
"buildServer": "cd server && swc src -d build",
"dev": "ts-node scripts/devWatch.ts",
Expand All @@ -23,8 +23,8 @@
"watchServer": "cd server && cross-env NODE_ENV=development swc src -d build -w",
"windowsDev": "powershell contrib/dev.ps1",
"bundle": "run-script-os",
"bundle:win32": "del yarn.lock && del sycpiano.zip && yarn cache clean && yarn workspaces focus --production && git archive --format=zip --output ./sycpiano.zip main && 7z a -r sycpiano.zip web/build server/build",
"bundle:linux": "rm yarn.lock && rm sycpiano.zip && yarn cache clean && yarn workspaces focus --production && git archive --format=zip --output ./sycpiano.zip main && zip -r sycpiano.zip web/build server/build"
"bundle:win32": "del sycpiano.zip && git archive --format=zip --output ./sycpiano.zip main && 7z a -r sycpiano.zip web/build server/build",
"bundle:linux": "rm sycpiano.zip && git archive --format=zip --output ./sycpiano.zip main && zip -r sycpiano.zip web/build server/build"
},
"resolutions": {
"@pm2/agent/ws": "^7.5.8",
Expand Down Expand Up @@ -192,6 +192,7 @@
"stylelint-custom-processor-loader": "^0.6.0",
"stylelint-formatter-pretty": "^3.1.0",
"stylelint-processor-styled-components": "^1.10.0",
"trash-cli": "^5.0.0",
"ts-node": "^10.8.2",
"typescript": "^4.7.4",
"webpack": "^5.73.0",
Expand Down
14 changes: 0 additions & 14 deletions pm2.json

This file was deleted.

11 changes: 7 additions & 4 deletions server/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ import * as cookieParser from 'cookie-parser';
import * as csurf from 'csurf';
import * as cors from 'cors';
import * as rootPath from 'app-root-path';
import { precheck } from './precheck';

const main = async () => {
await precheck();

const isProduction = process.env.NODE_ENV === 'production';

if (!process.env.PORT) {
throw new Error('No port number specified in environmental variables');
throw Error('No port number specified in environmental variables');
}
const port = parseInt(process.env.PORT, 10);

Expand Down Expand Up @@ -111,7 +114,7 @@ const main = async () => {
// prod uses nginx to serve static files
if (!isProduction) {
if (!process.env.MUSIC_ASSETS_DIR || !process.env.IMAGE_ASSETS_DIR) {
throw new Error('Necessary environmental variables not found');
throw Error('Necessary environmental variables not found');
}
app.use('/static/music', express.static(path.resolve(rootPath.toString(), process.env.MUSIC_ASSETS_DIR)));
app.use('/static/images', express.static(path.resolve(rootPath.toString(), process.env.IMAGE_ASSETS_DIR)));
Expand Down Expand Up @@ -146,7 +149,7 @@ const main = async () => {
};

if (!process.env.COOKIE_SECRET) {
throw new Error('No cookie secret specified in environmental variables.');
throw Error('No cookie secret specified in environmental variables.');
}
const adminMiddlewares = [
cors(corsOptions),
Expand All @@ -165,7 +168,7 @@ const main = async () => {
app.use(/\/resized/, Resized);

if (!process.env.ADMIN_PORT) {
throw new Error('No admin port specified in environmental variables.');
throw Error('No admin port specified in environmental variables.');
}
// Admin
app.use(
Expand Down
4 changes: 2 additions & 2 deletions server/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ const config = () => {
} else {
username = process.env.DB_USER;
password = process.env.DB_PASS;
host = process.env.DB_HOST;
host = process.env.DB_HOST || '127.0.0.1';
database = process.env.DB_NAME;
port = parseInt(process.env.DB_PORT, 10);
port = parseInt(process.env.DB_PORT || '5432', 10);
}
return {
username,
Expand Down
6 changes: 4 additions & 2 deletions server/src/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { SequelizeStorage, Umzug } from 'umzug';

import sequelize from './sequelize';

const umzug = new Umzug({
export const umzug = new Umzug({
storage: new SequelizeStorage({
sequelize,
modelName: 'migrations',
Expand All @@ -29,4 +29,6 @@ const umzug = new Umzug({
logger: console,
});

umzug.runAsCLI();
if (require.main === module) {
umzug.runAsCLI();
}
44 changes: 44 additions & 0 deletions server/src/precheck.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import * as dotenv from 'dotenv';
import { umzug } from './migrate';

dotenv.config();

const required = [
'PORT',
'ADMIN_PORT',
'HOST',
'GAPI_KEY_SERVER',
'STRIPE_SECRET_KEY',
'STRIPE_WEBHOOK_KEY',
'COOKIE_SECRET',
'PRODUCTS_DIR',
'IMAGE_ASSETS_DIR',
'MUSIC_ASSETS_DIR',
'DKIM_PRIVATE_KEY_FILE',
'SMTP_HOST',
'SMTP_PORT',
'SMTP_USERNAME',
'SMTP_PASSWORD'
]

export const precheck = async () => {
// Check DB stuff
if (!process.env.DB_URL) {
const dbRequired = ['DB_USER', 'DB_PASS'];
dbRequired.forEach((key) => {
const value = process.env[key];
if (!value) {
throw Error(`${key} is not defined, nor DB_URL`);
}
});
}
required.forEach((key) => {
const value = process.env[key];
if (!value) {
throw Error(`${key} is not defined.`);
}
});

// run migrations!
await umzug.up();
};
8 changes: 8 additions & 0 deletions webpack.common.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
require('dotenv').config();

if (!process.env.STRIPE_PUBLIC_KEY) {
throw Error('STRIPE_PUBLIC_KEY not defined');
}

if (!process.env.GAPI_KEY_APP) {
throw Error('GAPI_KEY_APP not defined');
}

const staticPrefix = '/static';

const sourcePaths = [
Expand Down
Loading

0 comments on commit bc020d6

Please sign in to comment.