From 093592179d8765757f7970dc15bd15eb652d4281 Mon Sep 17 00:00:00 2001 From: "aditya.chandel" <> Date: Tue, 11 Mar 2025 18:17:23 -0600 Subject: [PATCH] Prepare for open source and stopped tracking application-local.yaml --- .env | 12 +++++ .gitignore | 3 ++ booklore-api/build.gradle | 28 ++++++------ .../config/security/SecurityConfig.java | 2 +- .../src/main/resources/application-local.yaml | 45 ------------------- .../src/main/resources/application.yaml | 9 ++-- .../src/app/core/service/auth.service.ts | 8 ++-- build-docker.sh | 34 -------------- docker-compose.yml | 23 +++++++--- 9 files changed, 57 insertions(+), 107 deletions(-) create mode 100644 .env delete mode 100644 booklore-api/src/main/resources/application-local.yaml delete mode 100644 build-docker.sh diff --git a/.env b/.env new file mode 100644 index 000000000..d51597d12 --- /dev/null +++ b/.env @@ -0,0 +1,12 @@ +# User and timezone settings +PUID=1000 +PGID=1000 +TZ=Etc/UTC + +# Database credentials (Replace with a secure password) +MYSQL_ROOT_PASSWORD=your_secure_password + +# Paths for Docker volumes (Update these paths as per your system) +BOOKLORE_DATA_PATH=/path/to/booklore/data # Example: /home/user/booklore/data +BOOKLORE_BOOKS_PATH=/path/to/booklore/books # Example: /home/user/booklore/books +MARIADB_CONFIG_PATH=/path/to/mariadb/config # Example: /home/user/booklore/mariadb/config \ No newline at end of file diff --git a/.gitignore b/.gitignore index c2065bc26..de39c22a2 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,6 @@ out/ ### VS Code ### .vscode/ +local/ + +src/main/resources/application-local.yaml diff --git a/booklore-api/build.gradle b/booklore-api/build.gradle index 37f2f1ee5..ed8e36e13 100644 --- a/booklore-api/build.gradle +++ b/booklore-api/build.gradle @@ -25,7 +25,7 @@ configurations { } dependencies { - // Spring Boot + // --- Spring Boot --- implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-validation' @@ -35,34 +35,36 @@ dependencies { implementation 'org.springframework.boot:spring-boot-configuration-processor' implementation 'org.springframework.boot:spring-boot-starter-security' - // Lombok + // --- Database & Migration --- + implementation 'org.mariadb.jdbc:mariadb-java-client:3.5.2' + implementation 'org.flywaydb:flyway-mysql:11.3.4' + + // --- Security & Authentication --- + implementation 'io.jsonwebtoken:jjwt-api:0.12.6' + runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.12.6' + runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.12.6' + + // --- Lombok (For Clean Code) --- compileOnly 'org.projectlombok:lombok:1.18.36' annotationProcessor 'org.projectlombok:lombok:1.18.36' - // Database & Flyway - implementation 'com.h2database:h2:2.3.232' - implementation 'org.flywaydb:flyway-mysql:11.3.4' - - // Book and Image Libraries + // --- Book & Image Processing --- implementation 'org.apache.pdfbox:pdfbox:3.0.4' implementation 'org.apache.pdfbox:jbig2-imageio:3.0.4' implementation 'com.github.jai-imageio:jai-imageio-core:1.4.0' implementation 'com.github.jai-imageio:jai-imageio-jpeg2000:1.4.0' implementation 'io.documentnode:epub4j-core:4.2.2' - // JSON & Web + // --- JSON & Web Scraping --- implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.18.3' implementation 'org.jsoup:jsoup:1.19.1' - // MapStruct + // --- Mapping (DTOs & Entities) --- implementation 'org.mapstruct:mapstruct:1.6.3' annotationProcessor 'org.mapstruct:mapstruct-processor:1.6.3' + // --- API Documentation --- implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.5' - - implementation 'io.jsonwebtoken:jjwt-api:0.12.6' - runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.12.6' - runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.12.6' } hibernate { diff --git a/booklore-api/src/main/java/com/adityachandel/booklore/config/security/SecurityConfig.java b/booklore-api/src/main/java/com/adityachandel/booklore/config/security/SecurityConfig.java index b850a737f..58cd72815 100644 --- a/booklore-api/src/main/java/com/adityachandel/booklore/config/security/SecurityConfig.java +++ b/booklore-api/src/main/java/com/adityachandel/booklore/config/security/SecurityConfig.java @@ -55,7 +55,7 @@ public class SecurityConfig { @Bean public CorsConfigurationSource corsConfigurationSource() { CorsConfiguration configuration = new CorsConfiguration(); - configuration.setAllowedOrigins(List.of("http://localhost:4200")); + configuration.setAllowedOrigins(List.of("http://localhost:4200", "http://localhost:5050")); configuration.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "OPTIONS")); configuration.setAllowedHeaders(List.of("Authorization", "Cache-Control", "Content-Type")); configuration.setExposedHeaders(List.of("Content-Disposition")); diff --git a/booklore-api/src/main/resources/application-local.yaml b/booklore-api/src/main/resources/application-local.yaml deleted file mode 100644 index db3a97c24..000000000 --- a/booklore-api/src/main/resources/application-local.yaml +++ /dev/null @@ -1,45 +0,0 @@ - - -app: - path-book: '/Users/aditya.chandel/my-library-temp/books' - path-config: '/Users/aditya.chandel/my-library-temp/config/local' - -spring: - servlet: - multipart: - enabled: true - max-file-size: 100MB - max-request-size: 100MB - mvc: - async: - request-timeout: 600000 - application: - name: booklore-api - datasource: - driver-class-name: org.h2.Driver - url: 'jdbc:h2:tcp://localhost:8040/~/my-library-temp/config/local/db/booklore' - username: sa - password: password - jpa: - hibernate: - naming: - physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl - show-sql: false - properties: - hibernate: - jdbc: - batch_size: 500 - order_inserts: true - order_updates: true - flyway: - enabled: true - locations: classpath:db/migration - -logging: - level: - root: INFO - org.apache.fontbox: ERROR - org.apache.pdfbox: ERROR - -server: - port: 7050 \ No newline at end of file diff --git a/booklore-api/src/main/resources/application.yaml b/booklore-api/src/main/resources/application.yaml index af9ef25a4..b5ff53330 100644 --- a/booklore-api/src/main/resources/application.yaml +++ b/booklore-api/src/main/resources/application.yaml @@ -14,11 +14,12 @@ spring: application: name: booklore-api datasource: - driver-class-name: org.h2.Driver - url: 'jdbc:h2:/app/config/db/booklore' - username: sa - password: password + driver-class-name: org.mariadb.jdbc.Driver + url: jdbc:mariadb://mariadb:3306/booklore?createDatabaseIfNotExist=true + username: root + password: ${MYSQL_ROOT_PASSWORD} jpa: + database-platform: org.hibernate.dialect.MariaDBDialect hibernate: naming: physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl diff --git a/booklore-ui/src/app/core/service/auth.service.ts b/booklore-ui/src/app/core/service/auth.service.ts index 6f9a5e6d1..318ba7d86 100644 --- a/booklore-ui/src/app/core/service/auth.service.ts +++ b/booklore-ui/src/app/core/service/auth.service.ts @@ -2,12 +2,14 @@ import {inject, Injectable, Injector} from '@angular/core'; import {HttpClient} from '@angular/common/http'; import {Observable, tap} from 'rxjs'; import {RxStompService} from '../../shared/websocket/rx-stomp.service'; +import {API_CONFIG} from '../../config/api-config'; @Injectable({ providedIn: 'root', }) export class AuthService { - private apiUrl = 'http://localhost:7050/api/v1/auth'; + + private apiUrl = `${API_CONFIG.BASE_URL}/api/v1/auth`; private rxStompService?: RxStompService; private http = inject(HttpClient); @@ -40,10 +42,6 @@ export class AuthService { localStorage.setItem('refreshToken', refreshToken); } - saveToken(token: string): void { - localStorage.setItem('accessToken', token); - } - getToken(): string | null { return localStorage.getItem('accessToken'); } diff --git a/build-docker.sh b/build-docker.sh deleted file mode 100644 index fb05792b2..000000000 --- a/build-docker.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/bash - -# Define variables -PROJECT_ROOT=$(pwd) -UI_DIR="$PROJECT_ROOT/booklore-ui" -API_DIR="$PROJECT_ROOT/booklore-api" -H2_JAR="$PROJECT_ROOT/h2-2.3.232.jar" -DOCKER_IMAGE_NAME="booklore-app" - -# Step 1: Build Angular frontend -echo "Building Angular frontend..." -cd "$UI_DIR" || exit -npm install -npm run build --prod || { echo "Angular build failed"; exit 1; } -echo "Angular build completed." - -# Step 2: Package Spring Boot API -echo "Packaging Spring Boot API..." -cd "$API_DIR" || exit -mvn clean package -DskipTests || { echo "Spring Boot build failed"; exit 1; } -API_JAR=$(find target -name "*.jar" | head -n 1) -echo "Spring Boot API packaged: $API_JAR" - -# Step 3: Build Docker image -cd "$PROJECT_ROOT" || exit -echo "Building Docker image..." -docker build -t "$DOCKER_IMAGE_NAME" . || { echo "Docker build failed"; exit 1; } -echo "Docker image built: $DOCKER_IMAGE_NAME" - -# Step 4: Clean up (optional) -echo "Cleaning up intermediate files..." -rm -rf "$UI_DIR/node_modules" - -echo "Build process completed successfully!" \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 95b4a6851..7ce9c4eca 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,10 +1,23 @@ version: '3.8' services: - booklore-app: + booklore: + image: localhost:5000/booklore-app:latest container_name: booklore - image: localhost:5000/booklore-app:v8 + env_file: + - .env + depends_on: + - mariadb ports: - - "5050:6060" + - "6060:6060" volumes: - - /Users/aditya.chandel/my-library-temp/config/docker:/app/config - - /Users/aditya.chandel/my-library-temp/books:/app/books \ No newline at end of file + - ${BOOKLORE_DATA_PATH}:/app/data + - ${BOOKLORE_BOOKS_PATH}:/books + + mariadb: + image: lscr.io/linuxserver/mariadb:11.4.5 + container_name: mariadb + env_file: + - .env + volumes: + - ${MARIADB_CONFIG_PATH}:/config + restart: unless-stopped \ No newline at end of file