diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000000000000000000000000000000000000..c1f34c88117ebc8a62c85979ca4b9b4768e31828 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +node_modules/ +Dockerfile +docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d8f482e6a285a1f2d630a8da5547e193adc30922 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,30 @@ +# Stage 1: builder (instala dependências e compila TS) +FROM oven/bun:1.2.13-alpine AS builder +WORKDIR /app + +# Copia arquivos de dependências do Bun antes do código para aproveitar cache +COPY package.json bun.lockb bunfig.toml ./ +RUN bun install --frozen-lockfile --production + +# Copia todo o código-fonte e executa o build do projeto +COPY . . + +# Stage 2: runtime (imagem final leve) +FROM oven/bun:1.2.13-alpine AS runtime +WORKDIR /app + +# Definir modo de produção (opcional, dependendo do app) +ENV NODE_ENV=production + +# Copia só o código compilado e as dependências de produção do builder +COPY --from=builder /app /app + +# Expõe a porta padrão da API (Hono geralmente usa 3000) +EXPOSE 3000 + +# Usa o usuário não-root fornecido pelo Bun para executar +USER bun + +# Inicia a aplicação +ENTRYPOINT ["bun", "run", "src/index.ts"] + diff --git a/README.md b/README.md index 9ade0d32628fb4bd06dbc241d6103788eb349150..5886091d61932158c9c177160b337ab29f8e47c2 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ + ## Running for dev @@ -7,6 +8,8 @@ 2. Install bun https://bun.sh/docs/installation +2.1. Be sure you got a version that's above 1.2.13. + 3. To install dependencies: ```sh bun install @@ -15,11 +18,12 @@ 4. Get the container up and running: ```sh - docker compose up + docker compose --profile test up ``` 5. set dev db ``` + bun db:generate bun db:migrate bun db:seed ``` @@ -31,3 +35,16 @@ ``` 7. open http://localhost:3000 + +## Running for production + +1. Make a copy of .env.example to .env + ```mv .env.example .env``` + +2. Set env vars in .env + +3. Get the container up and running: + ```docker compose --profile prod up --build -d``` + +4. Server is now running in http://localhost:3000 + diff --git a/bun.lockb b/bun.lockb index c6fab67ceda4fd6f25551f4c2a416322ac7ac6ae..906ed9a589feee5e8d64813de80e168671ea1644 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/docker-compose.yml b/docker-compose.yml index 54f8f92ab3070e52457fbe38d559ca45e0e638ae..a41b083aaf3e03d8caa8a6b4e6df48186074247e 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,9 +12,26 @@ services: - apex_network volumes: - postgres_data:/var/lib/postgresql/data + profiles: + - test # Banco só é ativado com --profile test + + app: + image: oven/bun:1.2.13 + build: + context: . + dockerfile: Dockerfile + ports: + - "3000:3000" + env_file: + - .env + networks: + - apex_network + profiles: + - prod # Backend só é ativado com --profile prod volumes: postgres_data: networks: apex_network: + diff --git a/package.json b/package.json index dc6c791f39f0e0e41553932347c303a78fd7e115..d632f91e3051c3ed678f074473c627f60b622550 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "db:migrate": "cross-env DB_MIGRATING=true bun run src/db/migrate.ts", "db:seed": "cross-env DB_SEEDING=true bun run src/db/seed.ts", "db:studio": "drizzle-kit studio", - "route:test": "bun db:seed && bun test" + "route:test": "bun db:seed && bun test", }, "dependencies": { "@aws-sdk/client-s3": "^3.750.0",