Skip to content

Commit

Permalink
production ready docker
Browse files Browse the repository at this point in the history
  • Loading branch information
while1618 committed Dec 30, 2024
1 parent 3eb1316 commit 020af7f
Show file tree
Hide file tree
Showing 11 changed files with 199 additions and 59 deletions.
46 changes: 23 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,26 @@ Login credentials:

### Environment variables

| Variable | Description | Default |
| ------------------------ | --------------------------------------------------------------------- | -------------------------------- |
| APP_NAME | Name of the app that will be used in the application | BootstrapBugZ |
| UI_URL | URL on which UI is running | http://bootstrapbugz-ui:5173 |
| UI_PORT | Port on which you'll find UI running | 5173 |
| API_URL | URL on which API is running | http://bootstrapbugz-api:8080/v1 |
| SERVER_PORT | Port on which you'll find API running | 8080 |
| POSTGRES_HOST | Host on which postgres is running, used when locally starting the API | localhost |
| POSTGRES_PORT | Port on which you'll find postgres running | 5432 |
| POSTGRES_DATABASE | Name of the postgres database | bootstrapbugz |
| POSTGRES_USERNAME | Postgres username | postgres |
| POSTGRES_PASSWORD | Postgres password | root |
| REDIS_HOST | Host on which redis is running, used when locally starting the API | 127.0.0.1 |
| REDIS_PORT | Port on which you'll find redis running | 6379 |
| REDIS_DATABASE | Name of the redis database | 0 |
| REDIS_PASSWORD | Redis password | root |
| MAIL_HOST | SMTP host | smtp.mailgun.org |
| MAIL_PORT | SMTP port | 587 |
| MAIL_USERNAME | SMTP username | username |
| MAIL_PASSWORD | SMTP password | password |
| JWT_SECRET | Secret used to sign jwt | secret |
| SPRING_SECURITY_PASSWORD | Password used for auto-generated users | qwerty123 |
| HTTP_PROTOCOL | http protocol | http |
| Variable | Description | Default |
| ------------------------ | --------------------------------------------------------------------------------------------------------- | ---------------- |
| APP_NAME | Name of the app that will be used in the application | BootstrapBugZ |
| HTTP_PROTOCOL | HTTP protocol | http |
| UI_HOST | UI Host | localhost |
| UI_PORT | Port on which you'll find UI running | 5173 |
| API_PORT | Port on which you'll find API running | 8080 |
| POSTGRES_HOST | **Used only to override application.properties when starting locally.** Host on which postgres is running | localhost |
| POSTGRES_PORT | Port on which you'll find postgres running | 5432 |
| POSTGRES_DATABASE | Name of the postgres database | bootstrapbugz |
| POSTGRES_USERNAME | Postgres username | postgres |
| POSTGRES_PASSWORD | Postgres password | root |
| REDIS_HOST | **Used only to override application.properties when starting locally.** Host on which redis is running | localhost |
| REDIS_PORT | Port on which you'll find redis running | 6379 |
| REDIS_DATABASE | Name of the redis database | 0 |
| REDIS_PASSWORD | Redis password | root |
| MAIL_HOST | SMTP host | smtp.mailgun.org |
| MAIL_PORT | SMTP port | 587 |
| MAIL_USERNAME | SMTP username | username |
| MAIL_PASSWORD | SMTP password | password |
| JWT_SECRET | Secret used to sign jwt | secret |
| SPRING_SECURITY_PASSWORD | Password used for auto-generated users | qwerty123 |

14 changes: 6 additions & 8 deletions backend/spring-boot/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
FROM maven:3.9.6-amazoncorretto-21-debian AS build

RUN apt-get update; apt-get install -y curl \
&& curl -sL https://deb.nodesource.com/setup_20.x | bash - \
&& apt-get install -y nodejs \
&& curl -L https://www.npmjs.com/install.sh | sh

WORKDIR /app

COPY pom.xml .
COPY src ./src

RUN mvn clean install -DskipTests

FROM openjdk:21-jdk

FROM openjdk:21-jdk AS dev
WORKDIR /app

