diff --git a/agenta-web/dev.Dockerfile b/agenta-web/dev.Dockerfile index c155bc07db..1e5e0c16f5 100644 --- a/agenta-web/dev.Dockerfile +++ b/agenta-web/dev.Dockerfile @@ -1,21 +1,17 @@ -FROM node:18-alpine +FROM node:22-alpine3.18 AS base WORKDIR /app # Install dependencies based on the preferred package manager COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./ RUN \ - # echo "Standalone: $NEXT_PUBLIC_STANDALONE"; \ - # if [[ ! $NEXT_PUBLIC_STANDALONE == "true" ]]; then \ - if [ -f yarn.lock ]; then yarn --frozen-lockfile; \ - elif [ -f package-lock.json ]; then npm i; \ - elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i; \ - # Allow install without lockfile, so example works even without Node.js installed locally - else echo "Warning: Lockfile not found. It is recommended to commit lockfiles to version control." && yarn install; \ + if [ -f yarn.lock ]; then yarn install --frozen-lockfile; \ + elif [ -f package-lock.json ]; then npm install; \ + elif [ -f pnpm-lock.yaml ]; then npm install -g pnpm && pnpm install; \ + else yarn install; \ fi -# else echo "NEXT_PUBLIC_STANDALONE is set, skipping install"; \ -# fi +# Copy only the necessary files for development COPY src ./src COPY public ./public COPY next.config.js . @@ -23,25 +19,31 @@ COPY tsconfig.json . COPY postcss.config.js . COPY tailwind.config.ts . COPY .env . -RUN if [ -f .env.local ]; then cp .env.local .; fi -# RUN if [ -f tailwind.config.ts ]; then cp tailwind.config.ts .; fi -# # used in cloud COPY sentry.* . -# Next.js collects completely anonymous telemetry data about general usage. Learn more here: https://nextjs.org/telemetry -# Uncomment the following line to disable telemetry at run time -# ENV NEXT_TELEMETRY_DISABLED 1 -# Note: Don't expose ports here, Compose will handle that for us +# Stage 2: Development Stage +FROM node:22-alpine3.18 AS dev + +WORKDIR /app + +# Copy dependencies and application files from the base stage +COPY --from=base /app /app + +# Install development dependencies +RUN \ + if [ -f yarn.lock ]; then yarn install; \ + elif [ -f package-lock.json ]; then npm install; \ + elif [ -f pnpm-lock.yaml ]; then pnpm install; \ + else yarn install; \ + fi + +# Expose the necessary ports +EXPOSE 3000 # Start Next.js in development mode based on the preferred package manager CMD \ - # echo "Standalone: $NEXT_PUBLIC_STANDALONE"; \ - # if [[ ! $NEXT_PUBLIC_STANDALONE == "true" ]]; then \ if [ -f yarn.lock ]; then yarn dev; \ elif [ -f package-lock.json ]; then npm run dev; \ elif [ -f pnpm-lock.yaml ]; then pnpm dev; \ else yarn dev; \ fi -# else echo "NEXT_PUBLIC_STANDALONE is set, skipping run"; \ -# fi - diff --git a/agenta-web/prod.Dockerfile b/agenta-web/prod.Dockerfile index dbe9b9da3c..a2b8e55c60 100644 --- a/agenta-web/prod.Dockerfile +++ b/agenta-web/prod.Dockerfile @@ -1,11 +1,11 @@ -FROM node:18-alpine +# Stage 1: Build Stage +FROM node:22-alpine3.18 AS builder WORKDIR /app # Install only production dependencies COPY package.json package-lock.json* ./ -RUN npm ci --omit=dev - +RUN npm ci # Copy only necessary files COPY src ./src COPY public ./public @@ -14,10 +14,27 @@ COPY tsconfig.json . COPY postcss.config.js . COPY tailwind.config.ts . COPY .env.production . -# used in cloud COPY sentry.* . + # Build the Next.js app for production RUN npm run build +# Stage 2: Production Stage +FROM node:22-alpine3.18 AS prod + +WORKDIR /app + +# Copy only the necessary files from the build stage +COPY --from=builder /app/package.json /app/package-lock.json* /app +COPY --from=builder /app/.next /app/.next +COPY --from=builder /app/public /app/public +COPY --from=builder /app/next.config.js /app/tsconfig.json /app/postcss.config.js /app/tailwind.config.ts /app/.env.production /app/sentry.* /app/ + +# Install only production dependencies +RUN npm ci --omit=dev + +# Expose the necessary port +EXPOSE 3000 + # Start the production server CMD ["npm", "start"] diff --git a/docker-compose.yml b/docker-compose.yml index 476dede0cd..2832585b27 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -167,3 +167,4 @@ networks: volumes: mongodb_data: redis_data: + nextjs_cache: \ No newline at end of file