Files
web-hosts/domains/coppertone.tech/frontend/Containerfile
2025-12-26 13:38:04 +01:00

50 lines
1.3 KiB
Docker

# Build Stage
FROM node:lts AS build
# Install pnpm
RUN corepack enable && corepack prepare pnpm@latest --activate
WORKDIR /app
# Copy package files first to leverage Docker cache
COPY package.json pnpm-lock.yaml ./
RUN pnpm install --frozen-lockfile
# Copy the rest of the frontend application code
COPY . .
# Build the Vue.js application
RUN pnpm run build
# Production Stage
FROM docker.io/library/nginx:stable-alpine AS production
# Create non-root user for nginx
RUN addgroup -g 1000 appuser && \
adduser -D -u 1000 -G appuser appuser && \
chown -R appuser:appuser /var/cache/nginx && \
chown -R appuser:appuser /var/log/nginx && \
chown -R appuser:appuser /etc/nginx/conf.d && \
touch /var/run/nginx.pid && \
chown -R appuser:appuser /var/run/nginx.pid
# Copy custom Nginx configuration (to be created later)
COPY nginx.conf /etc/nginx/conf.d/default.conf
# Copy built assets from the build stage
COPY --from=build --chown=appuser:appuser /app/dist /usr/share/nginx/html
# Switch to non-root user
USER appuser
# Expose port 8080 (non-root can't bind to ports < 1024)
EXPOSE 8080
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/ || exit 1
# Start Nginx
CMD ["nginx", "-g", "daemon off;"]