Skip to content

Commit

Permalink
Merge pull request #8 from fga-eps-mds/fix#42/fix-docker
Browse files Browse the repository at this point in the history
[FIX] Modifica Dockerfile para uso em Ambiente de Desenvolvimento e Produção (fga-eps-mds/2024.2-ARANDU-DOC#42)
  • Loading branch information
dartmol203 authored Dec 4, 2024
2 parents f900276 + 2a7117d commit 26b5401
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 19 deletions.
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Dockerfile
Dockerfile.prod
.dockerignore
node_modules
npm-debug.log
README.md
docker
.git
10 changes: 7 additions & 3 deletions .env.dev.template
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
NEXT_PUBLIC_API_URL=
NEXTAUTH_URL=
NEXTAUTH_SECRET=
NEXT_PUBLIC_API_URL_USER=http://localhost:3000
NEXT_PUBLIC_API_URL_STUDIO=http://localhost:3002
NEXTAUTH_URL=http://localhost:4000
NEXTAUTH_SECRET=
JWT_SECRET=
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
7 changes: 7 additions & 0 deletions .env.prod.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
NEXT_PUBLIC_API_URL_USER=http://localhost:3000
NEXT_PUBLIC_API_URL_STUDIO=http://localhost:3002
NEXTAUTH_URL=http://localhost:4000
NEXTAUTH_SECRET=
JWT_SECRET=
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
40 changes: 35 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,43 @@
FROM node:18
FROM node:22-alpine AS base

WORKDIR /src
FROM base AS deps
RUN apk add --no-cache libc6-compat

COPY package*.json ./
WORKDIR /app

RUN npm install
COPY package.json package-lock.json* ./
RUN \
if [ -f package-lock.json ]; then npm ci; \
fi


FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .


COPY .env .env.production
RUN npm run build

FROM base AS runner
WORKDIR /app

ENV NODE_ENV=production

RUN addgroup -g 1001 -S nodejs \
&& adduser -S arandu -u 1001

COPY --from=builder --chown=arandu:nodejs /app/.next/standalone ./
COPY --from=builder --chown=arandu:nodejs /app/.next/static ./.next/static

RUN mkdir -p .next/cache \
&& chown -R arandu:nodejs .next

USER arandu

EXPOSE 4000

CMD ["npm", "run", "dev"]
ENV PORT=4000

CMD ["node", "server.js"]
41 changes: 41 additions & 0 deletions Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
FROM node:22-alpine AS base

FROM base AS deps
RUN apk add --no-cache libc6-compat

WORKDIR /app

COPY package.json package-lock.json* ./
RUN \
if [ -f package-lock.json ]; then npm ci; \
fi

FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .

COPY .env.prod.template .env.production
RUN npm run build

FROM base AS runner
WORKDIR /app

ENV NODE_ENV=production

RUN addgroup -g 1001 -S nodejs \
&& adduser -S arandu -u 1001

COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static

RUN mkdir -p .next/cache \
&& chown -R arandu:nodejs .next

USER arandu

EXPOSE 4000

ENV PORT=4000

CMD ["node", "server.js"]
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.PHONY: build
build:
docker compose build

.PHONY: start
start:
docker compose up

.PHONY: run
run:
docker compose up --build

.PHONY: stop
stop:
docker compose down
16 changes: 6 additions & 10 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,15 @@ services:
front-api:
container_name: front-api
restart: on-failure
build: .
build:
context: ./
dockerfile: Dockerfile
image: front-api
ports:
- "4000:4000"
environment:
- NODE_ENV=development
volumes:
- ./src:/app/src
env_file:
- .env
networks:
- calculus-network

- arandu-network

networks:
calculus-network:
arandu-network:
driver: bridge
1 change: 1 addition & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
output: 'standalone'
}

module.exports = nextConfig
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@
"react-dom": "^18.3.1",
"react-hook-form": "^7.52.1",
"react-markdown": "^9.0.1",
"react-table": "^7.8.0",
"react-multi-carousel": "^2.8.5",
"react-table": "^7.8.0",
"react-toastify": "^10.0.5",
"rehype-katex": "^7.0.0",
"rehype-raw": "^7.0.0",
"remark-gfm": "^4.0.0",
"remark-math": "^6.0.0",
"sharp": "^0.33.5",
"sonner": "^1.5.0",
"tailwind-merge": "^2.5.2",
"tailwindcss-animate": "^1.0.7",
Expand Down

0 comments on commit 26b5401

Please sign in to comment.