forked from noxious/server
?
This commit is contained in:
59
Dockerfile
59
Dockerfile
@ -1,33 +1,46 @@
|
||||
# Use the official Node.js 22.4.1 image
|
||||
FROM node:23.7.0-alpine
|
||||
# Build stage
|
||||
FROM node:23.7.0-alpine AS builder
|
||||
WORKDIR /usr/src/app
|
||||
COPY package*.json ./
|
||||
RUN npm ci
|
||||
COPY . .
|
||||
RUN npm run build
|
||||
|
||||
# Install Redis, MySQL, and tmux
|
||||
RUN apk add --no-cache redis mysql mysql-client tmux && \
|
||||
mkdir -p /run/mysqld && \
|
||||
# Production stage
|
||||
FROM node:23.7.0-alpine
|
||||
LABEL maintainer="Your Name"
|
||||
LABEL version="1.0"
|
||||
LABEL description="NQ Server Application"
|
||||
|
||||
# Install dependencies with versions
|
||||
RUN apk add --no-cache \
|
||||
redis=7.0.15-r0 \
|
||||
mysql=10.11.6-r0 \
|
||||
mysql-client=10.11.6-r0 \
|
||||
tmux=3.3a-r0
|
||||
|
||||
# Create non-root user
|
||||
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
|
||||
|
||||
# Setup MySQL
|
||||
RUN mkdir -p /run/mysqld && \
|
||||
chown -R mysql:mysql /run/mysqld && \
|
||||
mysql_install_db --user=mysql --datadir=/var/lib/mysql
|
||||
|
||||
# Set the working directory in the container
|
||||
WORKDIR /usr/src/
|
||||
WORKDIR /usr/src/app
|
||||
COPY --from=builder /usr/src/app/dist ./dist
|
||||
COPY --from=builder /usr/src/app/package*.json ./
|
||||
COPY docker-start.sh ./dist/start.sh
|
||||
|
||||
# Copy package.json and package-lock.json (if available)
|
||||
COPY package*.json ./
|
||||
RUN npm ci --only=production && \
|
||||
chmod +x ./dist/start.sh && \
|
||||
chown -R appuser:appgroup .
|
||||
|
||||
# Install application dependencies
|
||||
RUN npm install
|
||||
USER appuser
|
||||
|
||||
# Copy the rest of your application code to the container
|
||||
COPY . .
|
||||
|
||||
# Build the application
|
||||
RUN npm run build
|
||||
|
||||
# Expose the ports your Node.js application, Redis, and MySQL will listen on
|
||||
EXPOSE 80 6379 3306
|
||||
|
||||
# Copy and make the startup script executable
|
||||
COPY docker-start.sh /usr/src/dist/start.sh
|
||||
RUN chmod +x /usr/src/dist/start.sh
|
||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
||||
CMD mysqladmin ping -h localhost || exit 1
|
||||
|
||||
# Use the shell script as the entry point
|
||||
CMD ["/usr/src/dist/start.sh"]
|
||||
CMD ["./dist/start.sh"]
|
Reference in New Issue
Block a user