diff --git a/client/Dockerfile b/client/Dockerfile index bccabe37..6d79224e 100644 --- a/client/Dockerfile +++ b/client/Dockerfile @@ -9,17 +9,17 @@ COPY package.json yarn.lock ./ RUN yarn install --frozen-lockfile -FROM node:17-alpine AS builder +FROM deps AS builder WORKDIR /app -COPY --from=deps /app/node_modules ./node_modules -COPY . . - ARG API_URL -ENV NEXT_TELEMETRY_DISABLED=1 +ENV NODE_ENV=production ENV API_URL=${API_URL:-http://localhost:3000} +ENV NEXT_TELEMETRY_DISABLED=1 + +COPY . . RUN yarn build @@ -27,13 +27,13 @@ FROM node:17-alpine AS runner WORKDIR /app -ARG NODE_ENV - ENV NEXT_TELEMETRY_DISABLED=1 -ENV NODE_ENV=${NODE_ENV:-production} +ENV PORT=3001 + +EXPOSE ${PORT} -RUN addgroup --system --gid 1001 nodejs -RUN adduser --system --uid 1001 nextjs +RUN addgroup --system --gid 1001 nodejs && \ + adduser --system --uid 1001 nextjs COPY --from=builder /app/next.config.mjs ./ COPY --from=builder /app/public ./public @@ -43,8 +43,4 @@ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static USER nextjs -ENV PORT=3001 - -EXPOSE 3001 - CMD ["node", "server.js"] diff --git a/docker-compose.yml b/docker-compose.yml index 27bcc14c..3b4063ce 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,8 +2,6 @@ services: server: build: context: ./server - args: - - NODE_ENV=production container_name: server restart: unless-stopped user: 1000:1000 @@ -17,8 +15,8 @@ services: - WELCOME_TITLE - ENABLE_ADMIN - DRIFT_HOME - ports: - - "3000:3000" + # ports: + # - "3000:3000" # only expose if needed client: build: context: ./client diff --git a/server/Dockerfile b/server/Dockerfile index a5c9bc5c..dcc6bdae 100644 --- a/server/Dockerfile +++ b/server/Dockerfile @@ -9,38 +9,31 @@ COPY package.json yarn.lock tsconfig.json tslint.json ./ RUN yarn install --frozen-lockfile -FROM node:17-alpine AS builder +FROM deps AS builder WORKDIR /app -COPY --from=deps /app/node_modules ./node_modules -COPY . . - -ARG NODE_ENV +ENV NODE_ENV=production -ENV NODE_ENV=${NODE_ENV:-production} +COPY . . -RUN apk add --no-cache git RUN yarn build:docker FROM node:17-alpine AS runner WORKDIR /app -ARG NODE_ENV +ENV NODE_ENV=production +ENV PORT=3000 -ENV NODE_ENV=${NODE_ENV:-production} +EXPOSE ${PORT} -RUN addgroup --system --gid 1001 nodejs -RUN adduser --system --uid 1001 drift +RUN addgroup --system --gid 1001 nodejs && \ + adduser --system --uid 1001 drift COPY --from=builder /app/dist ./dist COPY --from=builder /app/node_modules ./node_modules USER drift -ENV PORT=3000 - -EXPOSE 3000 - CMD ["node", "dist/index.js"]