diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..e6b9c067d --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +Client/node_modules/ +Server/node_modules/ +*.env \ No newline at end of file diff --git a/Docker/.gitignore b/Docker/.gitignore new file mode 100644 index 000000000..e1b726025 --- /dev/null +++ b/Docker/.gitignore @@ -0,0 +1,5 @@ +*.sh +!build_images.sh +mongo/data/* +redis/data/* +*.env \ No newline at end of file diff --git a/Server/docker/build_images.sh b/Docker/build_images.sh old mode 100644 new mode 100755 similarity index 58% rename from Server/docker/build_images.sh rename to Docker/build_images.sh index 94f1087a5..72540168c --- a/Server/docker/build_images.sh +++ b/Docker/build_images.sh @@ -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 . diff --git a/Docker/client.Dockerfile b/Docker/client.Dockerfile new file mode 100644 index 000000000..6b6451560 --- /dev/null +++ b/Docker/client.Dockerfile @@ -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 diff --git a/Server/docker/docker-compose.yaml b/Docker/docker-compose.yaml similarity index 73% rename from Server/docker/docker-compose.yaml rename to Docker/docker-compose.yaml index e878a5338..f7f0cc4c6 100644 --- a/Server/docker/docker-compose.yaml +++ b/Docker/docker-compose.yaml @@ -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 diff --git a/Server/docker/mongoDB.Dockerfile b/Docker/mongoDB.Dockerfile similarity index 100% rename from Server/docker/mongoDB.Dockerfile rename to Docker/mongoDB.Dockerfile diff --git a/Server/docker/redis.Dockerfile b/Docker/redis.Dockerfile similarity index 100% rename from Server/docker/redis.Dockerfile rename to Docker/redis.Dockerfile diff --git a/Server/docker/server.Dockerfile b/Docker/server.Dockerfile similarity index 63% rename from Server/docker/server.Dockerfile rename to Docker/server.Dockerfile index 8a9bf04e3..f3bb45060 100644 --- a/Server/docker/server.Dockerfile +++ b/Docker/server.Dockerfile @@ -2,11 +2,11 @@ FROM node:20 WORKDIR /app -COPY ../../package*.json ./ +COPY ./Server/package*.json ./ RUN npm install -COPY ../../ ./ +COPY ./Server/ ./ EXPOSE 5000 diff --git a/README.md b/README.md index 09f26e237..59e79159c 100644 --- a/README.md +++ b/README.md @@ -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 - POST [/api/v1/auth/register](#post-register) - POST [/api/v1/auth/login](#post-login) @@ -64,11 +63,45 @@ You can see the designs [here](https://www.figma.com/design/RPSfaw66HjzSwzntKcgD - GET [/api/v1/alerts/{alertId}](#get-alert-alert-id) - POST [/api/v1/alerts/edit/{alertId}](#edit-alert) - POST [/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 + +#### Docker Quickstart + +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="" +SENDGRID_API_KEY="" +LOGIN_PAGE_URL=" + ### Client #### Installation @@ -96,32 +129,6 @@ You can see the designs [here](https://www.figma.com/design/RPSfaw66HjzSwzntKcgD ### Getting Started (Server) -#### Docker Quickstart - -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="" -SENDGRID_API_KEY="" -LOGIN_PAGE_URL=" - #### Manual Install ##### Install Server @@ -162,15 +169,15 @@ You may use the included Dockerfiles to spin up databases quickly if you wish. ###### (Optional) Dockerised Databases -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
MongoDB Image 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` @@ -180,9 +187,9 @@ From the `Server/docker` directory run Redis Image 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` diff --git a/Server/.dockerignore b/Server/.dockerignore deleted file mode 100644 index d88f9054e..000000000 --- a/Server/.dockerignore +++ /dev/null @@ -1 +0,0 @@ -./docker \ No newline at end of file diff --git a/Server/.gitignore b/Server/.gitignore index 09d6b130b..c07bfb34d 100644 --- a/Server/.gitignore +++ b/Server/.gitignore @@ -2,6 +2,3 @@ node_modules .env *.log *.sh -docker/mongo/data/* -docker/redis/data/* -!docker/build_images.sh \ No newline at end of file