crated volume for attachments

This commit is contained in:
slawk0
2025-01-05 00:24:28 +01:00
parent 334c14bd9e
commit 3439d4b9de
3 changed files with 24 additions and 8 deletions

View File

@@ -1,8 +1,12 @@
version: '3.8'
services: services:
relay-server: relay-server:
build: build:
context: ./server context: ./server
dockerfile: Dockerfile dockerfile: Dockerfile
env_file:
- server/.env
environment: environment:
SERVER_PORT: ${SERVER_PORT} SERVER_PORT: ${SERVER_PORT}
JWT_SECRET: ${JWT_SECRET} JWT_SECRET: ${JWT_SECRET}
@@ -11,6 +15,8 @@ services:
PG_PASSWORD: ${PG_PASSWORD} PG_PASSWORD: ${PG_PASSWORD}
PG_DATABASE: ${PG_DATABASE} PG_DATABASE: ${PG_DATABASE}
PG_HOST: db PG_HOST: db
volumes:
- attachments:/usr/src/app/attachments
ports: ports:
- "3000" - "3000"
depends_on: depends_on:
@@ -36,6 +42,8 @@ services:
image: postgres:latest image: postgres:latest
restart: always restart: always
user: postgres user: postgres
env_file:
- server/.env
volumes: volumes:
- postgres-data:/var/lib/postgresql/data - postgres-data:/var/lib/postgresql/data
environment: environment:
@@ -57,4 +65,5 @@ networks:
driver: bridge driver: bridge
volumes: volumes:
postgres-data: postgres-data:
attachments:

View File

@@ -1,21 +1,24 @@
ARG NODE_VERSION=20.17.0 ARG NODE_VERSION=20.17.0
FROM node:${NODE_VERSION}-alpine FROM node:${NODE_VERSION}-alpine
WORKDIR /usr/src/app WORKDIR /usr/src/app
# Create the attachments directory and set permissions
RUN mkdir -p attachments && chown -R node:node attachments RUN mkdir -p attachments && chown -R node:node attachments
# Install dependencies
RUN --mount=type=bind,source=package.json,target=package.json \ RUN --mount=type=bind,source=package.json,target=package.json \
--mount=type=bind,source=package-lock.json,target=package-lock.json \ --mount=type=bind,source=package-lock.json,target=package-lock.json \
--mount=type=cache,target=/root/.npm \ --mount=type=cache,target=/root/.npm \
npm ci --omit=dev npm ci --omit=dev
# Switch to the node user
USER node USER node
COPY . . # Copy the application code
COPY --chown=node:node . .
EXPOSE 3000 EXPOSE 3000
CMD node server.js CMD node server.js

View File

@@ -529,7 +529,7 @@ async function insertContact(initiatorId, receiverId, contactUsername, read) {
SELECT COUNT(DISTINCT user_id) SELECT COUNT(DISTINCT user_id)
FROM Memberships FROM Memberships
WHERE conversation_id = c.conversation_id WHERE conversation_id = c.conversation_id
) = 1 -- Allow a conversation with a single user (self) ) = 1
LIMIT 1 LIMIT 1
`; `;
const conversationResult = await client.query(findConversationQuery, [ const conversationResult = await client.query(findConversationQuery, [
@@ -540,16 +540,20 @@ async function insertContact(initiatorId, receiverId, contactUsername, read) {
// Create new conversation if none exists // Create new conversation if none exists
if (!conversation_id) { if (!conversation_id) {
console.error("CONVERSATION DON'T EXIST: ", conversation_id);
const createConversationQuery = ` const createConversationQuery = `
INSERT INTO Conversations (conversation_type) INSERT INTO Conversations (conversation_type)
VALUES ('direct') VALUES ('direct')
RETURNING conversation_id RETURNING conversation_id
`; `;
const newConversationResult = await client.query(createConversationQuery); const newConversationResult = await client.query(createConversationQuery);
if (!newConversationResult) {
console.error("Failed to create new conversation");
return null;
}
conversation_id = newConversationResult.rows[0].conversation_id; conversation_id = newConversationResult.rows[0].conversation_id;
console.error("NEW CONVERSATION ID: ", conversation_id); // Create memberships for users
// Create memberships for both users (or single user if they are the same)
const createMembershipsQuery = ` const createMembershipsQuery = `
INSERT INTO Memberships (conversation_id, user_id) INSERT INTO Memberships (conversation_id, user_id)
VALUES ($1, $2), ($1, $3) VALUES ($1, $2), ($1, $3)