ScoreSaberUtils-Script/Dockerfile

45 lines
1.3 KiB
Docker
Raw Normal View History

2024-04-25 22:39:26 +00:00
FROM node:21-alpine AS base
2024-04-25 22:40:53 +00:00
# Install dependencies only when needed
FROM base AS deps
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
2024-04-25 22:39:26 +00:00
WORKDIR /app
2024-04-25 22:40:53 +00:00
# Install dependencies based on the preferred package manager
2024-04-25 22:39:26 +00:00
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
RUN \
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci; \
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \
else echo "Lockfile not found." && exit 1; \
fi
# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
2024-04-25 23:12:22 +00:00
# Get the git commit hash
ARG GIT_REV
ENV GIT_REV ${GIT_REV}
2024-04-25 22:39:26 +00:00
# Set the environment to production
ENV NODE_ENV=production
# Build the scripts
RUN \
if [ -f yarn.lock ]; then yarn run build; \
elif [ -f package-lock.json ]; then npm run build; \
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \
else echo "Lockfile not found." && exit 1; \
fi
FROM nginx:alpine AS runner
2024-04-25 23:09:20 +00:00
COPY --from=builder /app/dist/ /var/www/html
2024-04-25 23:04:19 +00:00
COPY --from=builder /app/nginx.conf /etc/nginx/nginx.conf
2024-04-25 22:39:26 +00:00
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]