From 0e8070382ef54dd8966241ec53d678d7a65234cc Mon Sep 17 00:00:00 2001 From: Nelson Trindade Date: Mon, 20 May 2024 21:37:43 +0100 Subject: [PATCH 1/9] build: add docker-compose configuration --- build/.env.example | 18 ++++++++++++ build/Dockerfile | 12 ++++++++ build/docker-compose.yml | 60 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 build/.env.example create mode 100644 build/Dockerfile create mode 100644 build/docker-compose.yml diff --git a/build/.env.example b/build/.env.example new file mode 100644 index 00000000..2f38c37e --- /dev/null +++ b/build/.env.example @@ -0,0 +1,18 @@ +COMPOSE_NAME=neiist-website +NODE_COMMAND=start + +CLIENT_NAME=client +CLIENT_PORT=3000 +CLIENT_FOLDER=client + +SERVER_NAME=server +SERVER_PORT=3001 +SERVER_FOLDER=server + +POSTGRES_NAME=postgres +POSTGRES_PORT=5432 +POSTGRES_IMAGE=postgres:alpine + +POSTGRES_DB=neiist +POSTGRES_USER= +POSTGRES_PASSWORD= \ No newline at end of file diff --git a/build/Dockerfile b/build/Dockerfile new file mode 100644 index 00000000..82502ddf --- /dev/null +++ b/build/Dockerfile @@ -0,0 +1,12 @@ +FROM node:21.4.0-bullseye-slim + +WORKDIR /opt/app + +ARG FOLDER +COPY $FOLDER/package*.json /opt/app/ +RUN npm install + +COPY $FOLDER/ /opt/app + +EXPOSE $PORT +ENTRYPOINT npm "$COMMAND" \ No newline at end of file diff --git a/build/docker-compose.yml b/build/docker-compose.yml new file mode 100644 index 00000000..80c138c2 --- /dev/null +++ b/build/docker-compose.yml @@ -0,0 +1,60 @@ +name: neiist +services: + client: + container_name: $CLIENT_NAME + build: + context: ../ + dockerfile: build/Dockerfile + args: + FOLDER: $CLIENT_FOLDER + environment: + COMMAND: $NODE_COMMAND + PORT: $CLIENT_PORT + SERVER_HOST: server + ports: + - $CLIENT_PORT:$CLIENT_PORT + volumes: + - ../client/:/opt/app/ + - /opt/app/node_modules + depends_on: + - server + + server: + container_name: $SERVER_NAME + build: + context: ../ + dockerfile: build/Dockerfile + args: + FOLDER: $SERVER_FOLDER + environment: + COMMAND: $NODE_COMMAND + PGHOST: ${PGHOST:-postgres} + PORT: $SERVER_PORT + ports: + - $SERVER_PORT:$SERVER_PORT + volumes: + - ../server/:/opt/app/ + - /opt/app/node_modules + depends_on: + postgres: + condition: service_healthy + + postgres: + container_name: $POSTGRES_NAME + image: $POSTGRES_IMAGE + environment: + POSTGRES_DB: $POSTGRES_DB + POSTGRES_PORT: $POSTGRES_PORT + POSTGRES_USER: $POSTGRES_USER + POSTGRES_PASSWORD: $POSTGRES_PASSWORD + ports: + - $POSTGRES_PORT:$POSTGRES_PORT + volumes: + - postgres_data:/var/lib/postgresql/data + healthcheck: + test: ["CMD-SHELL", "pg_isready -d $POSTGRES_DB -U $POSTGRES_USER"] + interval: 10s + timeout: 5s + retries: 5 +volumes: + postgres_data: \ No newline at end of file From eda0758f436436bc1731dcadfbe5761838604492 Mon Sep 17 00:00:00 2001 From: Nelson Trindade Date: Mon, 20 May 2024 22:44:31 +0100 Subject: [PATCH 2/9] doc: add Docker documentation and reorganizing docs --- README.md | 105 +++----------------------------------------- doc/installation.md | 104 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+), 100 deletions(-) create mode 100644 doc/installation.md diff --git a/README.md b/README.md index 54ebf49e..916e9eba 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,8 @@

- - Logo + + Logo

NEIIST Website

@@ -25,8 +25,8 @@ Go to Website »

