Refactor dockerfiles for clarity

This commit is contained in:
Alex Holliday
2024-10-01 15:52:46 +08:00
parent 3a31387d00
commit 2499925423
20 changed files with 126 additions and 40 deletions

10
Docker/.gitignore vendored
View File

@ -1,7 +1,11 @@
*.sh
!quickstart.sh
!build_images.sh
mongo/data/*
redis/data/*
dev/mongo/data/*
dev/redis/data/*
dist/mongo/data/*
dist/redis/data/*
prod/mongo/data/*
prod/redis/data/*
*.env
certbot/*
prod/certbot/*

View File

@ -1,22 +0,0 @@
FROM node:20-alpine as build
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"]
FROM nginx:1.27.1-alpine
# COPY ./Docker/nginx/default.conf /etc/nginx/conf.d/default.conf
COPY --from=build /app/dist /usr/share/nginx/html
CMD ["nginx", "-g", "daemon off;"]

View File

@ -2,19 +2,19 @@
#!/bin/bash
# Change directory to root Server directory for correct Docker Context
cd ..
cd ../..
#Client
client="./Docker/client.Dockerfile"
client="./Docker/dev/client.Dockerfile"
# MongoDB
mongoDB="./Docker/mongoDB.Dockerfile"
mongoDB="./Docker/dev/mongoDB.Dockerfile"
# Redis
redis="./Docker/redis.Dockerfile"
redis="./Docker/dev/redis.Dockerfile"
# Server
server="./Docker/server.Dockerfile"
server="./Docker/dev/server.Dockerfile"
docker build -f $client -t uptime_client .
docker build -f $mongoDB -t uptime_database_mongo .

View File

@ -0,0 +1,15 @@
FROM node:20-alpine AS build
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"]

View File

@ -0,0 +1,30 @@
services:
client:
image: uptime_client:latest
ports:
- "5173:5173"
depends_on:
- server
server:
image: uptime_server:latest
ports:
- "5000:5000"
env_file:
- server.env
depends_on:
- redis
- mongodb
redis:
image: uptime_redis:latest
ports:
- "6379:6379"
volumes:
- ./redis/data:/data
mongodb:
image: uptime_database_mongo:latest
command: ["mongod", "--quiet"]
ports:
- "27017:27017"
volumes:
- ./mongo/data:/data/db

View File

@ -0,0 +1,3 @@
FROM mongo
EXPOSE 27017
CMD ["mongod"]

View File

@ -0,0 +1,13 @@
FROM node:20-alpine
WORKDIR /app
COPY ../../Server/package*.json ./
RUN npm install
COPY ../../Server/ ./
EXPOSE 5000
CMD ["node", "index.js"]

View File

@ -1,19 +1,19 @@
FROM node:20-alpine as build
FROM node:20-alpine AS build
WORKDIR /app
COPY ./Client/package*.json ./
COPY ../../Client/package*.json ./
RUN npm install
COPY ./Client .
COPY ../../Client .
RUN npm run build
FROM nginx:1.27.1-alpine
COPY ./Docker/nginx/conf.d/dist_default.conf /etc/nginx/conf.d/default.conf
COPY ./Docker/dist/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf
COPY --from=build /app/dist /usr/share/nginx/html
CMD ["nginx", "-g", "daemon off;"]

View File

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

View File

@ -1,4 +0,0 @@
FROM mongo
COPY ./Docker/mongo/init/create_users.js /docker-entrypoint-initdb.d/
EXPOSE 27017
CMD ["mongod"]

24
Docker/prod/build_images.sh Executable file
View File

@ -0,0 +1,24 @@
#!/bin/bash
# Change directory to root directory for correct Docker Context
cd ../..
#Client
client="./Docker/prod/client.Dockerfile"
# MongoDB
mongoDB="./Docker/prod/mongoDB.Dockerfile"
# Redis
redis="./Docker/prod/redis.Dockerfile"
# Server
server="./Docker/prod/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 .
echo "All images built"

View File

@ -0,0 +1,17 @@
FROM node:20-alpine AS build
WORKDIR /app
COPY ../../Client/package*.json ./
RUN npm install
COPY ../../Client .
RUN npm run build
FROM nginx:1.27.1-alpine
COPY --from=build /app/dist /usr/share/nginx/html
CMD ["nginx", "-g", "daemon off;"]

View File

@ -0,0 +1,4 @@
FROM mongo
COPY ./Docker/prod/mongo/init/create_users.js /docker-entrypoint-initdb.d/
EXPOSE 27017
CMD ["mongod"]

View File

@ -0,0 +1,2 @@
FROM redis
EXPOSE 6379