diff --git a/.dockerignore b/.dockerignore index bb83dc5..c3b7f2c 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1,7 @@ +.git .mysql +dist +node_modules +Dockerfile +docker-compose.yml +sous-podzim2024-app.tar.gz diff --git a/.gitignore b/.gitignore index d6da680..63fceff 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ -node_modules .mysql +dist +node_modules +sous-podzim2024-app.tar.gz diff --git a/Dockerfile b/Dockerfile index 4099fa5..3bb2ad7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,17 @@ -FROM oven/bun:1 AS base +FROM oven/bun:1 AS builder WORKDIR /usr/src/app COPY package.json bun.lockb . -#RUN bun install --frozen-lockfile --production -RUN bun install --frozen-lockfile --development +RUN bun install --frozen-lockfile --production COPY . . +RUN bun run build -#ENV NODE_ENV=production -ENV NODE_ENV=development +FROM node:22-alpine AS base +WORKDIR /usr/src/app +COPY --from=builder /usr/src/app . + +ENV NODE_ENV=production -USER bun EXPOSE 8080/tcp -#ENTRYPOINT [ "bun", "run", "src/index.ts" ] -ENTRYPOINT [ "bun", "run", "dev" ] +ENTRYPOINT [ "node", "./dist/index.js" ] diff --git a/README.md b/README.md index afc0144..fb48a9a 100644 --- a/README.md +++ b/README.md @@ -12,4 +12,8 @@ To run: bun run index.ts ``` -This project was created using `bun init` in bun v1.1.12. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime. +# transfer to server +build image with `docker compose build` +save image to file on client: `docker save sous-podzim2024-app:latest | gzip > sous-podzim2024-app.tar.gz` +copy zip to server +load image on server: `docker load < sous-podzim2024-app.tar.gz` diff --git a/bun.lockb b/bun.lockb index 84c9b1c..d9f0af5 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/docker-compose.yml b/docker-compose.yml index aa72a3c..6b3ab02 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,6 @@ services: app: - image: labyrint + image: sous-podzim2024-app build: context: . restart: on-failure:3 diff --git a/drizzle.config.ts b/drizzle.config.ts index 8ed41bd..f4825bf 100644 --- a/drizzle.config.ts +++ b/drizzle.config.ts @@ -1,12 +1,10 @@ import { defineConfig } from "drizzle-kit"; export const dbCredentials = { - //host: "127.0.0.1", host: "db", - //port: 8081, port: 3306, - user: "root", - password: "password", + user: "fykosak", + password: "zxvFcEztX0vzDhB", database: "sous-podzim2024-app" }; diff --git a/package.json b/package.json index 801a516..cac777a 100644 --- a/package.json +++ b/package.json @@ -1,26 +1,25 @@ { - "name": "sous-podzim2024-app", - "module": "index.ts", - "type": "module", - "devDependencies": { - "@types/bun": "latest" - }, - "peerDependencies": { - "typescript": "^5.0.0" - }, - "dependencies": { - "@types/ejs": "^3.1.5", - "@types/express": "^4.17.21", - "@types/multer": "^1.4.12", - "drizzle-kit": "^0.24.2", - "drizzle-orm": "^0.33.0", - "ejs": "^3.1.10", - "express": "^4.19.2", - "multer": "^1.4.5-lts.1", - "mysql2": "^3.11.0" - }, - "scripts": { - "dev": "bun --watch src/index.ts", - "push": "bun drizzle-kit push" - } + "name": "sous-podzim2024-app", + "module": "index.ts", + "type": "module", + "devDependencies": { + "@types/bun": "latest" + }, + "dependencies": { + "@types/ejs": "^3.1.5", + "@types/express": "^4.17.21", + "@types/multer": "^1.4.12", + "drizzle-kit": "^0.24.2", + "drizzle-orm": "^0.33.0", + "ejs": "^3.1.10", + "express": "^4.19.2", + "typescript": "^5.6.2", + "multer": "^1.4.5-lts.1", + "mysql2": "^3.11.0" + }, + "scripts": { + "dev": "bun --watch src/index.ts", + "push": "bun drizzle-kit push", + "build": "bun build ./src/index.ts --outdir ./dist --target node" + } } diff --git a/src/database/schema.ts b/src/database/schema.ts index 783bc04..c32a542 100644 --- a/src/database/schema.ts +++ b/src/database/schema.ts @@ -15,7 +15,7 @@ export const personRelations = relations(personTable, ({ many }) => ({ export const pointsTable = mysqlTable('points', { pointsId: int('pointsId').primaryKey().autoincrement(), personId: int('personId').notNull().references(() => personTable.personId), - points: int('points'), + points: int('points').notNull(), }); export const pointsRelations = relations(pointsTable, ({ one }) => ({ diff --git a/src/index.ts b/src/index.ts index 25e0753..8b136ad 100644 --- a/src/index.ts +++ b/src/index.ts @@ -88,6 +88,7 @@ app.get("/gamble/:id", async (req, res) => { if (isDetailAvailable(person.gambleTime)) { res.redirect('/person/' + id); + return; } if (!isGambleAvailable(person.gambleTime)) {