COPY --from=build /app/target/*.jar bootstrapbugz-api.jar

ENTRYPOINT ["java", "-Dspring.profiles.active=dev", "-jar", "bootstrapbugz-api.jar"]

FROM openjdk:21-jdk AS prod
WORKDIR /app
COPY --from=build /app/target/*.jar bootstrapbugz-api.jar
ENTRYPOINT ["java", "-Dspring.profiles.active=prod", "-jar", "bootstrapbugz-api.jar"]
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ services:
bootstrapbugz-api:
container_name: bootstrapbugz-api
image: bootstrapbugz-api:1.0.0
build: .
build:
target: ${PROFILE:-dev}
ports:
- "${SERVER_PORT:-8080}:${SERVER_PORT:-8080}"
- "${API_PORT:-8080}:${API_PORT:-8080}"
environment:
APP_NAME: ${APP_NAME:-BootstrapBugZ}
SERVER_PORT: ${SERVER_PORT:-8080}
UI_URL: ${UI_URL:-http://localhost:5173}
API_PORT: ${API_PORT:-8080}
UI_URL: ${HTTP_PROTOCOL:-http}://${UI_HOST:-localhost}:${UI_PORT:-5173}
SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:${POSTGRES_PORT:-5432}/${POSTGRES_DATABASE:-bootstrapbugz}
SPRING_DATASOURCE_USERNAME: ${POSTGRES_USERNAME:-postgres}
SPRING_DATASOURCE_PASSWORD: ${POSTGRES_PASSWORD:-root}
Expand All @@ -31,7 +32,7 @@ services:
"CMD",
"curl",
"-f",
"${HTTP_PROTOCOL:-http}://localhost:${SERVER_PORT:-8080}/actuator/health",
"${HTTP_PROTOCOL:-http}://localhost:${API_PORT:-8080}/actuator/health",
]
start_period: 10s
interval: 30s
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

@Profile({"dev", "test"})
@Profile({"dev", "prod", "test"})
@Component
public class DataInit implements ApplicationRunner {
private final UserRepository userRepository;
Expand Down
4 changes: 2 additions & 2 deletions backend/spring-boot/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# app
app.name=${APP_NAME:BootstrapBugZ}
server.port=${SERVER_PORT:8080}
server.port=${API_PORT:8080}
ui.url=${UI_URL:http://localhost:5173}
# database
spring.sql.init.platform=postgres
Expand All @@ -17,7 +17,7 @@ spring.data.web.pageable.default-page-size=10
#logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
# redis
spring.data.redis.database=${REDIS_DATABASE:0}
spring.data.redis.host=${REDIS_HOST:127.0.0.1}
spring.data.redis.host=${REDIS_HOST:localhost}
spring.data.redis.port=${REDIS_PORT:6379}
spring.data.redis.password=${REDIS_PASSWORD:root}
spring.data.redis.timeout=60
Expand Down
19 changes: 12 additions & 7 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ services:
build:
context: ./backend/spring-boot
dockerfile: Dockerfile
target: ${PROFILE:-prod}
ports:
- "${SERVER_PORT:-8080}:${SERVER_PORT:-8080}"
- "${API_PORT:-8080}:${API_PORT:-8080}"
environment:
APP_NAME: ${APP_NAME:-BootstrapBugZ}
SERVER_PORT: ${SERVER_PORT:-8080}
UI_URL: ${UI_URL:-http://bootstrapbugz-ui:5173}
API_PORT: ${API_PORT:-8080}
UI_URL: ${HTTP_PROTOCOL:-http}://${UI_HOST:-localhost}:${UI_PORT:-5173}
SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:${POSTGRES_PORT:-5432}/${POSTGRES_DATABASE:-bootstrapbugz}
SPRING_DATASOURCE_USERNAME: ${POSTGRES_USERNAME:-postgres}
SPRING_DATASOURCE_PASSWORD: ${POSTGRES_PASSWORD:-root}
Expand All @@ -33,7 +34,7 @@ services:
"CMD",
"curl",
"-f",
"${HTTP_PROTOCOL:-http}://localhost:${SERVER_PORT:-8080}/actuator/health",
"${HTTP_PROTOCOL:-http}://localhost:${API_PORT:-8080}/actuator/health",
]
start_period: 10s
interval: 30s
Expand Down Expand Up @@ -95,10 +96,14 @@ services:
build:
context: ./frontend/svelte-kit
dockerfile: Dockerfile
args:
PUBLIC_APP_NAME: ${APP_NAME:-BootstrapBugZ}
PUBLIC_API_URL: ${HTTP_PROTOCOL:-http}://bootstrapbugz-api:${API_PORT:-8080}/v1
JWT_SECRET: ${JWT_SECRET:-secret}
target: ${PROFILE:-prod}
environment:
PUBLIC_APP_NAME: ${APP_NAME:-BootstrapBugZ}
PUBLIC_API_URL: ${API_URL:-http://bootstrapbugz-api:8080/v1}
JWT_SECRET: ${JWT_SECRET:-secret}
PORT: ${UI_PORT:-5173}
ORIGIN: ${HTTP_PROTOCOL:-http}://${UI_HOST:-localhost}:${UI_PORT:-5173}
ports:
- "${UI_PORT:-5173}:${UI_PORT:-5173}"
depends_on:
Expand Down
28 changes: 20 additions & 8 deletions frontend/svelte-kit/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
FROM node:20-alpine

RUN apk add --no-cache curl

FROM node:22-alpine AS base
WORKDIR /app

ARG PUBLIC_APP_NAME
ARG PUBLIC_API_URL
ARG JWT_SECRET
COPY package.json .
COPY pnpm-lock.yaml .

RUN npm install -g pnpm
RUN pnpm install

COPY . .

FROM base AS dev
RUN apk add --no-cache curl
CMD ["pnpm", "run", "dev", "--host"]

FROM base AS build
RUN pnpm run build
RUN pnpm prune --prod

CMD ["pnpm", "run", "dev", "--host"]
FROM node:22-alpine AS prod
RUN apk add --no-cache curl
WORKDIR /app
# copy node_modules only if you have dependencies in package.json
# if you only have devDependencies you can skip this line
# COPY --from=build /app/node_modules node_modules/
COPY --from=build /app/build build/
COPY --from=build /app/package.json .
ENV NODE_ENV=production
CMD ["node", "build"]
1 change: 1 addition & 0 deletions frontend/svelte-kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@inlang/paraglide-sveltekit": "0.15.0",
"@playwright/test": "1.49.1",
"@sveltejs/adapter-auto": "3.3.1",
"@sveltejs/adapter-node": "5.2.11",
"@sveltejs/kit": "2.13.0",
"@sveltejs/vite-plugin-svelte": "5.0.3",
"@types/eslint": "9.6.1",
Expand Down
Loading

0 comments on commit 020af7f

Please sign in to comment.