Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker-compose.yml build #318

Merged
merged 9 commits into from
May 23, 2024
Merged
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
101 changes: 4 additions & 97 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
<a href="https://neiist.tecnico.ulisboa.pt"><strong>Go to Website »</strong></a>
<br />
<br />
<!-- <a href="https://github.com/othneildrew/Best-README-Template">View Demo</a>
· -->
<a href="https://github.com/neiist-dev/neiist-website/issues">Report Bug</a>
·
<a href="https://github.com/neiist-dev/neiist-website/issues">Request Feature</a>
Expand Down Expand Up @@ -79,104 +77,13 @@ 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
### Getting Started

> [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/)
* [Installation](./readme/installation.md)

### Built With

<!-- GETTING STARTED -->
## Getting Started

<!-- This is an example of how you may give instructions on setting up your project locally. -->
To get a local copy up and running follow these simple example steps.

### Prerequisites

<!-- This is an example of how to list things you need to use the software and how to install them. -->

* **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=<PASSWORD> -p 5432:5432 -v <HOST_FOLDER>:/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
> [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/)


<!-- USAGE EXAMPLES -->
Expand Down
17 changes: 17 additions & 0 deletions build/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
NPM_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=
13 changes: 13 additions & 0 deletions build/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM node:21.4.0-bullseye-slim

WORKDIR /opt/app

COPY ./package*.json /opt/app/
RUN npm install

COPY ./ /opt/app

ARG PORT
EXPOSE $PORT

ENTRYPOINT ["npm"]
56 changes: 56 additions & 0 deletions build/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: neiist
services:
client:
container_name: $CLIENT_NAME
build:
context: ../client/
dockerfile: ../build/Dockerfile
args:
PORT: $CLIENT_PORT
ports:
- $CLIENT_PORT:$CLIENT_PORT
volumes:
- ../client/:/opt/app/
- /opt/app/node_modules
command: $NPM_COMMAND
depends_on:
- server

server:
container_name: $SERVER_NAME
build:
context: ../server/
dockerfile: ../build/Dockerfile
args:
PORT: $SERVER_PORT
environment:
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

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:
105 changes: 105 additions & 0 deletions readme/installation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# Installation

To get a local copy up and running follow these simple example steps.

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. Clone the repo
```sh
cd folder-where-i-keep-my-repos/
git clone https://github.com/neiist-dev/neiist-website.git
```
3. Server: Create .env file
```sh
cp .env.example .env
```
4. Server: Populate the .env file with your Fénix application and database credentials
5. Client: Create .env file
```sh
cp .env.example .env
```
6. Client: Populate the .env file with your Fénix application credentials


## Docker

1. Install Docker Desktop for Windows/MacOS or simply install Docker in Linux
2. Check if Docker-Compose is installed by checking `docker-compose version`
3. Go to [build/](build/) folder
4. Build: Create .env file
```sh
cp .env.example .env
```
5. Build: Populate the .env file with the database information
6. Build all containers
```sh
docker-compose build --no-cache
```
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
```
or if you want to be running in the background...
```sh
docker-compose up -d
```
9. Whenever desired, close all container
```sh
docker-compose down
```

> Note:
> - Build and Deploy can be achieved with one command
> ```sh
> docker-compose up --build --no-cache
> ```

## Linux Base System

### Prerequisites

<!-- This is an example of how to list things you need to use the software and how to install them. -->

* **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
```