mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-10 01:43:43 +00:00
V2 docker (#312)
* Create docker-ci.yml * docker build * add build app * path changes * delete double workflow * update docker run template * cleanup * resolve wierd path issue * wrong path * again wrong path * rename docker releases * move styles population and change to function call * re-add old build pipeline * rename buld file * feractor init function * refactor: startDb to initAssets * refactor: startDB to initAssets * fix: docker.cjs building whole app * fix: docker environment * update docker paths * update: build command * cleanup * cleanup: commented code --------- Co-authored-by: Fabian Posenau <fabian@fphome.de>
This commit is contained in:
@@ -29,6 +29,7 @@ import { eventLoader } from './classes/event-loader/EventLoader.js';
|
||||
import { integrationService } from './services/integration-service/IntegrationService.js';
|
||||
import { logger } from './classes/Logger.js';
|
||||
import { oscIntegration } from './services/integration-service/OscIntegration.js';
|
||||
import { populateStyles } from './modules/loadStyles.js';
|
||||
|
||||
console.log(`Starting Ontime version ${ONTIME_VERSION}`);
|
||||
|
||||
@@ -95,19 +96,19 @@ app.use((error, response) => {
|
||||
|
||||
enum OntimeStartOrder {
|
||||
Error,
|
||||
InitDB,
|
||||
InitAssets,
|
||||
InitServer,
|
||||
InitIO,
|
||||
}
|
||||
|
||||
let step = OntimeStartOrder.InitDB;
|
||||
let step = OntimeStartOrder.InitAssets;
|
||||
let expressServer = null;
|
||||
let oscServer = null;
|
||||
|
||||
const checkStart = (currentState: OntimeStartOrder) => {
|
||||
if (step !== currentState) {
|
||||
step = OntimeStartOrder.Error;
|
||||
throw new Error('Init order error: startDb > startServer > startOsc > startIntegrations');
|
||||
throw new Error('Init order error: initAssets > startServer > startOsc > startIntegrations');
|
||||
} else {
|
||||
if (step === 1 || step === 2) {
|
||||
step = step + 1;
|
||||
@@ -115,9 +116,10 @@ const checkStart = (currentState: OntimeStartOrder) => {
|
||||
}
|
||||
};
|
||||
|
||||
export const startDb = async () => {
|
||||
checkStart(OntimeStartOrder.InitDB);
|
||||
export const initAssets = async () => {
|
||||
checkStart(OntimeStartOrder.InitAssets);
|
||||
await dbLoadingProcess;
|
||||
populateStyles();
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
export const config = {
|
||||
database: {
|
||||
testdb: 'test-db',
|
||||
directory: 'preloaded-db',
|
||||
directory: 'db',
|
||||
filename: 'db.json',
|
||||
tablename: 'events',
|
||||
},
|
||||
styles: {
|
||||
directory: 'styles',
|
||||
filename: 'override.css',
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
import { startDb, startIntegrations, startOSCServer, startServer } from './app.js';
|
||||
import { initAssets, startIntegrations, startOSCServer, startServer } from './app.js';
|
||||
|
||||
async function startOntime() {
|
||||
try {
|
||||
await startDb();
|
||||
console.log('Starting Ontime');
|
||||
console.log('Loading Assets');
|
||||
await initAssets();
|
||||
console.log('Starting Server');
|
||||
await startServer();
|
||||
console.log('Starting OSC Server');
|
||||
await startOSCServer();
|
||||
console.log('Starting Integrations');
|
||||
await startIntegrations();
|
||||
} catch (error) {
|
||||
console.log('Error starting Ontime');
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import { copyFileSync, existsSync } from 'fs';
|
||||
import { pathToStartStyles, resolveStylesDirectory, resolveStylesPath } from '../setup.js';
|
||||
import { ensureDirectory } from '../utils/fileManagement.js';
|
||||
import { reportSentryException } from './sentry.js';
|
||||
|
||||
/**
|
||||
* @description ensures directories exist and populates stylesheet
|
||||
* @return {string} - path to stylesheet file
|
||||
*/
|
||||
export const populateStyles = () => {
|
||||
const stylesInDisk = resolveStylesPath;
|
||||
ensureDirectory(resolveStylesDirectory);
|
||||
|
||||
// if stylesInDisk doesn't exist we want to use startup stylesheet
|
||||
if (!existsSync(stylesInDisk)) {
|
||||
try {
|
||||
copyFileSync(pathToStartStyles, stylesInDisk);
|
||||
} catch (error) {
|
||||
reportSentryException(error);
|
||||
}
|
||||
}
|
||||
|
||||
return stylesInDisk;
|
||||
};
|
||||
@@ -36,14 +36,24 @@ const env = process.env.NODE_ENV || 'production';
|
||||
|
||||
export const isTest = Boolean(process.env.IS_TEST);
|
||||
export const environment = isTest ? 'test' : env;
|
||||
export const isProduction = env === 'production' && !isTest;
|
||||
export const isProduction = env === ('production' || 'docker') && !isTest;
|
||||
export const isDocker = env === 'docker';
|
||||
|
||||
// =================================================
|
||||
// resolve path to external
|
||||
const productionPath = '../../Resources/extraResources/client';
|
||||
const devPath = '../../client/build/';
|
||||
const dockerPath = 'client/';
|
||||
|
||||
export const resolvedPath = (): string => (isProduction ? productionPath : devPath);
|
||||
export const resolvedPath = (): string => {
|
||||
if (isProduction) {
|
||||
return productionPath;
|
||||
}
|
||||
if (isDocker) {
|
||||
return dockerPath;
|
||||
}
|
||||
return devPath;
|
||||
};
|
||||
|
||||
// resolve file URL in both CJS and ESM (build and dev)
|
||||
if (import.meta.url) {
|
||||
@@ -61,4 +71,10 @@ export const resolveDbPath = join(resolveDbDirectory, config.database.filename);
|
||||
|
||||
export const pathToStartDb = isTest
|
||||
? join(currentDirectory, '../', config.database.testdb, config.database.filename)
|
||||
: join(currentDirectory, config.database.directory, config.database.filename);
|
||||
: join(currentDirectory, '/preloaded-db/', config.database.filename);
|
||||
|
||||
// path to public styles
|
||||
export const resolveStylesDirectory = join(appPath, config.styles.directory);
|
||||
export const resolveStylesPath = join(resolveStylesDirectory, config.styles.filename);
|
||||
|
||||
export const pathToStartStyles = join(currentDirectory, '/external/styles/', config.styles.filename);
|
||||
|
||||
Reference in New Issue
Block a user