Dockerupdate
This commit is contained in:
61
Dockerfile
61
Dockerfile
@ -1,68 +1,59 @@
|
||||
# syntax=docker/dockerfile:1.4
|
||||
|
||||
# 1. For build React app
|
||||
FROM node:lts AS development
|
||||
# Use Alpine for smaller size and faster package manager
|
||||
FROM node:lts-alpine AS development
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /app
|
||||
|
||||
# Install system dependencies needed for sharp
|
||||
RUN apt-get update && apt-get install -y \
|
||||
libvips-dev \
|
||||
# Install dependencies using apk (much faster than apt)
|
||||
RUN --mount=type=cache,target=/var/cache/apk \
|
||||
apk add --update --no-cache \
|
||||
vips-dev \
|
||||
python3 \
|
||||
make \
|
||||
g++ \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
g++
|
||||
|
||||
# Copy package files
|
||||
COPY package.json /app/package.json
|
||||
COPY package-lock.json /app/package-lock.json
|
||||
COPY package.json package-lock.json ./
|
||||
|
||||
# Install dependencies normally first
|
||||
RUN npm ci --legacy-peer-deps --ignore-scripts
|
||||
# Install npm dependencies with cache
|
||||
RUN --mount=type=cache,target=/root/.npm \
|
||||
npm ci --legacy-peer-deps --ignore-scripts
|
||||
|
||||
# Then install sharp properly for the current platform
|
||||
RUN npm install --platform=linux --arch=x64 sharp
|
||||
# Install sharp
|
||||
RUN --mount=type=cache,target=/root/.npm \
|
||||
npm install --platform=linux --arch=x64 sharp
|
||||
|
||||
COPY . /app
|
||||
COPY . .
|
||||
|
||||
ENV CI=true
|
||||
ENV PORT=3000
|
||||
|
||||
CMD [ "npm", "start" ]
|
||||
|
||||
# Build stage
|
||||
FROM development AS build
|
||||
|
||||
RUN npm run build
|
||||
|
||||
# Development with tools
|
||||
FROM development as dev-envs
|
||||
RUN <<EOF
|
||||
apt-get update
|
||||
apt-get install -y --no-install-recommends git
|
||||
EOF
|
||||
|
||||
RUN <<EOF
|
||||
useradd -s /bin/bash -m vscode
|
||||
groupadd docker
|
||||
usermod -aG docker vscode
|
||||
EOF
|
||||
# install Docker tools (cli, buildx, compose)
|
||||
RUN --mount=type=cache,target=/var/cache/apk \
|
||||
apk add --no-cache git
|
||||
|
||||
RUN adduser -D -s /bin/sh vscode && \
|
||||
addgroup docker && \
|
||||
addgroup vscode docker
|
||||
|
||||
COPY --from=gloursdocker/docker / /
|
||||
CMD [ "npm", "start" ]
|
||||
|
||||
# 2. For Nginx setup
|
||||
FROM nginx:alpine
|
||||
# Production
|
||||
FROM nginx:alpine AS production
|
||||
|
||||
# Copy config nginx
|
||||
COPY --from=build /app/.nginx/nginx.conf /etc/nginx/conf.d/default.conf
|
||||
|
||||
WORKDIR /usr/share/nginx/html
|
||||
|
||||
# Remove default nginx static assets
|
||||
RUN rm -rf ./*
|
||||
|
||||
# Copy static assets from builder stage
|
||||
COPY --from=build /app/build .
|
||||
|
||||
# Containers run nginx with global directives and daemon off
|
||||
ENTRYPOINT ["nginx", "-g", "daemon off;"]
|
||||
Reference in New Issue
Block a user