diff --git a/backend/.dockerignore b/backend/.dockerignore new file mode 100644 index 00000000..82cb2fc6 --- /dev/null +++ b/backend/.dockerignore @@ -0,0 +1,4 @@ +target +.git +.idea +*.iml diff --git a/backend/Dockerfile b/backend/Dockerfile index 05a8b156..30937697 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -1,3 +1,15 @@ +# ---------- Build stage ---------- +FROM maven:3.9-eclipse-temurin-25 AS builder + +WORKDIR /app + +COPY pom.xml . +RUN mvn dependency:go-offline + +COPY src ./src +RUN mvn clean package -DskipTests + +# ---------- Runtime stage ---------- FROM eclipse-temurin:25.0.2_10-jre ARG APP_VERSION="" @@ -8,7 +20,7 @@ WORKDIR /app RUN groupadd -r appuser && useradd -r -g appuser appuser -COPY target/*.jar app.jar +COPY --from=builder /app/target/*.jar app.jar RUN chown -R appuser:appuser /app diff --git a/backend/src/main/java/org/rdfarchitect/config/WebConfig.java b/backend/src/main/java/org/rdfarchitect/config/WebConfig.java index 68a4eab2..455a2dce 100644 --- a/backend/src/main/java/org/rdfarchitect/config/WebConfig.java +++ b/backend/src/main/java/org/rdfarchitect/config/WebConfig.java @@ -29,10 +29,16 @@ @Configuration public class WebConfig implements WebMvcConfigurer { + private final FrontendConfig frontendConfig; + + public WebConfig(FrontendConfig frontendConfig) { + this.frontendConfig = frontendConfig; + } + @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/api/**") - .allowedOrigins("http://localhost:1407") + .allowedOrigins(frontendConfig.getUrl()) .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH", "HEAD") .allowedHeaders("*") .allowCredentials(true) diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml index 18e88b4c..511242e6 100644 --- a/docker/docker-compose.yaml +++ b/docker/docker-compose.yaml @@ -1,17 +1,19 @@ services: backend: build: - context: ./backend + context: ../backend environment: DATABASE_DATABASETYPE: http DATABASE_DEFAULTDATASET: default DATABASE_HTTP_ENDPOINT: http://host.docker.internal:3030 + FRONTEND_URL: http://localhost:3000 + FRONTEND_ACCESS_ROUTE: /api expose: - "8080" frontend: build: - context: ./frontend + context: ../frontend environment: PUBLIC_BACKEND_URL: "/api" expose: @@ -28,4 +30,4 @@ services: - ./nginx.local.conf:/etc/nginx/conf.d/default.conf:ro volumes: - fuseki-data: \ No newline at end of file + fuseki-data: diff --git a/frontend/.dockerignore b/frontend/.dockerignore new file mode 100644 index 00000000..9ca390d2 --- /dev/null +++ b/frontend/.dockerignore @@ -0,0 +1,4 @@ +node_modules +build +dist +.git diff --git a/frontend/Dockerfile b/frontend/Dockerfile index cee5eb0f..7d7d2ac8 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -1,3 +1,20 @@ +# ---------- Build stage ---------- +FROM node:22-alpine AS builder + +WORKDIR /app + +# Copy package files first for better layer caching +COPY package*.json ./ + +RUN npm ci + +# Copy source code +COPY . . + +# Build frontend +RUN npm run build + +# ---------- Runtime stage ---------- FROM nginx:alpine3.22 ARG PUBLIC_APP_VERSION="" @@ -10,7 +27,7 @@ ENV PUBLIC_APP_VERSION="${PUBLIC_APP_VERSION}" \ #RUN addgroup -S appgroup && adduser -S appuser -G appgroup -COPY build /usr/share/nginx/html +COPY --from=builder /app/build /usr/share/nginx/html COPY nginx.conf /etc/nginx/conf.d/default.conf COPY docker-entrypoint.sh /docker-entrypoint.sh