- + Getting Started +
Report Bug · Request Feature @@ -79,106 +79,11 @@ Of course, no one template will serve all projects since your needs may be diffe A list of commonly used resources that I find helpful are listed in the acknowledgements. --> -### Built With +### Built With > [React](https://reactjs.org/), [React Bootstrap](https://react-bootstrap.github.io/), [Node.js](https://nodejs.org/en/), [Express](http://expressjs.com/), [PostgreSQL](https://www.postgresql.org/) - -## Getting Started - - -To get a local copy up and running follow these simple example steps. - -### Prerequisites - - - -* **Node.js** (Version 21.4.0) - ```sh - sudo apt install nodejs - ``` - -* **NPM** (Version 10.2.4) - ```sh - sudo apt install npm - ``` - -> ❗ You can also use Node Version Manager ([NVM](https://github.com/nvm-sh/nvm)) to install Node.js and NPM - -* **PostgreSQL** - ```sh - sudo apt install postgresql - ``` - ...or use Docker ([see below](?tab=readme-ov-file#alternative-docker-for-database)) - -### Installation - -1. Create a Fénix application with a Redirect Url of `http://localhost:3000/` and a Scope of `Informações` at [https://fenix.tecnico.ulisboa.pt/personal/external-applications/#/applications](https://fenix.tecnico.ulisboa.pt/personal/external-applications/#/applications) -2. Create a PostgreSQL database - ```sh - sudo -i -u postgres - psql - CREATE DATABASE neiist; - \q - exit - ``` -3. Clone the repo - ```sh - cd folder-where-i-keep-my-repos/ - git clone https://github.com/neiist-dev/neiist-website.git - ``` -4. Server: Install NPM packages - ```sh - cd server/ - npm install - ``` -5. Server: Create .env file - ```sh - cp .env.example .env - ``` -6. Server: Populate the .env file with your Fénix application and database credentials -7. Server: Run - ```sh - npm start - ``` -8. Client: Install NPM packages - ```sh - cd ../client/ - npm install - ``` -9. Client: Create .env file - ```sh - cp .env.example .env - ``` -10. Client: Populate the .env file with your Fénix application credentials -11. Client: Run - ```sh - npm start - ``` - - -### Alternative: Docker for database - -1. Pull postgres image - ```sh - docker pull postgres:alpine - ``` -2. Create and run the container - ```sh - docker run -itd -e POSTGRES_PASSWORD= -p 5432:5432 -v :/var/lib/postgresql/data --name postgresql postgres:alpine - ``` -3. Create database - ```sh - docker exec -it postgresql bash - psql -U postgres - CREATE DATABASE neiist; - \q - exit - ``` -Note: the env variable PGHOST should be localhost - - + +* **Node.js** (Version 21.4.0) + ```sh + sudo apt install nodejs + ``` + +* **NPM** (Version 10.2.4) + ```sh + sudo apt install npm + ``` + +> ❗ You can also use Node Version Manager ([NVM](https://github.com/nvm-sh/nvm)) to install Node.js and NPM + +* **PostgreSQL** + ```sh + sudo apt install postgresql + ``` + +1. Create a PostgreSQL database + ```sh + sudo -i -u postgres + psql + CREATE DATABASE neiist; + \q + exit + ``` +2. Server: Install NPM packages + ```sh + cd server/ + npm install + ``` +3. Server: Run + ```sh + npm start + ``` +4. Client: Install NPM packages + ```sh + cd ../client/ + npm install + ``` +5. Client: Run + ```sh + npm start + ``` \ No newline at end of file From 6baf65739aa5065c137cf9f162fd44be4dbec1e8 Mon Sep 17 00:00:00 2001 From: Nelson Trindade Date: Mon, 20 May 2024 22:46:16 +0100 Subject: [PATCH 3/9] doc: add Docker documentation and reorganizing docs --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 916e9eba..31c3e250 100644 --- a/README.md +++ b/README.md @@ -25,8 +25,6 @@ Go to Website »

