Full application docker compose set up

This commit is contained in:
Alex Holliday
2024-06-24 16:04:06 -07:00
parent 11c1819951
commit 531eb0b857
11 changed files with 93 additions and 53 deletions

3
.dockerignore Normal file
View File

@ -0,0 +1,3 @@
Client/node_modules/
Server/node_modules/
*.env

5
Docker/.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
*.sh
!build_images.sh
mongo/data/*
redis/data/*
*.env

View File

@ -4,15 +4,19 @@
# Change directory to root Server directory for correct Docker Context
cd ..
#Client
client="./Docker/client.Dockerfile"
# MongoDB
mongoDB="./docker/mongoDB.Dockerfile"
mongoDB="./Docker/mongoDB.Dockerfile"
# Redis
redis="./docker/redis.Dockerfile"
redis="./Docker/redis.Dockerfile"
# Server
server="./docker/server.Dockerfile"
server="./Docker/server.Dockerfile"
docker build -f $client -t uptime_client .
docker build -f $mongoDB -t uptime_database_mongo .
docker build -f $redis -t uptime_redis .
docker build -f $server -t uptime_server .

17
Docker/client.Dockerfile Normal file
View File

@ -0,0 +1,17 @@
FROM node:20
WORKDIR /app
COPY ./Client/package*.json ./
RUN npm install
COPY ./Client .
RUN npm run build
RUN npm install -g serve
CMD ["serve","-s", "dist", "-l", "5173"]
EXPOSE 5000

View File

@ -1,11 +1,19 @@
version: "3"
services:
client:
image: uptime_client:latest
ports:
- "5173:5173"
env_file:
- client.env
depends_on:
- server
server:
image: uptime_server:latest
ports:
- "5000:5000"
env_file:
- .env
- server.env
depends_on:
- redis
- mongodb

View File

@ -2,11 +2,11 @@ FROM node:20
WORKDIR /app
COPY ../../package*.json ./
COPY ./Server/package*.json ./
RUN npm install
COPY ../../ ./
COPY ./Server/ ./
EXPOSE 5000

View File

@ -27,18 +27,17 @@ You can see the designs [here](https://www.figma.com/design/RPSfaw66HjzSwzntKcgD
- Clone this repository to your local machine
1. [Docker Quickstart](#docker-compose)
1. [Installation (Client)](#client)
2. [Configuration(Client)](#config-client)
1. [Configuration(Client)](#config-client)
- [Environment](#env-vars-client)
3. [Getting Started (Server)](#server)
- [Docker Compose Quickstart](#docker-quickstart)
- [Manual Installation](#manual-install)
- [Install Server](#install-server)
- [Environment](#env-vars-server)
- [Database](#databases)
- [(Optional) Dockerised Databases](#optional-docker-databases)
- [Start Server](#start-server)
4. [Endpoints](#endpoints)
1. [Getting Started (Server)](#server)
- [Install Server](#install-server)
- [Environment](#env-vars-server)
- [Database](#databases)
- [(Optional) Dockerised Databases](#optional-docker-databases)
- [Start Server](#start-server)
1. [Endpoints](#endpoints)
###### Auth
- <code>POST</code> [/api/v1/auth/register](#post-register)
- <code>POST</code> [/api/v1/auth/login](#post-login)
@ -64,11 +63,45 @@ You can see the designs [here](https://www.figma.com/design/RPSfaw66HjzSwzntKcgD
- <code>GET</code> [/api/v1/alerts/{alertId}](#get-alert-alert-id)
- <code>POST</code> [/api/v1/alerts/edit/{alertId}](#edit-alert)
- <code>POST</code> [/api/v1/alerts/delete/{alertId}](#delete-alert)
5. [Error Handling](#error-handling)
6. [Contributors](#contributors)
1. [Error Handling](#error-handling)
1. [Contributors](#contributors)
---
### Docker Quick Start
#### <u>Docker Quickstart</u> <a id="docker-quickstart"></a>
The fastest way to start the application is to use our Dockerfiles and [Docker Compose](https://docs.docker.com/compose/).
To get the application up and running you need to:
1. In the `Docker` directory run the build script `build_images.sh` to build docker images for the client, server, Redis database, and MongoDB database.
2. In the `Docker` directory, create a `server.env` file with the [requried environtmental variables](#env-vars-server) for the server. Sample file:
```
CLIENT_HOST="http://localhost:5173"
JWT_SECRET="my_secret"
DB_TYPE="MongoDB"
DB_CONNECTION_STRING="mongodb://mongodb:27017/uptime_db"
REDIS_HOST="redis"
REDIS_PORT=6379
SYSTEM_EMAIL_ADDRESS="<email>"
SENDGRID_API_KEY="<api_key>"
LOGIN_PAGE_URL="<login_page"
```
3. In the `Docker` directory, create a `client.env` file with the [required environtmental variables](#env-vars-cllient) for the client. Sample file:
```
VITE_APP_API_BASE_URL="http://localhost:5000/api/v1"
```
4. In the `Docker` directory run `docker compose up` to run the `docker-compose.yaml` file and start all four images.
That's it, the application is ready to use on port 5173.
<br/>
### Client
#### <u>Installation</u>
@ -96,32 +129,6 @@ You can see the designs [here](https://www.figma.com/design/RPSfaw66HjzSwzntKcgD
### Getting Started (Server)
#### <u>Docker Quickstart</u> <a id="docker-quickstart"></a>
The fastest way to start the server is to use our Dockerfiles and [Docker Compose](https://docs.docker.com/compose/).
To get the server up and running you need to:
1. In the `Server/docker` directory run the build script `build_images.sh` to build docker images for the server, Redis database, and MongoDB database.
2. In the `Server/docker` directory, create a `.env` file with the [requried environtmental variables](#env-vars-server). Sample file:
```
CLIENT_HOST="http://localhost:5173"
JWT_SECRET="my_secret"
DB_TYPE="MongoDB"
DB_CONNECTION_STRING="mongodb://mongodb:27017/uptime_db"
REDIS_HOST="redis"
REDIS_PORT=6379
SYSTEM_EMAIL_ADDRESS="<email>"
SENDGRID_API_KEY="<api_key>"
LOGIN_PAGE_URL="<login_page"
```
3. In the `Server/docker` directory run `docker compose up` to run the `docker-compose.yaml` file and start all three images.
That's it, the server is ready to use.
<br/>
#### <u>Manual Install</u> <a id="manual-install"></a>
##### Install Server <a id="install-server"></a>
@ -161,15 +168,15 @@ You may use the included Dockerfiles to spin up databases quickly if you wish.
###### (Optional) Dockerised Databases <a id="optional-docker-databases"></a>
Dockerfiles for the server and databases are located in the `./Server/docker` directory
Dockerfiles for the server and databases are located in the `Docker` directory
<details>
<summary><b>MongoDB Image</b></summary>
Location: `./Server/docker/mongoDB.Dockerfile`
The `./Server/docker/mongo/data` directory should be mounted to the MongoDB container in order to persist data.
The `Docker/mongo/data` directory should be mounted to the MongoDB container in order to persist data.
From the `Server/docker` directory run
From the `Docker` directory run
1. Build the image: `docker build -f mongoDB.Dockerfile -t uptime_database_mongo .`
2. Run the docker image: `docker run -d -p 27017:27017 -v $(pwd)/mongo/data:/data/db --name uptime_database_mongo uptime_database_mongo`
@ -179,9 +186,9 @@ From the `Server/docker` directory run
<summary><b>Redis Image</b></summary>
Location `./Server/docker/redislDockerfile`
the `./Server/docker/redis/data` directory should be mounted to the Redis container in order to persist data.
the `Docker/redis/data` directory should be mounted to the Redis container in order to persist data.
From the `Server/docker` directory run
From the `Docker` directory run
1. Build the image: `docker build -f redis.Dockerfile -t uptime_redis .`
2. Run the image: `docker run -d -p 6379:6379 -v $(pwd)/redis/data:/data --name uptime_redis uptime_redis`

View File

@ -1 +0,0 @@
./docker

3
Server/.gitignore vendored
View File

@ -2,6 +2,3 @@ node_modules
.env
*.log
*.sh
docker/mongo/data/*
docker/redis/data/*
!docker/build_images.sh