Skip to content

Commit 84e6732

Browse files
committed
updated typeorm calls and added datasource needed to operate db calls.
1 parent 050fd34 commit 84e6732

25 files changed

+3886
-2494
lines changed

bulwark_base/Dockerfile

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,40 @@
22
# Maintained by Bill Jones
33

44
# Start from Alpine Linux for smaller footprint
5-
FROM alpine:3.12.0
5+
FROM alpine:latest
66

77
# Environmental Items
8-
ENV NODE_VERSION=14.17.0 \
9-
TYPESCRIPT_VERSION=4.0.2 \
10-
PUPPETEER_VERSION=5.2.1 \
8+
ENV NODE_VERSION=20.14.0 \
9+
TYPESCRIPT_VERSION=10.9.2 \
10+
PUPPETEER_VERSION=23.2.0 \
1111
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true \
1212
PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser
1313

1414
# View template at https://github.com/nodejs/docker-node/blob/master/Dockerfile-alpine.template
1515
# Setup Bulwark Container User
16-
RUN addgroup -S bulwark && adduser -S bulwark -G bulwark
16+
RUN addgroup -S bulwark && adduser -S bulwark -G bulwark -s /bin/sh -D bulwark
1717

1818
# Update Image
1919
RUN apk upgrade --no-cache -U
2020

2121
# Install Required Packages to Build NodeJS and Puppeter Items
22-
RUN apk add --no-cache curl make gcc g++ python3 linux-headers binutils-gold gnupg libstdc++ chromium \
22+
RUN apk add --no-cache --virtual .build-deps-full curl make gcc g++ python3 linux-headers binutils-gold gnupg libstdc++ chromium \
2323
fontconfig udev ttf-freefont fontconfig pango-dev libxcursor libxdamage cups-libs dbus-libs libxrandr \
24-
libxscrnsaver libc6-compat nss freetype freetype-dev harfbuzz ca-certificates
24+
libxscrnsaver libc6-compat nss freetype freetype-dev harfbuzz ca-certificates libgcc py-setuptools
2525

2626
# Ingest the GPG Keys from https://github.com/nodejs/node#release-keys
27-
RUN for server in pool.sks-keyservers.net keyserver.pgp.com ha.pool.sks-keyservers.net; do \
27+
RUN for server in keys.openpgp.org pool.sks-keyservers.net keyserver.pgp.com ha.pool.sks-keyservers.net; do \
2828
gpg --keyserver $server --recv-keys \
2929
4ED778F539E3634C779C87C6D7062848A1AB005C \
30-
94AE36675C464D64BAFA68DD7434390BDBE9B9C5 \
31-
71DCFD284A79C3B38668286BC97EC7A07EDE3FC1 \
30+
141F07595B7B3FFE74309A937405533BE57C7D57 \
31+
74F12602B6F1C4E913FAA37AD3A89613643B6201 \
32+
DD792F5973C6DE52C432CBDAC77ABFA00DDBF2B7 \
33+
CC68F5A3106FF448322E48ED27F5E38D5B0A215F \
3234
8FCCA13FEF1D0C2E91008E09770F7A9A5AE15600 \
33-
C4F0DFFF4E8C1A8236409D08E73BC641CC11F4C8 \
35+
890C08DB8579162FEE0DF9DB8BEAB4DFCF555EF4 \
3436
C82FA3AE1CBEDC6BE46B9360C43CEC45C17AB93C \
35-
DD8F2338BAE7501E3DD5AC78C273792F7D83545D \
36-
A48C2BEE680E841632CD4E44F07496B3EB3C1762 \
3737
108F52B48DB57BB0CC439B2997B01419BD92F80A \
38-
B9E2F5981AA6E0CD28160D9FF13993A75599653C && break; \
38+
A363A499291CBBC940DD62E41F10027AF002F8B0 && break; \
3939
done
4040

4141
# Perform nodejs installation
@@ -50,16 +50,15 @@ RUN curl -fsSLO --compressed "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE
5050
&& ./configure \
5151
&& make -j$(getconf _NPROCESSORS_ONLN) V= \
5252
&& make install \
53+
&& apk del .build-deps-full \
5354
&& cd .. \
5455
&& rm -Rf "node-v$NODE_VERSION" \
55-
&& rm "node-v$NODE_VERSION.tar.gz" SHASUMS256.txt.sig SHASUMS256.txt
56-
56+
&& rm "node-v$NODE_VERSION.tar.gz" SHASUMS256.txt.sig SHASUMS256.txt \
5757
# Cleanup
5858
RUN rm -f "node-v$NODE_VERSION" \
5959
# smoke tests
6060
&& node --version \
61-
&& npm --version
62-
61+
&& npm --version \
6362
# Setup for launch control of Bulwark
6463
WORKDIR /
6564
COPY bulwark-entrypoint /usr/local/bin/

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ services:
4646
&& npm run start"
4747
4848
bulwark-db:
49-
image: mysql:5.7.31
49+
image: mysql:9.0.1 # 7.7.31
5050
container_name: bulwark_db
5151
environment:
5252
MYSQL_DATABASE: '${DB_NAME}'

package-lock.json

