Skip to content

Commit

Permalink
[integration] Fix tests and standalone build
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Hassine committed Mar 4, 2022
1 parent 1e1e4e3 commit 13b3295
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 3 deletions.
4 changes: 2 additions & 2 deletions opencti-platform/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ COPY opencti-front/patch ./patch
RUN yarn install
COPY opencti-front /opt/opencti-build/opencti-front
COPY opencti-graphql/config/schema/opencti.graphql /opt/opencti-build/opencti-graphql/config/schema/opencti.graphql
RUN yarn build
RUN yarn build:standalone


FROM base AS app
Expand All @@ -48,7 +48,7 @@ RUN pip3 install --upgrade --force --no-cache-dir git+https://github.com/OpenCTI
RUN apk del git python3-dev gcc musl-dev
COPY --from=graphql-deps-builder /opt/opencti-build/opencti-graphql/node_modules ./node_modules
COPY --from=graphql-builder /opt/opencti-build/opencti-graphql/build ./build
COPY --from=front-builder /opt/opencti-build/opencti-front/build ./public
COPY --from=front-builder /opt/opencti-build/opencti-front/builder/prod/build ./public
COPY opencti-graphql/src ./src
COPY opencti-graphql/config ./config
COPY opencti-graphql/script ./script
Expand Down
69 changes: 69 additions & 0 deletions opencti-platform/opencti-front/builder/prod/prod-keepfiles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
const esbuild = require("esbuild");
const { RelayPlugin } = require("../plugin/esbuild-relay");
const fsExtra = require("fs-extra");
const fs = require("fs");

const buildPath = "./builder/prod/build/";
esbuild
.build({
logLevel: "info",
plugins: [RelayPlugin],
entryPoints: ["src/index.tsx"],
bundle: true,
loader: {
".js": "jsx",
".svg": "file",
".png": "file",
".woff": "dataurl",
".woff2": "dataurl",
".ttf": "dataurl",
".eot": "dataurl",
},
assetNames: "static/media/[name]-[hash]",
entryNames: "static/[ext]/opencti-[hash]",
target: ["chrome58"],
minify: true,
keepNames: false,
sourcemap: false,
sourceRoot: "src",
sourcesContent: false,
outdir: "builder/prod/build",
incremental: false,
})
.then(() => {
// Copy file
fsExtra.copySync("./builder/public/", buildPath, {
recursive: true,
overwrite: true,
});
// Generate index.html
const cssStaticFiles = fs.readdirSync(buildPath + "static/css");
const cssLinks = cssStaticFiles.map(
(f) => `<link href="%BASE_PATH%/static/css/${f}" rel="stylesheet">`
);
const cssImport = cssLinks.join("\n");
const jsStaticFiles = fs.readdirSync(buildPath + "static/js");
const jsLinks = jsStaticFiles.map(
(f) => `<script defer="defer" src="%BASE_PATH%/static/js/${f}"></script>`
);
const jsImport = jsLinks.join("\n");
const indexHtml = `
<!doctype html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<link rel="shortcut icon" href="%BASE_PATH%/static/favicon.png">
<script>window.BASE_PATH = "%BASE_PATH%"</script>
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>OpenCTI - Cyber Threat Intelligence Platform</title>
${jsImport}
${cssImport}
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
</body>
</html>`;
fs.writeFileSync(buildPath + "index.html", indexHtml);
});
2 changes: 2 additions & 0 deletions opencti-platform/opencti-front/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,10 @@
},
"scripts": {
"esbuild": "node builder/prod/prod.js",
"esbuild:keep-files": "node builder/prod/prod-keepfiles.js",
"relay": "relay-compiler",
"build": "yarn relay && yarn esbuild",
"build:standalone": "yarn relay && yarn esbuild:keep-files",
"start": "yarn relay && node builder/dev/dev.js",
"lint": "cross-env DEBUG=eslint:cli-engine TIMING=1 eslint --max-warnings 0 --cache -c .eslintrc.json src",
"control": "yarn audit --groups dependencies --summary",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('Settings resolver standard behavior', () => {
expect(queryResult).not.toBeNull();
const { about } = queryResult.data;
expect(about).not.toBeNull();
expect(about.version).toContain('5.2.0');
expect(about.version).toContain('5.2.1');
expect(about.dependencies.length).toEqual(3);
});
it('should settings information', async () => {
Expand Down

0 comments on commit 13b3295

Please sign in to comment.