init
This commit is contained in:
commit
f0d13cd510
29 files changed
+6868
No files matched your search
@@ -0,0 +1,93 @@
|
||||
# Express.js Optimized Dockerfile
|
||||
# Auto-generated for {{ app_name }}
|
||||
# Node.js Version: {{ node_version }}
|
||||
# Package Manager: {{ package_manager }}
|
||||
|
||||
# ============================================================================
|
||||
# Build arguments
|
||||
# ============================================================================
|
||||
ARG NODE_VERSION={{ node_version }}
|
||||
ARG PACKAGE_MANAGER={{ package_manager }}
|
||||
ARG BUILD_COMMAND={{ build_command }}
|
||||
ARG APP_PORT={{ framework_settings_port }}
|
||||
ARG NODE_ENV=production
|
||||
|
||||
# ============================================================================
|
||||
# Base stage
|
||||
# ============================================================================
|
||||
FROM gitlab.forlife.one:5050/share/node:${NODE_VERSION}-alpine AS base
|
||||
|
||||
# Install dependencies for native modules and health checks
|
||||
RUN apk update && apk add imagemagick && apk add graphicsmagick && apk add tmux && apk add ffmpeg
|
||||
|
||||
RUN apk add --no-cache \
|
||||
libc6-compat \
|
||||
python3 \
|
||||
make \
|
||||
g++ \
|
||||
curl \
|
||||
dumb-init
|
||||
|
||||
# ============================================================================
|
||||
# Production stage
|
||||
# ============================================================================
|
||||
FROM base AS production
|
||||
|
||||
COPY . ./app
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
RUN npm install
|
||||
|
||||
# Build arguments
|
||||
ARG GIT_COMMIT=unknown
|
||||
ARG BUILD_DATE=unknown
|
||||
|
||||
# Set build environment
|
||||
ENV NODE_ENV=production
|
||||
|
||||
# Create build info endpoint
|
||||
RUN mkdir -p src/common && \
|
||||
echo 'export const BUILD_INFO = {"version":"{{ docker_image_tag }}","commit":"'${GIT_COMMIT}'","buildDate":"'${BUILD_DATE}'","framework":"expressjs","nodeVersion":"{{ node_version }}"}' > src/common/build-info.ts
|
||||
|
||||
# Build app
|
||||
RUN npm run build
|
||||
|
||||
# Create non-root user
|
||||
RUN addgroup --system --gid 1001 expressjs && adduser --system --uid 1001 expressjs
|
||||
|
||||
# Ensure dist folder is owned by expressjs user
|
||||
RUN chown -R expressjs:expressjs /app/dist
|
||||
|
||||
# Set environment variables
|
||||
ENV NODE_ENV=production
|
||||
ENV PORT=${APP_PORT}
|
||||
ENV APP_PORT=${APP_PORT}
|
||||
ENV NODE_OPTIONS="--max-old-space-size={{ MEMORY_LIMIT_MB }}"
|
||||
|
||||
RUN echo '#!/bin/sh\n\
|
||||
status=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:${APP_PORT}/health)\n\
|
||||
if [ "$status" -eq 200 ] || [ "$status" -eq 404 ]; then exit 0; fi\n\
|
||||
\n\
|
||||
status=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:${APP_PORT}/)\n\
|
||||
if [ "$status" -eq 200 ] || [ "$status" -eq 404 ]; then exit 0; fi\n\
|
||||
\n\
|
||||
exit 1' > /health-check.sh && \
|
||||
chmod +x /health-check.sh
|
||||
|
||||
# Create logs directory
|
||||
RUN mkdir -p ./logs && chown -R expressjs:expressjs ./logs
|
||||
RUN ([ -d "./src/public" ] && cp -r ./src/public ./dist && chown -R expressjs:expressjs ./dist/public) || true
|
||||
|
||||
# Switch to non-root user
|
||||
USER expressjs
|
||||
|
||||
# Expose port
|
||||
EXPOSE ${APP_PORT}
|
||||
|
||||
# Health check
|
||||
#HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 CMD /health-check.sh
|
||||
|
||||
# Start the application with dumb-init for proper signal handling
|
||||
#CMD ["dumb-init", "node", "dist/main"]
|
||||
CMD {{ RUN_CMD }}
|
||||
Reference in new issue
Block a user