short-url/Dockerfile

33 lines
1.1 KiB
Docker
Raw Normal View History

2024-11-30 08:19:57 +08:00
# Stage 1: Install dependencies
2024-11-29 20:46:12 +08:00
FROM node:18-alpine AS builder
WORKDIR /app
2024-11-30 13:56:24 +08:00
RUN sed -i 's#https\?://dl-cdn.alpinelinux.org/alpine#https://mirrors.tuna.tsinghua.edu.cn/alpine#g' /etc/apk/repositories
2024-11-29 20:46:12 +08:00
RUN apk update
RUN npm config set registry https://registry.npmmirror.com
COPY package*.json ./
RUN npm ci
2024-11-30 08:19:57 +08:00
# Stage 2: Build the applicatio
2024-11-29 20:46:12 +08:00
COPY . .
RUN apk add --no-cache build-base python3 g++ make
RUN npm rebuild better-sqlite3 --update-binary
2024-11-30 08:19:57 +08:00
RUN mkdir -p /app/data
2024-11-29 20:46:12 +08:00
RUN npm run build
2024-11-30 08:19:57 +08:00
# Stage 3: Production image
2024-11-29 20:46:12 +08:00
FROM node:18-alpine AS runner
2024-11-30 08:19:57 +08:00
RUN mkdir -p /app/data && chmod 755 /app/data
2024-11-29 20:46:12 +08:00
WORKDIR /app
2024-11-30 13:56:24 +08:00
RUN sed -i 's#https\?://dl-cdn.alpinelinux.org/alpine#https://mirrors.tuna.tsinghua.edu.cn/alpine#g' /etc/apk/repositories
2024-11-29 20:46:12 +08:00
RUN apk update
2024-11-30 08:19:57 +08:00
ENV NODE_ENV Production
2024-11-29 20:46:12 +08:00
COPY --from=builder /app/next.config.js ./
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
2024-11-30 08:19:57 +08:00
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package*.json ./
COPY --from=builder /app/data/shorturl.db ./data
2024-11-29 20:46:12 +08:00
VOLUME /app/data
2024-11-30 13:56:24 +08:00
# Run App
2024-11-30 08:19:57 +08:00
CMD ["node", "server.js"]