Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
46 changes: 26 additions & 20 deletions libs/scully/src/lib/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,28 @@ import { cpus } from 'os';
export const angularRoot = findAngularJsonPath();
export const scullyConfig: ScullyConfig = {} as ScullyConfig;

export const scullyDefaults: Partial<ScullyConfig> = {
bareProject: false,
homeFolder: angularRoot,
outDir: join(angularRoot, './dist/static/'),
logFileSeverity: LogSeverity.warning,
inlineStateOnly: false,
thumbnails: false,
maxRenderThreads: cpus().length,
handle404: '',
appPort: /** 1864 */ 'herodevs'
.split('')
.reduce((sum, token) => (sum += token.charCodeAt(0)), 1000),
staticport: /** 1668 */ 'scully'
.split('')
.reduce((sum, token) => (sum += token.charCodeAt(0)), 1000),
reloadPort: /** 2667 */ 'scullyLiveReload'
.split('')
.reduce((sum, token) => (sum += token.charCodeAt(0)), 1000),
hostName: 'localhost',
defaultPostRenderers: [],
};

const loadIt = async () => {
const compiledConfig = await compileConfig();
let angularConfig = {} as any;
Expand All @@ -37,7 +59,7 @@ const loadIt = async () => {
compiledConfig.projectName
)}" in 'angular.json'.`
);
process.exit(15);
// process.exit(15);
}

if (compiledConfig.hostUrl && compiledConfig.hostUrl.endsWith('/')) {
Expand All @@ -46,34 +68,18 @@ const loadIt = async () => {
compiledConfig.hostUrl.length - 1
);
}

// TODO: update types in interfacesandenums to force correct types in here.
// tslint:disable-next-line: no-unused-expression
Object.assign(
scullyConfig,
/** the default config */
scullyDefaults,
/** calculated defaults. */
{
bareProject: false,
homeFolder: angularRoot,
outDir: join(angularRoot, './dist/static/'),
sourceRoot: projectConfig.sourceRoot,
projectRoot: projectConfig.root,
distFolder,
logFileSeverity: LogSeverity.warning,
inlineStateOnly: false,
tumbnails: false,
maxRenderThreads: cpus().length,
handle404: '',
appPort: /** 1864 */ 'herodevs'
.split('')
.reduce((sum, token) => (sum += token.charCodeAt(0)), 1000),
staticport: /** 1668 */ 'scully'
.split('')
.reduce((sum, token) => (sum += token.charCodeAt(0)), 1000),
reloadPort: /** 2667 */ 'scullyLiveReload'
.split('')
.reduce((sum, token) => (sum += token.charCodeAt(0)), 1000),
hostName: 'localhost',
defaultPostRenderers: [],
}
) as ScullyConfig;
/** activate loaded config */
Expand Down
27 changes: 13 additions & 14 deletions libs/scully/src/lib/utils/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,24 @@ import { loadConfig, scullyConfig } from '../utils/config';
export const orange = chalk.hex('#FFA500');
export const { white, red, yellow, green }: { [x: string]: any } = chalk;

