Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
32 changes: 0 additions & 32 deletions .github/workflows/node.js.yml

This file was deleted.

2 changes: 2 additions & 0 deletions client/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
build
10 changes: 10 additions & 0 deletions client/local.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM node:20-alpine AS dependencies-env
WORKDIR /app
COPY package*.json ./
RUN npm install --legacy-peer-deps

FROM node:20-alpine
WORKDIR /app
COPY --from=dependencies-env /app/node_modules /app/node_modules
COPY . ./
CMD ["npm", "run", "start"]
15 changes: 15 additions & 0 deletions client/remote.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM node:20-alpine AS dependencies-env
WORKDIR /app
COPY package*.json ./
RUN npm install --legacy-peer-deps

FROM node:20-alpine AS build-env
WORKDIR /app
COPY --from=dependencies-env /app/node_modules ./node_modules
COPY . .
RUN npm run build

FROM node:20-alpine
WORKDIR /app
COPY --from=build-env /app/build ./build
CMD ["npx", "serve", "-s", "build", "-l", "80"]
2 changes: 1 addition & 1 deletion client/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const plugin = require("tailwindcss/plugin");

module.exports = {
prefix: "tw-",
content: ["../client/src/**/*.{js,jsx}"],
content: ["./src/**/*.{js,jsx}"],
important: true,
theme: {
screens: {
Expand Down
35 changes: 35 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
services:
db:
image: postgres
ports:
- '5433:5433'
restart: always
env_file:
- ./server/.env
volumes:
- ./server/database/schema.sql:/docker-entrypoint-initdb.d/schema.sql
command: -p 5433
healthcheck:
test: ["CMD-SHELL", "pg_isready -p 5433 -U $$POSTGRES_USER -d postgres"]
interval: 5s
timeout: 5s
retries: 5
server:
build:
context: ./server
dockerfile: Dockerfile
env_file:
- ./server/.env
ports:
- "5005:5005"
depends_on:
db:
condition: service_healthy
client:
build:
context: ./client
dockerfile: local.Dockerfile
ports:
- "3000:3000"
depends_on:
- server
10 changes: 10 additions & 0 deletions server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM node:20-alpine AS dependencies-env
WORKDIR /app
COPY package*.json ./
RUN npm install

FROM node:20-alpine
WORKDIR /app
COPY --from=dependencies-env /app/node_modules ./node_modules
COPY . ./
CMD ["node", "app.js"]
13 changes: 0 additions & 13 deletions server/database/compose.yml

This file was deleted.

54 changes: 27 additions & 27 deletions server/database/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
const fs = require('fs');
const path = require('path');
const pathname = path.join(__dirname, 'models');
const withPassword = process.env.DB_PASS ? `:${process.env.DB_PASS}` : '';
const URI = `postgres://${process.env.DB_USER}${withPassword}@${process.env.DB_HOST}:${process.env.ENVIRONMENT === 'dev'?5433:5432}/${process.env.DB_SCHEMA}`;
const withPassword = process.env.POSTGRES_PASSWORD
? `:${process.env.POSTGRES_PASSWORD}`
: '';
const URI = `postgres://${process.env.DB_USER}${withPassword}@${process.env.DB_HOST}:${process.env.DB_PORT}/${process.env.DB_SCHEMA}`;
const Sequelize = require('sequelize');
const sequelize = new Sequelize(URI, {
dialect: 'postgres',
Expand All @@ -14,34 +16,33 @@ const sequelize = new Sequelize(URI, {
define: {
timestamps: false,
},
logging: process.env.TESTING === 'test'? false : console.log,
logging: process.env.TESTING === 'test' ? false : console.log,
});
const db = {};

sequelize
.authenticate()
.then(() => {
console.log('Connection has been established successfully.');
})
.catch((err) => {
console.error('Unable to connect to the database:', err);
});
.authenticate()
.then(() => {
console.log('Connection has been established successfully.');
})
.catch((err) => {
console.error('Unable to connect to the database:', err);
});
const files = [];
const sortDir = (maniDir) => {
const folders = [];
const CheckFile = (filePath) => (fs.statSync(filePath).isFile());
const CheckFile = (filePath) => fs.statSync(filePath).isFile();
const sortPath = (dir) => {
fs
.readdirSync(dir)
.filter((file) => (file.indexOf('.') !== 0) && (file !== 'index.js'))
.forEach((res) => {
const filePath = path.join(dir, res);
if (CheckFile(filePath)) {
files.push(filePath);
} else {
folders.push(filePath);
}
});
fs.readdirSync(dir)
.filter((file) => file.indexOf('.') !== 0 && file !== 'index.js')
.forEach((res) => {
const filePath = path.join(dir, res);
if (CheckFile(filePath)) {
files.push(filePath);
} else {
folders.push(filePath);
}
});
};
folders.push(maniDir);
let i = 0;
Expand All @@ -51,11 +52,10 @@ const sortDir = (maniDir) => {
} while (i < folders.length);
};
sortDir(pathname);
files
.forEach((file) => {
const model = require(file)(sequelize, Sequelize.DataTypes);
db[model.name] = model;
});
files.forEach((file) => {
const model = require(file)(sequelize, Sequelize.DataTypes);
db[model.name] = model;
});

Object.keys(db).forEach((modelName) => {
if (db[modelName].associate) {
Expand Down