diff --git a/.github/workflows/biweekly-pr.yaml b/.github/workflows/biweekly-pr.yml similarity index 100% rename from .github/workflows/biweekly-pr.yaml rename to .github/workflows/biweekly-pr.yml diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yml similarity index 100% rename from .github/workflows/deploy.yaml rename to .github/workflows/deploy.yml diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml deleted file mode 100644 index ead019fc0..000000000 --- a/.github/workflows/node.js.yml +++ /dev/null @@ -1,32 +0,0 @@ -# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs - -name: Node.js CI - -on: - pull_request: - branches: ["prod", "dev"] - -jobs: - build: - runs-on: ubuntu-latest - - strategy: - matrix: - node-version: [16.x, 18.x, 20.x] - # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ - - steps: - - uses: actions/checkout@v3 - - name: Use Node.js ${{ matrix.current-version }} - uses: actions/setup-node@v3 - with: - node-version: ${{ matrix.current-version }} - cache: "npm" - - run: cd client - - run: npm i --legacy-peer-deps - - run: npm run build --if-present - - run: cd ../ - - run: cd server - - run: npm i --legacy-peer-deps - - run: npm run build --if-present diff --git a/.github/workflows/staging-deploy.yaml b/.github/workflows/staging-deploy.yml similarity index 100% rename from .github/workflows/staging-deploy.yaml rename to .github/workflows/staging-deploy.yml diff --git a/client/.dockerignore b/client/.dockerignore new file mode 100644 index 000000000..b7dab5e9c --- /dev/null +++ b/client/.dockerignore @@ -0,0 +1,2 @@ +node_modules +build \ No newline at end of file diff --git a/client/local.Dockerfile b/client/local.Dockerfile new file mode 100644 index 000000000..8694f53a4 --- /dev/null +++ b/client/local.Dockerfile @@ -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"] \ No newline at end of file diff --git a/client/remote.Dockerfile b/client/remote.Dockerfile new file mode 100644 index 000000000..e5753711d --- /dev/null +++ b/client/remote.Dockerfile @@ -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"] diff --git a/client/tailwind.config.js b/client/tailwind.config.js index a3886aacc..1b314a67d 100644 --- a/client/tailwind.config.js +++ b/client/tailwind.config.js @@ -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: { diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..33819c6aa --- /dev/null +++ b/docker-compose.yml @@ -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 diff --git a/server/Dockerfile b/server/Dockerfile new file mode 100644 index 000000000..a1284c22b --- /dev/null +++ b/server/Dockerfile @@ -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"] \ No newline at end of file diff --git a/server/database/compose.yml b/server/database/compose.yml deleted file mode 100644 index ecbd07703..000000000 --- a/server/database/compose.yml +++ /dev/null @@ -1,13 +0,0 @@ -# Use postgres/example user/password credentials -version: "3.1" -services: - db: - image: postgres - ports: - - "5433:5433" - restart: always - env_file: - - ../.env - volumes: - - ./schema.sql:/docker-entrypoint-initdb.d/schema.sql - command: -p 5433 diff --git a/server/database/index.js b/server/database/index.js index cbe06a369..1722278d0 100644 --- a/server/database/index.js +++ b/server/database/index.js @@ -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', @@ -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; @@ -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) {