export enum LogSeverity {
export const enum LogSeverity {
normal,
warning,
error,
none,
}

const logToFile = loadConfig
.then(() => (string) => {
return new Promise((res, rej) =>
appendFile(join(scullyConfig.homeFolder, 'scully.log'), string, (e) =>
e ? rej(e) : res
)
);
})
.then((file) => {
/** inject a couple of newlines to indicate new run */
return file;
});
const logToFile = Promise.resolve((string) => {
return new Promise((res, rej) =>
appendFile(join(__dirname, '../../', 'scully.log'), string, (e) =>
e ? rej(e) : res
)
);
}).then((file) => {
/** inject a couple of newlines to indicate new run */
return file;
});

export const log = (...a) => enhancedLog(white, LogSeverity.normal, ...a);
export const logError = (...a) => enhancedLog(red, LogSeverity.error, ...a);
export const logWarn = (...a) => enhancedLog(orange, LogSeverity.warning, ...a);
Expand All @@ -43,7 +42,7 @@ function enhancedLog(colorFn, severity: LogSeverity, ...args: any[]) {
})
.catch((e) => {
/** silently ignore log errors */
console.log('log error', e);
// console.log('log error', e)
});
console.log(colorFn(...out));
}
Expand Down
29 changes: 22 additions & 7 deletions libs/scully/src/scully.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import open from 'open';
import { join } from 'path';
import './lib/pluginManagement/systemPlugins';
import { startBackgroundServer } from './lib/startBackgroundServer';
import { waitForServerToBeAvailable } from './lib/utils';
import { waitForServerToBeAvailable, ScullyConfig } from './lib/utils';
import * as cliOption from './lib/utils/cli-options';
import { ssl } from './lib/utils/cli-options';
import { loadConfig } from './lib/utils/config';
import { loadConfig, scullyDefaults } from './lib/utils/config';
import { moveDistAngular } from './lib/utils/fsAngular';
import { httpGetJson } from './lib/utils/httpGetJson';
import { logError, logWarn, yellow } from './lib/utils/log';
Expand All @@ -31,11 +31,18 @@ if (process.argv.includes('version')) {

(async () => {
/** make sure not to do something before the config is ready */
const scullyConfig = await loadConfig;
if (cliOption.hostName) {
scullyConfig.hostName = cliOption.hostName;
let scullyConfig: ScullyConfig;
let err;
/** load the config, and use the defaults when there is an error */
try {
scullyConfig = await loadConfig;
} catch (e) {
scullyConfig = scullyDefaults as ScullyConfig;
/** store the error */
err = e;
}
if (cliOption.killServer) {
/** do we need to kill something? */
if (process.argv.includes('killServer')) {
await httpGetJson(
`http://${scullyConfig.hostName}:${scullyConfig.appPort}/killMe`,
{
Expand All @@ -50,7 +57,15 @@ if (process.argv.includes('version')) {
).catch((e) => e);
logWarn('Sent kill command to server');
process.exit(0);
return;
}

if (err) {
/** exit due to severe error during config parsing */
process.exit(15);
}

if (cliOption.hostName) {
scullyConfig.hostName = cliOption.hostName;
}
await isBuildThere(scullyConfig);

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"server:testDocs": "npm run server:docs &",
"server:sample": "npm run scully -- --project sample-blog --tds serve ",
"server:docs": "npm run scully -- --project scully-docs --tds serve ",
"server:kill": "npm run scully -- --project scully-docs killServer ",
"server:kill": "npm run scully -- killServer ",
"e2e": "nx e2e",
"docs": "run-s server:kill build:code symlinks build:docs deploy:docs",
"deploy:docs": "echo No deploy script yet",
Expand Down
85 changes: 85 additions & 0 deletions tools/docker/chromium-base.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
FROM ubuntu:20.04


# Dependencies + NodeJS
RUN apt-get -qq update && \
echo "ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true" | debconf-set-selections && \
apt-get -y -qq install software-properties-common &&\
apt-add-repository "deb http://archive.canonical.com/ubuntu $(lsb_release -sc) partner" && \
apt-get -qq update && apt-get -y -qq --no-install-recommends install \
dumb-init \
adobe-flashplugin \
git \
ffmpeg \
msttcorefonts \
fonts-roboto \
fonts-ubuntu \
fonts-noto-color-emoji \
fonts-noto-cjk \
fonts-ipafont-gothic \
fonts-wqy-zenhei \
fonts-kacst \
fonts-freefont-ttf \
fonts-thai-tlwg \
fonts-indic \
fontconfig \
libappindicator3-1 \
pdftk \
unzip \
locales \
gconf-service \
libasound2 \
libatk1.0-0 \
libc6 \
libcairo2 \
libcups2 \
libdbus-1-3 \
libexpat1 \
libfontconfig1 \
libgcc1 \
libgconf-2-4 \
libgdk-pixbuf2.0-0 \
libglib2.0-0 \
libgtk-3-0 \
libnspr4 \
libpango-1.0-0 \
libpangocairo-1.0-0 \
libstdc++6 \
libx11-6 \
libx11-xcb1 \
libxcb1 \
libxcomposite1 \
libxcursor1 \
libxdamage1 \
libxext6 \
libxfixes3 \
libxi6 \
libxrandr2 \
libxrender1 \
libxss1 \
libxtst6 \
libllvm8 \
libgbm-dev \
ca-certificates \
libappindicator1 \
libnss3 \
lsb-release \
xdg-utils \
wget \
xvfb \
curl &&\
curl --silent --location https://deb.nodesource.com/setup_13.x | bash - &&\
apt-get -y -qq install nodejs &&\
apt-get -y -qq install build-essential &&\
fc-cache -f -v

# Add the browserless user (blessuser)
RUN groupadd -r blessuser && useradd -r -g blessuser -G audio,video blessuser \
&& mkdir -p /home/blessuser/Downloads \
&& chown -R blessuser:blessuser /home/blessuser

# Install deps necessary to build
RUN npm install -g typescript @types/node

# Cleanup
RUN apt-get -qq clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
55 changes: 55 additions & 0 deletions tools/docker/pupeteer.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
FROM chromium-base:latest

# Build Args
ARG USE_CHROME_STABLE
ARG PUPPETEER_CHROMIUM_REVISION
ARG PUPPETEER_VERSION

# Application parameters and variables
ENV APP_DIR=/usr/src/app
ENV CONNECTION_TIMEOUT=60000
ENV CHROME_PATH=/usr/bin/google-chrome
ENV HOST=0.0.0.0
ENV IS_DOCKER=true
ENV LANG="C.UTF-8"
ENV NODE_ENV=production
ENV PORT=3000
ENV PUPPETEER_CHROMIUM_REVISION=${PUPPETEER_CHROMIUM_REVISION}
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
ENV USE_CHROME_STABLE=${USE_CHROME_STABLE}
ENV WORKSPACE_DIR=$APP_DIR/workspace

RUN mkdir -p $APP_DIR $WORKSPACE_DIR

WORKDIR $APP_DIR

# Install app dependencies
COPY package.json .
COPY tsconfig.json .
COPY . .

# Install Chrome Stable when specified
RUN if [ "$USE_CHROME_STABLE" = "true" ]; then \
cd /tmp &&\
wget -q https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb &&\
dpkg -i google-chrome-stable_current_amd64.deb;\
fi

# Build and install external binaries + assets
RUN if [ "$USE_CHROME_STABLE" = "true" ]; then \
export CHROMEDRIVER_SKIP_DOWNLOAD=false;\
else \
export CHROMEDRIVER_SKIP_DOWNLOAD=true;\
fi &&\
npm i puppeteer@$PUPPETEER_VERSION;\
npm run post-install &&\
npm run build &&\
chown -R blessuser:blessuser $APP_DIR

# Run everything after as non-privileged user.
USER blessuser

# Expose the web-socket and HTTP ports
EXPOSE 3000

CMD ["./start.sh"]