Reduce docker build time and size and finx nginx config not producing a UI
This commit is contained in:
@@ -22,25 +22,35 @@ RUN apk add --no-cache python3 make g++ \
|
|||||||
&& rm -rf /root/.npm
|
&& rm -rf /root/.npm
|
||||||
|
|
||||||
# Stage 4: Final production image
|
# Stage 4: Final production image
|
||||||
FROM mongo:4.4-focal
|
FROM ubuntu:20.04
|
||||||
|
|
||||||
# Install Node.js and nginx
|
# Prevent interactive prompts during package installation
|
||||||
RUN rm -f /etc/apt/sources.list.d/mongodb*.list && \
|
ENV DEBIAN_FRONTEND=noninteractive
|
||||||
apt-get update && \
|
|
||||||
# Install curl and gnupg for Node.js repository
|
# Install MongoDB 4.4
|
||||||
|
RUN apt-get update && \
|
||||||
apt-get install -y --no-install-recommends \
|
apt-get install -y --no-install-recommends \
|
||||||
curl \
|
wget \
|
||||||
gnupg && \
|
gnupg \
|
||||||
# Add Node.js repository and install Node.js and nginx
|
ca-certificates && \
|
||||||
curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && \
|
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | apt-key add - && \
|
||||||
|
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-4.4.list && \
|
||||||
|
# Install Node.js, nginx, and MongoDB
|
||||||
|
wget -qO- https://deb.nodesource.com/setup_18.x | bash - && \
|
||||||
apt-get update && \
|
apt-get update && \
|
||||||
apt-get install -y --no-install-recommends \
|
apt-get install -y --no-install-recommends \
|
||||||
nodejs \
|
nodejs \
|
||||||
nginx && \
|
nginx \
|
||||||
|
mongodb-org=4.4.24 \
|
||||||
|
mongodb-org-server=4.4.24 \
|
||||||
|
mongodb-org-shell=4.4.24 \
|
||||||
|
mongodb-org-mongos=4.4.24 \
|
||||||
|
mongodb-org-tools=4.4.24 && \
|
||||||
# Cleanup
|
# Cleanup
|
||||||
apt-get clean && \
|
apt-get clean && \
|
||||||
rm -rf /var/lib/apt/lists/* && \
|
rm -rf /var/lib/apt/lists/* && \
|
||||||
rm -rf /var/cache/apt/*
|
rm -rf /var/cache/apt/* && \
|
||||||
|
rm -rf /root/.npm /tmp/*
|
||||||
|
|
||||||
# Configure nginx and copy frontend
|
# Configure nginx and copy frontend
|
||||||
COPY docker/nginx.conf /etc/nginx/nginx.conf
|
COPY docker/nginx.conf /etc/nginx/nginx.conf
|
||||||
@@ -54,8 +64,8 @@ COPY --from=bcrypt-builder /app/node_modules/bcrypt /app/node_modules/bcrypt
|
|||||||
COPY --from=backend-builder /app/src/backend ./src/backend
|
COPY --from=backend-builder /app/src/backend ./src/backend
|
||||||
|
|
||||||
# Create necessary directories and set permissions
|
# Create necessary directories and set permissions
|
||||||
RUN mkdir -p /data/db /var/log/{nginx,mongodb} /var/lib/nginx \
|
RUN mkdir -p /data/db /var/log/{nginx,mongodb} /var/lib/nginx /var/run/mongodb \
|
||||||
&& chown -R mongodb:mongodb /data/db /var/log/mongodb \
|
&& chown -R mongodb:mongodb /data/db /var/log/mongodb /var/run/mongodb \
|
||||||
&& chown -R www-data:www-data /var/log/nginx /var/lib/nginx \
|
&& chown -R www-data:www-data /var/log/nginx /var/lib/nginx \
|
||||||
&& rm -rf /root/.npm /tmp/*
|
&& rm -rf /root/.npm /tmp/*
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,24 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
# Create MongoDB pid directory if it doesn't exist
|
||||||
|
mkdir -p /var/run/mongodb
|
||||||
|
chown mongodb:mongodb /var/run/mongodb
|
||||||
|
|
||||||
# Start MongoDB
|
# Start MongoDB
|
||||||
echo "Starting MongoDB..."
|
echo "Starting MongoDB..."
|
||||||
mongod --fork --dbpath $MONGODB_DATA_DIR --logpath $MONGODB_LOG_DIR/mongodb.log
|
mongod --fork --dbpath $MONGODB_DATA_DIR --logpath $MONGODB_LOG_DIR/mongodb.log --pidfilepath /var/run/mongodb/mongod.pid
|
||||||
|
|
||||||
# Wait for MongoDB to be ready
|
# Wait for MongoDB to be ready (using mongo instead of mongosh for MongoDB 4.4)
|
||||||
echo "Waiting for MongoDB to start..."
|
echo "Waiting for MongoDB to start..."
|
||||||
until mongo --eval "print(\"waited for connection\")" > /dev/null 2>&1; do
|
until mongo --eval "print(\"waited for connection\")" > /dev/null 2>&1; do
|
||||||
sleep 0.5
|
sleep 0.5
|
||||||
|
# Check if MongoDB is still running
|
||||||
|
if ! pgrep -x "mongod" > /dev/null; then
|
||||||
|
echo "MongoDB failed to start. Checking logs:"
|
||||||
|
cat $MONGODB_LOG_DIR/mongodb.log
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
echo "MongoDB has started"
|
echo "MongoDB has started"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user