Adding some docker setup for local testing

This commit is contained in:
Collin Duncan 2022-11-21 18:50:59 +01:00
parent e039c3d5a8
commit 5cdbc3ebb0
No known key found for this signature in database
8 changed files with 175 additions and 1222 deletions

View file

@ -5,3 +5,10 @@ services:
env_file: ./database/.env
ports:
- 3306:3306
http:
build:
context: ..
dockerfile: ./docker/server/Dockerfile
restart: always
env_file: ./server/.env

26
docker/server/Dockerfile Normal file
View file

@ -0,0 +1,26 @@
FROM node:18-alpine as builder
WORKDIR /app
RUN apk add chromium gcc
RUN npm i -g node-gyp
COPY package.json package.json
COPY package-lock.json package-lock.json
RUN CXX=g++-12 npm install argon2
RUN npm install
COPY src src
COPY tsconfig.json tsconfig.json
RUN npm run build
#------------------------------------------------------------------------------
FROM node:18-alpine as app
WORKDIR /app
COPY --from=builder /app/dist dist
ENTRYPOINT node dist/server/index.cjs

1321
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -16,7 +16,9 @@
"test:clean": "npm run test:clear-cache && npm run test",
"lint": "eslint src/ --ext ts",
"prettier": "prettier src tests -w",
"local": "npx ts-node src/local.ts"
"local": "npx ts-node src/local.ts",
"docker:start": "docker compose -f docker/docker-compose.yml up",
"docker:stop": "docker compose -f docker/docker-compose.yml down"
},
"author": "Collin Duncan",
"license": "ISC",
@ -35,12 +37,11 @@
"@types/mysql": "^2.15.21",
"@types/puppeteer": "^5.4.7",
"@types/uuid": "^8.3.4",
"@typescript-eslint/eslint-plugin": "^5.40.1",
"@typescript-eslint/parser": "^5.40.1",
"@typescript-eslint/eslint-plugin": "^5.42.0",
"@typescript-eslint/parser": "^5.42.0",
"babel-jest": "^29.2.1",
"eslint": "^8.26.0",
"eslint": "^8.27.0",
"jest": "^29.2.1",
"node-gyp": "^9.3.0",
"prettier": "^2.7.1",
"rollup": "^3.2.5",
"rollup-plugin-natives": "^0.7.6",

View file

@ -1,15 +1,19 @@
import mysql, { Connection, ConnectionConfig, FieldInfo } from 'mysql'
import { readFile } from 'fs/promises'
import { resolve } from 'path'
import { TABLE_reservations } from './sql'
const createConnectionConfig = async (): Promise<ConnectionConfig> => {
const user = await readFile(resolve('.', './secrets/dbUser'))
const password = await readFile(resolve('.', './secrets/dbPassword'))
const user = process.env.MYSQL_USER
const password = process.env.MYSQL_PASSWORD
const database = process.env.MYSQL_DATABASE
if (!user || !password || !database) {
throw new DatabaseEnvironmentError(
'Required environment variables are missing'
)
}
return {
user: user.toString(),
password: password.toString(),
database: 'autobaan',
user,
password,
database,
}
}
@ -73,3 +77,6 @@ export const init = async () => {
console.error(err)
}
}
export class DatabaseError extends Error {}
export class DatabaseEnvironmentError extends DatabaseError {}

View file

@ -3,6 +3,8 @@ import isSameOrBefore from 'dayjs/plugin/isSameOrBefore'
import { query } from './database'
dayjs.extend(isSameOrBefore)
const RESERVATION_AVAILABLE_WITHIN_DAYS = 7
export interface User {
username: string
password: string
@ -18,8 +20,6 @@ export interface DateRange {
end: dayjs.Dayjs
}
const RESERVATION_AVAILABLE_WITHIN_DAYS = 7
export class Reservation {
public readonly user: User
public readonly dateRange: DateRange

View file

@ -1,6 +1,7 @@
import http from 'http'
import { Readable } from 'stream'
import { v4 } from 'uuid'
import { disconnect } from '../common/database'
import { Logger, LogLevel } from '../common/logger'
import { work as schedule } from '../workers/scheduler'
@ -14,6 +15,10 @@ process.on('uncaughtException', (error, origin) => {
Logger.error('uncaught exception', { error, origin })
})
process.on('beforeExit', async () => {
await disconnect()
})
const parseJson = async <T extends Record<string, unknown>>(
length: number,
encoding: BufferEncoding,

View file

@ -21,7 +21,7 @@ export default {
dlopen: false,
sourcemap: true,
}),
nodeResolve(),
commonjs(),
nodeResolve(),
],
}