- Getting Started -
Report Bug · Request Feature @@ -79,6 +77,8 @@ Of course, no one template will serve all projects since your needs may be diffe A list of commonly used resources that I find helpful are listed in the acknowledgements. --> +### >> [Getting Started](./doc/installation.md) + ### Built With > [React](https://reactjs.org/), [React Bootstrap](https://react-bootstrap.github.io/), [Node.js](https://nodejs.org/en/), [Express](http://expressjs.com/), [PostgreSQL](https://www.postgresql.org/) From d1344095b20794a6fabd9658e02d52b81622f6b5 Mon Sep 17 00:00:00 2001 From: Nelson Trindade Date: Mon, 20 May 2024 22:49:40 +0100 Subject: [PATCH 4/9] doc: reorganizing docs --- README.md | 4 +++- doc/installation.md | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 31c3e250..5258c74d 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,9 @@ Of course, no one template will serve all projects since your needs may be diffe A list of commonly used resources that I find helpful are listed in the acknowledgements. --> -### >> [Getting Started](./doc/installation.md) +### Getting Started + +* [Installation](./doc/installation.md) ### Built With diff --git a/doc/installation.md b/doc/installation.md index 1afdbc15..84a65895 100644 --- a/doc/installation.md +++ b/doc/installation.md @@ -49,9 +49,9 @@ To get a local copy up and running follow these simple example steps. > Note: > - Build and Deploy can be achieved with one command -> ```sh -> docker-compose up --build --no-cache -> ``` +> ```sh +> docker-compose up --build --no-cache +> ``` ## Linux Base System From 76a79c9bceaf23bd1f059e04cce0103687d16fa7 Mon Sep 17 00:00:00 2001 From: Nelson Trindade Date: Mon, 20 May 2024 22:53:35 +0100 Subject: [PATCH 5/9] doc: adding proxy change needed --- doc/installation.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/installation.md b/doc/installation.md index 84a65895..2de9b19b 100644 --- a/doc/installation.md +++ b/doc/installation.md @@ -34,7 +34,8 @@ To get a local copy up and running follow these simple example steps. ```sh docker-compose build --no-cache ``` -7. Up all containers +7. Modify client package.json proxy value to `http://server:3001`. Make sure to add this change in any commit +8. Up all containers ```sh docker-compose up ``` @@ -42,7 +43,7 @@ To get a local copy up and running follow these simple example steps. ```sh docker-compose up -d ``` -8. Whenever desired, close all container +9. Whenever desired, close all container ```sh docker-compose down ``` From 8de3519566cf24b4789318a4a38c6da9df101003 Mon Sep 17 00:00:00 2001 From: Nelson Trindade Date: Tue, 21 May 2024 22:16:02 +0100 Subject: [PATCH 6/9] refactor: doc to readme and dockerfile --- README.md | 2 +- build/Dockerfile | 2 +- {doc => readme}/installation.md | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename {doc => readme}/installation.md (100%) diff --git a/README.md b/README.md index 5258c74d..35e164e7 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ A list of commonly used resources that I find helpful are listed in the acknowle ### Getting Started -* [Installation](./doc/installation.md) +* [Installation](./readme/installation.md) ### Built With diff --git a/build/Dockerfile b/build/Dockerfile index 82502ddf..eedf2ba9 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -9,4 +9,4 @@ RUN npm install COPY $FOLDER/ /opt/app EXPOSE $PORT -ENTRYPOINT npm "$COMMAND" \ No newline at end of file +ENTRYPOINT npm $COMMAND \ No newline at end of file diff --git a/doc/installation.md b/readme/installation.md similarity index 100% rename from doc/installation.md rename to readme/installation.md From 01720a7a390712d66eeb785c320861faae499ed3 Mon Sep 17 00:00:00 2001 From: Nelson Trindade Date: Tue, 21 May 2024 22:30:21 +0100 Subject: [PATCH 7/9] refactor: doc to readme and dockerfile --- README.md | 4 ++-- build/Dockerfile | 4 ++-- build/docker-compose.yml | 15 +++++---------- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 35e164e7..06a289e9 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,8 @@

- - Logo + + Logo

NEIIST Website