Lines changed: 18 additions & 54 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "bulwark",
3-
"version": "7.3.0",
3+
"version": "8.0.0",
44
"description": "An organizational asset and vulnerability management tool",
55
"main": "index.js",
66
"scripts": {
7-
"test:node": "node_modules/.bin/jest --config=jest.config.js --collectCoverage --runInBand",
7+
"test:node": "node_modules/.bin/jest --config=jest.config.js --collectCoverage",
88
"test:front": "cd frontend && npm run-script test",
99
"test": "npm run-script test:node && npm run-script test:front",
1010
"start": "node dist/app.js",
@@ -17,11 +17,11 @@
1717
"postinstall": "rimraf dist && tsc && npm run config && npm run build:prod",
1818
"typeorm": "ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js",
1919
"docker:check": "node dist/init/docker-run-exec.js",
20-
"migration:run": "typeorm migration:run",
21-
"migration:init": "typeorm migration:generate -n CreateDatabase && rimraf dist && tsc",
22-
"migration:generate": "typeorm migration:generate -n Refactor && rimraf dist && tsc",
23-
"migration:create": "typeorm migration:create -n newInit && rimraf dist && tsc",
24-
"migration:revert": "typeorm migration:revert",
20+
"migration:run": "typeorm migration:run -d src/data-source.ts",
21+
"migration:init": "typeorm migration:generate -d src/data-source.ts CreateDatabase && rimraf dist && tsc",
22+
"migration:generate": "typeorm migration:generate -d src/data-source.ts Refactor && rimraf dist && tsc",
23+
"migration:create": "typeorm migration:create -d src/data-source.ts newInit && rimraf dist && tsc",
24+
"migration:revert": "typeorm migration:revert -d src/data-source.ts",
2525
"tsc": "rimraf dist && tsc",
2626
"lint": "tslint --project . && cd frontend && npm run-script lint",
2727
"lint:fix": "tslint --fix --project . && cd frontend && npm run-script lint --fix=true",
@@ -97,9 +97,9 @@
9797
"jira2md": "^3.0.1",
9898
"jsonwebtoken": "^9.0.2",
9999
"mime-types": "^2.1.35",
100-
"multer": "^1.4.4",
100+
"multer": "^1.4.5-lts.1",
101101
"mysql": "^2.18.1",
102-
"node-fetch": "^2.7.0",
102+
"node-fetch": "^2.6.7",
103103
"nodemailer": "^6.9.14",
104104
"password-validator": "^5.3.0",
105105
"prod": "^1.0.1",

src/app.ts

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,9 @@
11
import * as express from 'express';
22
import * as path from 'path';
3-
const fs = require('fs');
4-
const dotenv = require('dotenv');
5-
6-
if (fs.existsSync(path.join(__dirname, '../.env'))) {
7-
const envPath = fs.readFileSync(path.join(__dirname, '../.env'));
8-
// tslint:disable-next-line: no-console
9-
console.log('A .env file has been found and will now be parsed.');
10-
// https://github.com/motdotla/dotenv#what-happens-to-environment-variables-that-were-already-set
11-
const envConfig = dotenv.parse(envPath);
12-
if (envConfig) {
13-
for (const key in envConfig) {
14-
if (envConfig.hasOwnProperty(key)) {
15-
process.env[key] = envConfig[key];
16-
}
17-
}
18-
// tslint:disable-next-line: no-console
19-
console.log('The provided .env file has been parsed successfully.');
20-
}
21-
}
3+
import * as fs from 'fs';
4+
import * as dotenv from 'dotenv';
225
import * as bodyParser from 'body-parser';
23-
import { createConnection } from 'typeorm';
6+
import { AppDataSource } from './data-source';
247
const authController = require('./routes/authentication.controller');
258
import * as userController from './routes/user.controller';
269
const fileUploadController = require('./routes/file-upload.controller');
@@ -35,6 +18,9 @@ import * as teamController from './routes/team.controller';
3518
import * as apiKeyController from './routes/api-key.controller';
3619
const helmet = require('helmet');
3720
const cors = require('cors');
21+
22+
// Environment variables are loaded from .env file in data-source.ts
23+
3824
const app = express();
3925
app.use(cors());
4026
app.use(
@@ -64,16 +50,12 @@ const serverIpAddress = process.env.SERVER_ADDRESS || '127.0.0.1';
6450
app.set('port', serverPort);
6551
app.set('serverIpAddress', serverIpAddress);
6652
// tslint:disable-next-line: no-console
67-
app.listen(serverPort, () =>
68-
console.info(`Server running on ${serverIpAddress}:${serverPort}`)
69-
);
70-
// create typeorm connection
71-
createConnection().then((_) => {
72-
// tslint:disable-next-line: no-console
73-
console.info(`Database connection successful`);
74-
// Check for initial configuration and user
75-
// If none exist, insert
76-
configController.initialInsert();
53+
54+
// Initialize TypeORM connection
55+
AppDataSource.initialize()
56+
.then(async () => {
57+
console.info(`Database connection successful`);
58+
await configController.initialInsert();
7759

7860
// Protected Global Routes
7961
app.post(
@@ -364,4 +346,14 @@ createConnection().then((_) => {
364346
[jwtMiddleware.checkToken, jwtMiddleware.isAdmin],
365347
apiKeyController.deleteApiKeyAsAdmin
366348
);
349+
350+
// Start the server
351+
app.listen(serverPort, () =>
352+
console.info(`Server running on ${serverIpAddress}:${serverPort}`)
353+
);
354+
})
355+
.catch((error) => {
356+
console.error('Error during Data Source initialization:', error);
367357
});
358+
359+
export { app };

0 commit comments

Comments
 (0)