fixed docker deployment

This commit is contained in:
leca 2025-01-25 17:09:44 +03:00
parent b82c2dc1d6
commit a1890acad0
5 changed files with 24 additions and 8 deletions

10
.gitignore vendored
View File

@ -130,3 +130,13 @@ dist
.yarn/install-state.gz
.pnp.*
build/
.env
backend/build
backend/node-modules
frontend/build
frontend/node-modules
data/

View File

@ -2,7 +2,8 @@ FROM node:22-bullseye
WORKDIR /opt/backend
COPY . .
COPY backend .
COPY .env .
RUN npm i
EXPOSE 3000

View File

@ -1,7 +1,7 @@
import express from "express";
import { AppDataSource } from "./data-source";
import UserRouter from "./routers/user";
import bodyParser from "body-parser";
import fs from 'fs';
import cookieParser from 'cookie-parser';
import PostRouter from "./routers/post";
import session from "express-session";
@ -17,6 +17,8 @@ app.use(session({
saveUninitialized: false,
}));
if (!fs.existsSync(process.env.UPLOAD_DESTINATION)) fs.mkdirSync(process.env.UPLOAD_DESTINATION);
AppDataSource.initialize().then(() => {
app.use('/api/v1/user/', UserRouter);
app.use('/api/v1/post/', PostRouter);

View File

@ -20,7 +20,7 @@ const handlePostData = async (req: Request, res: Response, next: NextFunction):
if (postToUpdate.type == 1) {
const filename = postToUpdate.message;
fs.rmSync(`${process.env.UPLOAD_DESTINATION}/${filename}`);
fs.unlinkSync(`${process.env.UPLOAD_DESTINATION}/${filename}`);
}
}
if (req.file) {
@ -33,9 +33,10 @@ const handlePostData = async (req: Request, res: Response, next: NextFunction):
const hash = crypto.createHash('md5');
hash.update(buffer);
const newFilename = `${hash.digest('hex')}${extension}`;
fs.renameSync(`./${req.file.path}`, `${process.env.UPLOAD_DESTINATION}/${newFilename}`)
post.message = newFilename
post.type = 1
fs.copyFileSync(`./${req.file.path}`, `${process.env.UPLOAD_DESTINATION}/${newFilename}`);
fs.unlinkSync(`./${req.file.path}`);
post.message = newFilename;
post.type = 1;
} else {
post.type = 0;
post.message = message;

View File

@ -11,7 +11,9 @@ services:
healthcheck:
test: pg_isready -U $${DB_USER} -d $${DB_NAME}
backend:
build: backend
build:
context: .
dockerfile: backend.Dockerfile
env_file: .env
ports:
- 8080:${APP_PORT}
@ -19,4 +21,4 @@ services:
- database
restart: on-failure
volumes:
- ./data/files:${PWD}/${UPLOAD_DESTINATION}
- ./data/files:${UPLOAD_DESTINATION}