diff --git a/build/Dockerfile b/build/Dockerfile index eedf2ba9..ef367af0 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -3,10 +3,10 @@ FROM node:21.4.0-bullseye-slim WORKDIR /opt/app ARG FOLDER -COPY $FOLDER/package*.json /opt/app/ +COPY ./package*.json /opt/app/ RUN npm install -COPY $FOLDER/ /opt/app +COPY ./ /opt/app EXPOSE $PORT ENTRYPOINT npm $COMMAND \ No newline at end of file diff --git a/build/docker-compose.yml b/build/docker-compose.yml index 80c138c2..fbd5465d 100644 --- a/build/docker-compose.yml +++ b/build/docker-compose.yml @@ -3,14 +3,11 @@ services: client: container_name: $CLIENT_NAME build: - context: ../ - dockerfile: build/Dockerfile - args: - FOLDER: $CLIENT_FOLDER + context: ../client/ + dockerfile: ../build/Dockerfile environment: COMMAND: $NODE_COMMAND PORT: $CLIENT_PORT - SERVER_HOST: server ports: - $CLIENT_PORT:$CLIENT_PORT volumes: @@ -22,14 +19,12 @@ services: server: container_name: $SERVER_NAME build: - context: ../ - dockerfile: build/Dockerfile - args: - FOLDER: $SERVER_FOLDER + context: ../server/ + dockerfile: ../build/Dockerfile environment: COMMAND: $NODE_COMMAND - PGHOST: ${PGHOST:-postgres} PORT: $SERVER_PORT + PGHOST: ${PGHOST:-postgres} ports: - $SERVER_PORT:$SERVER_PORT volumes: From 457caf01f61d26fb81e2b8aa609ae49ac0d8e22e Mon Sep 17 00:00:00 2001 From: Nelson Trindade Date: Tue, 21 May 2024 22:31:35 +0100 Subject: [PATCH 8/9] refactor: doc to readme and dockerfile --- build/.env.example | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/build/.env.example b/build/.env.example index 2f38c37e..4fb5b219 100644 --- a/build/.env.example +++ b/build/.env.example @@ -1,4 +1,3 @@ -COMPOSE_NAME=neiist-website NODE_COMMAND=start CLIENT_NAME=client @@ -15,4 +14,4 @@ POSTGRES_IMAGE=postgres:alpine POSTGRES_DB=neiist POSTGRES_USER= -POSTGRES_PASSWORD= \ No newline at end of file +POSTGRES_PASSWORD= From ac6b3ebf37668c4d7f1d43e9742ff74ac81224d7 Mon Sep 17 00:00:00 2001 From: Nelson Trindade Date: Thu, 23 May 2024 22:37:25 +0100 Subject: [PATCH 9/9] fix: refactor docker command to correct location --- build/.env.example | 2 +- build/Dockerfile | 5 +++-- build/docker-compose.yml | 11 ++++++----- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/build/.env.example b/build/.env.example index 4fb5b219..8e52d609 100644 --- a/build/.env.example +++ b/build/.env.example @@ -1,4 +1,4 @@ -NODE_COMMAND=start +NPM_COMMAND=start CLIENT_NAME=client CLIENT_PORT=3000 diff --git a/build/Dockerfile b/build/Dockerfile index ef367af0..4a2d2324 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -2,11 +2,12 @@ FROM node:21.4.0-bullseye-slim WORKDIR /opt/app -ARG FOLDER COPY ./package*.json /opt/app/ RUN npm install COPY ./ /opt/app +ARG PORT EXPOSE $PORT -ENTRYPOINT npm $COMMAND \ No newline at end of file + +ENTRYPOINT ["npm"] \ No newline at end of file diff --git a/build/docker-compose.yml b/build/docker-compose.yml index fbd5465d..d11bdbb9 100644 --- a/build/docker-compose.yml +++ b/build/docker-compose.yml @@ -5,14 +5,14 @@ services: build: context: ../client/ dockerfile: ../build/Dockerfile - environment: - COMMAND: $NODE_COMMAND - PORT: $CLIENT_PORT + args: + PORT: $CLIENT_PORT ports: - $CLIENT_PORT:$CLIENT_PORT volumes: - ../client/:/opt/app/ - /opt/app/node_modules + command: $NPM_COMMAND depends_on: - server @@ -21,15 +21,16 @@ services: build: context: ../server/ dockerfile: ../build/Dockerfile + args: + PORT: $SERVER_PORT environment: - COMMAND: $NODE_COMMAND - PORT: $SERVER_PORT PGHOST: ${PGHOST:-postgres} ports: - $SERVER_PORT:$SERVER_PORT volumes: - ../server/:/opt/app/ - /opt/app/node_modules + command: $NPM_COMMAND depends_on: postgres: condition: service_healthy