diff --git a/Dockerfile.backend b/Dockerfile.backend new file mode 100644 index 0000000..4a29885 --- /dev/null +++ b/Dockerfile.backend @@ -0,0 +1,10 @@ +FROM gradle:9.3.1-jdk21-alpine AS build +WORKDIR /app +COPY build.gradle.kts settings.gradle.kts gradle.properties ./ +COPY src src +RUN echo "org.gradle.jvmargs=-Xmx1g" >> gradle.properties && gradle bootJar --no-daemon + +FROM eclipse-temurin:21-jre +WORKDIR /app +COPY --from=build /app/build/libs/*.jar app.jar +ENTRYPOINT ["java", "-jar", "app.jar"] diff --git a/Dockerfile.frontend b/Dockerfile.frontend new file mode 100644 index 0000000..f1c527c --- /dev/null +++ b/Dockerfile.frontend @@ -0,0 +1,11 @@ +FROM node:22-alpine AS build +WORKDIR /app +COPY frontend/package*.json ./ +RUN npm ci +COPY frontend . +RUN npm run build + +FROM nginx:alpine +COPY --from=build /app/dist /usr/share/nginx/html +COPY nginx.conf /etc/nginx/conf.d/default.conf +EXPOSE 3000 diff --git a/README.md b/README.md index df28f52..5c2f812 100644 --- a/README.md +++ b/README.md @@ -46,24 +46,15 @@ Key patterns: ## Prerequisites -- Java 21 -- Docker +- Docker (at least 4 GB memory allocated to the Docker VM) ## Getting Started -Start the database: - -```sh -docker compose up -d -``` - -Run the application: - ```sh -./gradlew bootRun +docker compose up --build ``` -The API is available at `http://localhost:8080`. Swagger UI is at `http://localhost:8080/docs/swagger-ui.html`. +The frontend is available at `http://localhost:3000`. The API is available at `http://localhost:8080`. Swagger UI is at `http://localhost:8080/docs/swagger-ui.html`. ## Running Tests diff --git a/docker-compose.yml b/docker-compose.yml index 796b163..e663094 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,5 +13,26 @@ services: timeout: 10s volumes: - ./tmp/postgresql:/var/lib/postgresql/data + + backend: + build: + context: . + dockerfile: Dockerfile.backend + environment: + SPRING_DATASOURCE_URL: jdbc:postgresql://database:5432/interview + SPRING_DATASOURCE_USERNAME: postgres + SPRING_DATASOURCE_PASSWORD: postgres + ports: + - "8080:8080" + depends_on: + database: + condition: service_healthy + + frontend: + build: + context: . + dockerfile: Dockerfile.frontend ports: - - "5432:5432" + - "3000:3000" + depends_on: + - backend diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..a5d42a8 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,16 @@ +server { + listen 3000; + + root /usr/share/nginx/html; + index index.html; + + location /api { + proxy_pass http://backend:8080; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + } + + location / { + try_files $uri $uri/ /index.html; + } +}