diff --git a/backend/Dockerfile b/backend/Dockerfile index 53f7d78..6f00042 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -5,15 +5,19 @@ WORKDIR /app COPY . . RUN go mod tidy -RUN CGO_ENABLED=0 GOOS=linux go build -o /main ./cmd/api +# -s -w drops debug symbols; the static binary needs nothing else at runtime. +RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="-s -w" -o /main ./cmd/api -# Final stage -FROM golang:1.24.4-alpine +# Final stage: plain Alpine instead of the Go toolchain image. It keeps a +# shell for the compose files that start the binary with `sh -c`. +FROM alpine:3.22 -WORKDIR / +RUN adduser -D -H -u 10001 app COPY --from=builder /main /main +USER app + EXPOSE 8000 -CMD ["/main"] \ No newline at end of file +CMD ["/main"] diff --git a/frontend/.dockerignore b/frontend/.dockerignore new file mode 100644 index 0000000..d5ddc3f --- /dev/null +++ b/frontend/.dockerignore @@ -0,0 +1,5 @@ +# Installed and built inside the image; host copies would overwrite them. +node_modules +.next +.env*.local +npm-debug.log* diff --git a/frontend/Dockerfile b/frontend/Dockerfile index ca26d43..b0f974f 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -1,10 +1,11 @@ # Build stage -FROM node:18-alpine AS builder +FROM node:22-alpine AS builder WORKDIR /app +ENV NEXT_TELEMETRY_DISABLED=1 -COPY package.json ./ -RUN npm install +COPY package.json package-lock.json ./ +RUN npm ci COPY . . @@ -16,16 +17,21 @@ RUN if [ -n "$NEXT_PUBLIC_LIVEKIT_WS_URL" ]; then echo "NEXT_PUBLIC_LIVEKIT_WS_U && if [ -n "$NEXT_PUBLIC_APP_URL" ]; then echo "NEXT_PUBLIC_APP_URL=$NEXT_PUBLIC_APP_URL" >> .env.production.local; fi \ && npm run build -# Final stage -FROM node:18-alpine +# Final stage: only Next.js' standalone server with the dependencies it +# traced, plus static assets. No build cache or dev dependencies. +FROM node:22-alpine WORKDIR /app +ENV NODE_ENV=production \ + PORT=3000 \ + HOSTNAME=0.0.0.0 -COPY --from=builder /app/.next ./.next -COPY --from=builder /app/node_modules ./node_modules -COPY --from=builder /app/package.json ./package.json -COPY --from=builder /app/public ./public +COPY --from=builder --chown=node:node /app/.next/standalone ./ +COPY --from=builder --chown=node:node /app/.next/static ./.next/static +COPY --from=builder --chown=node:node /app/public ./public + +USER node EXPOSE 3000 -CMD ["npm", "start"] +CMD ["node", "server.js"] diff --git a/frontend/next.config.js b/frontend/next.config.js index d03e9cc..8941fd5 100644 --- a/frontend/next.config.js +++ b/frontend/next.config.js @@ -1,6 +1,8 @@ /** @type {import('next').NextConfig} */ const nextConfig = { reactStrictMode: true, + // Docker imajı yalnızca .next/standalone içindeki sunucuyu ve ihtiyaç duyduğu paketleri taşır. + output: 'standalone', async rewrites() { return [ {