Skip to content

Commit c41c552

Browse files
Added dockerfile and fixed issues with packaging
1 parent da3aa95 commit c41c552

File tree

5 files changed

+51
-4
lines changed

5 files changed

+51
-4
lines changed

.dockerignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# If we don't include this it will be copied over with docker
2+
node_modules
3+
ts-built
4+
logs
5+
*.DS_Store
6+
tmp
7+
build
8+
package-outputs

Dockerfile

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
# The instructions for the first stage
3+
FROM node:14.15.3-alpine as builder
4+
5+
# set to production to run build
6+
#ARG NODE_ENV=development
7+
8+
# set working directory
9+
WORKDIR /app
10+
11+
# install app dependencies
12+
# package.json is copied over before source so that docker can appropriately use cache
13+
COPY package.json ./
14+
COPY package-lock.json ./
15+
RUN npm install --silent
16+
17+
# This would be a problem if node_modules wasn't docker ignored
18+
COPY . ./
19+
20+
# This would ordinarilly be run with npm install
21+
# However we don't copy over the schema file so it can't run this
22+
# We could copy this ahead of time with `COPY prisma ./` alongside the package.json but that would mess with cache
23+
RUN npx prisma generate
24+
25+
# Builds and creates the package, does not create an archive
26+
RUN REDERLY_PACKAGER_ARCHIVE=false npm run build:package
27+
28+
# The instructions for second stage
29+
FROM node:14.15.3-alpine
30+
31+
#WORKDIR /app
32+
COPY --from=builder /app/build ./rederly
33+
COPY --from=builder /app/.env ./rederly/
34+
35+
WORKDIR /rederly
36+
CMD npm run run:build

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"clean": "if [ -d ts-built ]; then rm -r ts-built; fi;",
1414
"lint": "eslint src/ --ext .ts",
1515
"build": "npm run clean && tsc",
16+
"run:build": "node ts-built/app-scripts/index.js",
1617
"package": "node ./utility-scripts/package.js",
1718
"build:package": "npm run build && npm run package"
1819
},

src/routes/index.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as express from 'express';
2+
import { Request, Response, NextFunction } from 'express';
23
import httpResponse from '../utilities/http-response';
34
const router = express.Router();
45
import { PrismaClient } from '@prisma/client';
@@ -24,7 +25,7 @@ const filterNaN = (arr: number[]) => _.filter(arr, _.negate(_.isNaN));
2425

2526
const getNumberArrayFromQuery = (value: string | string[] | undefined) => filterNaN(stringArrayToNumberArray(getQueryParamArray(value)));
2627

27-
router.get('/subjects', async (_req, _res, next) => {
28+
router.get('/subjects', async (_req: Request, _res: Response, next: NextFunction) => {
2829
try {
2930
const subjects = await prisma.opl_dbsubject.findMany();
3031
logger.debug(`Subject count: ${subjects.length}`);
@@ -36,7 +37,7 @@ router.get('/subjects', async (_req, _res, next) => {
3637
}
3738
});
3839

39-
router.get('/chapters', async (req, _res, next) => {
40+
router.get('/chapters', async (req: Request, _res: Response, next: NextFunction) => {
4041
const subjectId: number | undefined = getNumberArrayFromQuery(req.query.subjectId as string | string[] | undefined)[0];
4142

4243
try {
@@ -54,7 +55,7 @@ router.get('/chapters', async (req, _res, next) => {
5455
}
5556
});
5657

57-
router.get('/sections', async (req, _res, next) => {
58+
router.get('/sections', async (req: Request, _res: Response, next: NextFunction) => {
5859
const chapterId: number | undefined = getNumberArrayFromQuery(req.query.chapterId as string | string[] | undefined)[0];
5960

6061
try {
@@ -73,7 +74,7 @@ router.get('/sections', async (req, _res, next) => {
7374
});
7475

7576

76-
router.get('/search', async (req, _res, next) => {
77+
router.get('/search', async (req: Request, _res: Response, next: NextFunction) => {
7778
const subjectId: number | undefined = getNumberArrayFromQuery(req.query.subjectId as string | string[] | undefined)[0];
7879
const chapterId: number | undefined = getNumberArrayFromQuery(req.query.chapterId as string | string[] | undefined)[0];
7980
const sectionId: number | undefined = getNumberArrayFromQuery(req.query.sectionId as string | string[] | undefined)[0];

utility-scripts/package.js

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ console.log(`Starting to package project into ${destFile}`);
5757
recursive: true
5858
});
5959
const filesToCopy = [
60+
'prisma',
6061
builtDirectory,
6162
'package.json',
6263
'package-lock.json'

0 commit comments

Comments
 (0)