From de5e8ab5600e1c467df57c2c5833dea269513494 Mon Sep 17 00:00:00 2001 From: tobias Date: Thu, 20 Jun 2024 10:37:21 +0200 Subject: [PATCH] Create dev script --- Dockerfile | 36 ++++++++++++++++------------ docker-compose.yml | 58 ++++++++++++++++++++++------------------------ package.json | 3 ++- 3 files changed, 51 insertions(+), 46 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6d173b3..ea3b2a1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,38 +1,44 @@ # Build stage -FROM node:20-slim as builder +FROM node:20-slim as base ENV PNPM_HOME="/pnpm" ENV PATH="$PNPM_HOME:$PATH" RUN corepack enable - -WORKDIR /builder +WORKDIR /base COPY package.json pnpm-lock.yaml ./ RUN pnpm install --frozen-lockfile -ENV NODE_ENV=production - COPY . . + +# Development +FROM base AS dev +ENTRYPOINT [] +CMD ["pnpm", "dev:next"] + + +# Production +FROM base AS builder +ENV NODE_ENV=production RUN pnpm build -# Production stage: serve the application +# Production: copy build artifacts FROM node:20-slim as runner -WORKDIR /runner +WORKDIR /prod ENV PNPM_HOME="/pnpm" ENV PATH="$PNPM_HOME:$PATH" RUN corepack enable -## Copy build artifacts from the build stage -COPY --from=builder /builder/package.json ./ -#COPY --from=builder /builder/node_modules ./node_modules -COPY --from=builder /builder/.next/standalone ./.next/standalone/ -COPY --from=builder /builder/.next/static ./.next/standalone/.next/static -COPY --from=builder /builder/public ./.next/standalone/public -COPY --from=builder /builder/next.config.mjs ./ +COPY --from=builder /base/package.json ./ +COPY --from=builder /base/.next/standalone ./.next/standalone/ +COPY --from=builder /base/.next/static ./.next/standalone/.next/static +COPY --from=builder /base/public ./.next/standalone/public +COPY --from=builder /base/next.config.mjs ./ -FROM runner as server +# Production: serve the website +FROM runner as prod EXPOSE 3000 COPY docker-entrypoint.sh /docker-entrypoint.sh ENTRYPOINT ["/docker-entrypoint.sh"] diff --git a/docker-compose.yml b/docker-compose.yml index 71485a2..e15b38c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,50 +1,48 @@ +--- services: nextjs: - image: git.autonomic.zone/autonomic-cooperative/nextload:latest - container_name: ${NAME}-nextjs + image: git.autonomic.zone/autonomic-cooperative/nextload-dev:latest restart: unless-stopped - # build: - # context: payload - # target: dev + build: + context: ./ + target: dev environment: - DEV: 1 - NAME: ${NAME} - PAYLOAD_SECRET: ${PAYLOAD_SECRET} - NODE_ENV: development - MONGODB_URI: "mongodb://$MONGODB_USER:$MONGODB_PASSWORD@$MONGODB_HOST:27017" - # volumes: - # - ./payload/src:/base/src - # # - ./astro/src/types.ts:/types.ts - # - payload_media:/base/src/media + - "NAME=${STACK_NAME}" + - "PAYLOAD_SECRET=${PAYLOAD_SECRET}" + - "MONGODB_USER=mongo" + - "MONGODB_HOST=${STACK_NAME}_mongo" + - "MONGODB_PORT=27017" + - "MONGODB_PASSWORD=${MONGO_PASSWORD}" + - "REPOSITORY" + - "PORT=3000" + - "HOSTNAME=0.0.0.0" + - "MONGODB_URI=mongodb://${MONGO_USER}:${MONGO_PASSWORD}@mongo:27017" + #volumes: + # Must be changed for dev as it is not standalone + #- payload_uploads:/runner/.next/standalone/.next/media + networks: + - internal ports: - 3000:3000 - networks: - - front - - back - depends_on: - - mongo mongo: - container_name: ${NAME}-mongo image: mongo:6.0.5 restart: unless-stopped - ports: - - 27017:27017 volumes: - mongo:/data/db command: - --storageEngine=wiredTiger environment: - MONGO_INITDB_ROOT_USERNAME: ${MONGODB_USER} - MONGO_INITDB_ROOT_PASSWORD: ${MONGODB_PASSWORD} - + - "MONGO_INITDB_ROOT_USERNAME=mongo" + - "MONGO_INITDB_ROOT_PASSWORD=${MONGO_PASSWORD}" networks: - - back + - internal + ports: + - 27017:27017 networks: - front: - back: + internal: -volumes: +volumes: mongo: - payload_media: + payload_uploads: diff --git a/package.json b/package.json index 1696d6c..0c76d7c 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "private": true, "type": "module", "scripts": { - "dev": "cross-env NODE_OPTIONS=--no-deprecation next dev", + "dev": "docker compose up", + "dev:next": "cross-env NODE_OPTIONS=--no-deprecation next dev", "devturbo": "cross-env NODE_OPTIONS=--no-deprecation next dev --turbo", "devsafe": "rm -rf .next && cross-env NODE_OPTIONS=--no-deprecation next dev", "build": "cross-env NODE_OPTIONS=--no-deprecation next build",