diff --git a/Dockerfile b/Dockerfile index 239eb59..e0bdd82 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,20 @@ -FROM eclipse-temurin:21-jdk-alpine +FROM eclipse-temurin:25-jdk-alpine AS build +RUN apk add --no-cache maven +WORKDIR /app + +# Copy pom.xml and download dependencies (for caching) +COPY pom.xml . +RUN mvn dependency:go-offline + +# Copy source and templates +COPY src ./src + +# Build and run tests with overridden properties +ARG PUZZLE_ROWS=8 +ARG PUZZLE_COLS=9 +RUN mvn clean test package -DPUZZLE_ROWS=${PUZZLE_ROWS} -DPUZZLE_COLS=${PUZZLE_COLS} + +FROM eclipse-temurin:25-jdk-alpine RUN apk add --no-cache curl tzdata @@ -9,19 +25,12 @@ RUN curl -fsSL -o /usr/local/bin/supercronic \ WORKDIR /app -# Copy source files -COPY src/ /app/src/ -COPY export_real_words_with_hints.csv /app/export_real_words_with_hints.csv -COPY compile.sh /app/compile.sh +# Copy the built jar and other necessary files from the build stage +COPY --from=build /app/target/tools-all.jar /app/target/tools-all.jar +COPY nl_score_hints.csv /app/nl_score_hints.csv COPY docker-entrypoint.sh /app/docker-entrypoint.sh COPY crontab /app/crontab -# Compile Java code -RUN chmod +x /app/compile.sh && \ - mkdir -p /app/target && \ - cp src/puzzle/postgresql-42.7.8.jar /app/target/ && \ - javac -cp /app/target/postgresql-42.7.8.jar -d /app/target src/puzzle/*.java - # Create output directory RUN mkdir -p /data/puzzles diff --git a/compile.sh b/compile.sh index fa24d40..5c3c9bc 100755 --- a/compile.sh +++ b/compile.sh @@ -1,4 +1,31 @@ #!/bin/bash TARGET=${1:-~/dev/.target} mkdir -p "$TARGET" -javac -cp src/puzzle/postgresql-42.7.8.jar -d "$TARGET" src/puzzle/*.java +# Inject constants +ENV_FILE=${ENV_FILE:-.env} +GEN_DIR="src/main/generated-sources" +if [ -f "$ENV_FILE" ]; then + echo "Injecting constants from $ENV_FILE..." + # Create Config.java from template + mkdir -p "$GEN_DIR/puzzle" + sed "s/\${CLUE_SIZE}/$(grep '^CLUE_SIZE=' "$ENV_FILE" | cut -d= -f2)/g; + s/\${MIN_LEN}/$(grep '^MIN_LEN=' "$ENV_FILE" | cut -d= -f2)/g; + s/\${MAX_TRIES_PER_SLOT}/$(grep '^MAX_TRIES_PER_SLOT=' "$ENV_FILE" | cut -d= -f2)/g; + s/\${MAX_LEN}/$(grep '^MAX_LEN=' "$ENV_FILE" | cut -d= -f2)/g; + s/\${PUZZLE_ROWS}/$(grep '^PUZZLE_ROWS=' "$ENV_FILE" | cut -d= -f2)/g; + s/\${PUZZLE_COLS}/$(grep '^PUZZLE_COLS=' "$ENV_FILE" | cut -d= -f2)/g" \ + src/main/java-templates/puzzle/Config.java > "$GEN_DIR/puzzle/Config.java" +elif [ -f pom.xml ]; then + echo "Injecting constants from pom.xml..." + # Create Config.java from template + mkdir -p "$GEN_DIR/puzzle" + sed "s/\${CLUE_SIZE}/$(grep '' pom.xml | sed 's/.*>\(.*\)<.*/\1/')/g; + s/\${MIN_LEN}/$(grep '' pom.xml | sed 's/.*>\(.*\)<.*/\1/')/g; + s/\${MAX_TRIES_PER_SLOT}/$(grep '' pom.xml | sed 's/.*>\(.*\)<.*/\1/')/g; + s/\${MAX_LEN}/$(grep '' pom.xml | sed 's/.*>\(.*\)<.*/\1/')/g; + s/\${PUZZLE_ROWS}/$(grep '' pom.xml | sed 's/.*>\(.*\)<.*/\1/')/g; + s/\${PUZZLE_COLS}/$(grep '' pom.xml | sed 's/.*>\(.*\)<.*/\1/')/g" \ + src/main/java-templates/puzzle/Config.java > "$GEN_DIR/puzzle/Config.java" +fi + +javac -cp src/main/java/puzzle/postgresql-42.7.8.jar:$(find . -name "lombok-*.jar") -d "$TARGET" src/main/java/puzzle/*.java "$GEN_DIR/puzzle/Config.java" diff --git a/docker-compose.yml b/docker-compose.yml index 6e1edc0..921d157 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -59,6 +59,21 @@ services: volumes: - puzzles_data:/data/puzzle:rw + puzzle_test: + build: + context: ${PUZZLE_ROOT_DIR:-/opt/apps/puzzle} + dockerfile: Dockerfile + args: + PUZZLE_ROWS: 3 + PUZZLE_COLS: 3 + container_name: puzzle_test + profiles: ["test"] + environment: + GENERATE_ON_START: "true" + START_CLASS: "puzzle.MainTest" + volumes: + - puzzles_data:/data/puzzle:rw + volumes: puzzles_data: diff --git a/pom.xml b/pom.xml index b8862b2..f0199d7 100644 --- a/pom.xml +++ b/pom.xml @@ -9,6 +9,14 @@ 25 25 + UTF-8 + + 4 + 2 + 2000 + 8 + 8 + 9 @@ -57,9 +65,26 @@ + + org.codehaus.mojo + templating-maven-plugin + 3.0.0 + + + filter-src + + filter-sources + + + + + org.apache.maven.plugins maven-compiler-plugin + 3.13.0 @@ -68,6 +93,8 @@ 1.18.42 + 25 + 25