Removing rollup and relying on tsc to make builds. Also updated Docker to have a working development version
This commit is contained in:
parent
9f59e60901
commit
dfcb1f25a1
10 changed files with 331 additions and 1954 deletions
|
|
@ -46,4 +46,4 @@ npm run local <username> <password> <year> <month> <day> <startTime> <endTime> <
|
|||
|==========| |
|
||||
| Database |<---------------------------|
|
||||
|==========|
|
||||
```
|
||||
```
|
||||
|
|
|
|||
|
|
@ -3,12 +3,22 @@ services:
|
|||
image: mysql:latest
|
||||
restart: always
|
||||
env_file: ./database/.env
|
||||
command: --default-authentication-plugin=mysql_native_password
|
||||
ports:
|
||||
- 3306:3306
|
||||
healthcheck:
|
||||
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
|
||||
timeout: 20s
|
||||
retries: 10
|
||||
|
||||
http:
|
||||
build:
|
||||
context: ..
|
||||
dockerfile: ./docker/server/Dockerfile
|
||||
restart: always
|
||||
env_file: ./server/.env
|
||||
env_file: ./server/.env
|
||||
ports:
|
||||
- 3000:3000
|
||||
depends_on:
|
||||
database:
|
||||
condition: service_healthy
|
||||
|
|
@ -1,8 +1,9 @@
|
|||
FROM node:18-alpine as builder
|
||||
FROM node:18
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
RUN apk add chromium gcc
|
||||
RUN apt update
|
||||
RUN apt install -y chromium gcc
|
||||
RUN npm i -g node-gyp
|
||||
|
||||
COPY package.json package.json
|
||||
|
|
@ -15,12 +16,4 @@ 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
|
||||
ENTRYPOINT node dist/server/index.js
|
||||
2146
package-lock.json
generated
2146
package-lock.json
generated
File diff suppressed because it is too large
Load diff
15
package.json
15
package.json
|
|
@ -1,7 +1,6 @@
|
|||
{
|
||||
"name": "autobaan",
|
||||
"version": "1.0.0",
|
||||
"type": "module",
|
||||
"description": "",
|
||||
"private": true,
|
||||
"engines": {
|
||||
|
|
@ -10,7 +9,8 @@
|
|||
"scripts": {
|
||||
"preinstall": "export CXX=g++-12",
|
||||
"clean": "rm -r ./dist || true",
|
||||
"build": "rollup -c src/server/rollup.config.js",
|
||||
"prebuild": "npm run clean",
|
||||
"build": "tsc",
|
||||
"test": "jest",
|
||||
"test:unit": "jest tests/unit/*",
|
||||
"test:unit:clean": "npm run test:clear-cache && npm run test:unit",
|
||||
|
|
@ -19,14 +19,14 @@
|
|||
"test:clear-cache": "jest --clearCache",
|
||||
"lint": "eslint src/ --ext ts",
|
||||
"prettier": "prettier src tests -w",
|
||||
"local": "npx ts-node src/local.ts",
|
||||
"local": "npx ts-node src/local/index.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",
|
||||
"dependencies": {
|
||||
"argon2": "^0.30.1",
|
||||
"argon2": "^0.30.3",
|
||||
"axios": "^1.2.0",
|
||||
"dayjs": "^1.11.6",
|
||||
"mysql": "^2.18.1",
|
||||
|
|
@ -35,9 +35,6 @@
|
|||
"uuid": "^9.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@rollup/plugin-commonjs": "^23.0.2",
|
||||
"@rollup/plugin-node-resolve": "^15.0.1",
|
||||
"@rollup/plugin-typescript": "^9.0.2",
|
||||
"@types/jest": "^29.2.3",
|
||||
"@types/mysql": "^2.15.21",
|
||||
"@types/node": "^18.11.9",
|
||||
|
|
@ -50,9 +47,7 @@
|
|||
"eslint": "^8.27.0",
|
||||
"jest": "^29.2.1",
|
||||
"prettier": "^2.7.1",
|
||||
"rollup": "^3.2.5",
|
||||
"rollup-plugin-natives": "^0.7.6",
|
||||
"ts-jest": "^29.0.3",
|
||||
"typescript": "^4.8.4"
|
||||
"typescript": "^4.9.4"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
27
src/index.ts
27
src/index.ts
|
|
@ -1,27 +0,0 @@
|
|||
import { connect, disconnect } from './common/database'
|
||||
import { Logger } from './common/logger'
|
||||
import server from './server/http'
|
||||
import { startTasks, stopTasks } from './server/cron'
|
||||
|
||||
process.on('unhandledRejection', (reason) => {
|
||||
Logger.error('unhandled rejection', { reason })
|
||||
})
|
||||
|
||||
process.on('uncaughtException', (error, origin) => {
|
||||
Logger.error('uncaught exception', { error, origin })
|
||||
})
|
||||
|
||||
process.on('beforeExit', async () => {
|
||||
await disconnect()
|
||||
stopTasks()
|
||||
})
|
||||
|
||||
const port = process.env.SERVER_PORT || 3000
|
||||
|
||||
startTasks()
|
||||
|
||||
server.listen(port, async () => {
|
||||
Logger.info('server ready and listening', { port })
|
||||
await connect()
|
||||
Logger.info('database connection established')
|
||||
})
|
||||
|
|
@ -1,11 +1,8 @@
|
|||
import dayjs from 'dayjs'
|
||||
import { v4 } from 'uuid'
|
||||
import { Logger, LogLevel } from './common/logger'
|
||||
import { Reservation } from './common/reservation'
|
||||
import { Runner } from './common/runner'
|
||||
import { Reservation } from '../common/reservation'
|
||||
import { Runner } from '../common/runner'
|
||||
|
||||
const run = async (request: Record<string, any>) => {
|
||||
Logger.instantiate('local', v4(), LogLevel.DEBUG)
|
||||
const { user, dateRange, opponent } = request
|
||||
const reservation = new Reservation(user, dateRange, opponent)
|
||||
|
||||
29
src/server/index.ts
Normal file
29
src/server/index.ts
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import { disconnect, init } from '../common/database'
|
||||
import { Logger, LogLevel } from '../common/logger'
|
||||
import server from './http'
|
||||
import { startTasks, stopTasks } from './cron'
|
||||
|
||||
const logger = new Logger('process', 'default', LogLevel.DEBUG)
|
||||
|
||||
process.on('unhandledRejection', (reason) => {
|
||||
logger.error('unhandled rejection', { reason })
|
||||
})
|
||||
|
||||
process.on('uncaughtException', (error, origin) => {
|
||||
logger.error('uncaught exception', { error, origin })
|
||||
})
|
||||
|
||||
process.on('beforeExit', async () => {
|
||||
await disconnect()
|
||||
stopTasks()
|
||||
})
|
||||
|
||||
const port = process.env.SERVER_PORT || 3000
|
||||
|
||||
startTasks()
|
||||
|
||||
server.listen(port, async () => {
|
||||
logger.info('server ready and listening', { port })
|
||||
await init()
|
||||
logger.info('database connection established')
|
||||
})
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
// rollup.config.js
|
||||
import path from 'path'
|
||||
|
||||
import typescript from '@rollup/plugin-typescript'
|
||||
import { nodeResolve } from '@rollup/plugin-node-resolve'
|
||||
import commonjs from '@rollup/plugin-commonjs'
|
||||
import natives from 'rollup-plugin-natives'
|
||||
|
||||
export default {
|
||||
input: path.resolve('src/server/index.ts'),
|
||||
output: {
|
||||
file: './dist/server/index.cjs',
|
||||
format: 'cjs',
|
||||
sourcemap: true,
|
||||
},
|
||||
plugins: [
|
||||
typescript(),
|
||||
natives({
|
||||
copyTo: 'dist/libs',
|
||||
destDir: '../libs',
|
||||
dlopen: false,
|
||||
sourcemap: true,
|
||||
}),
|
||||
commonjs(),
|
||||
nodeResolve(),
|
||||
],
|
||||
}
|
||||
|
|
@ -2,10 +2,11 @@
|
|||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
|
||||
"compilerOptions": {
|
||||
"lib": ["esnext"],
|
||||
"module": "esnext",
|
||||
"lib": ["esnext", "dom"],
|
||||
"module": "commonjs",
|
||||
"moduleResolution": "node",
|
||||
"target": "es6",
|
||||
"allowJs": true,
|
||||
"sourceMap": true,
|
||||
|
||||
"strict": true,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue