Compare commits

3 Commits

Author SHA1 Message Date
867edab39c Optimize dockerfile and add docker compose 2025-07-12 18:13:09 +05:00
39ee53e262 Add kodik token to application.properties 2025-07-12 18:12:46 +05:00
32b16ddf31 Add logging to controllers 2025-07-12 18:12:25 +05:00
6 changed files with 50 additions and 13 deletions

View File

@ -1,19 +1,29 @@
# Build
FROM maven:3.9.6-eclipse-temurin-21 AS builder
WORKDIR /workspace
COPY pom.xml .
RUN mvn dependency:go-offline -B
COPY src ./src
RUN mvn clean package -DskipTests
# Create optimized runtime
FROM eclipse-temurin:21 AS app-build
ENV RELEASE=21
WORKDIR /opt/build
COPY ./target/*.jar ./application.jar
COPY --from=builder /workspace/target/*.jar ./application.jar
RUN java -Djarmode=layertools -jar application.jar extract
RUN $JAVA_HOME/bin/jlink \
--add-modules `jdeps --ignore-missing-deps -q -recursive --multi-release ${RELEASE} --print-module-deps -cp 'dependencies/BOOT-INF/lib/*' application.jar` \
--add-modules $(jdeps --ignore-missing-deps -q -recursive --multi-release ${RELEASE} --print-module-deps -cp 'dependencies/BOOT-INF/lib/*' application.jar),jdk.crypto.ec,jdk.security.auth,jdk.crypto.cryptoki \
--strip-debug \
--no-man-pages \
--no-header-files \
--compress=2 \
--output jdk
FROM debian:buster-slim
# Run
FROM debian:bookworm-slim
ARG BUILD_PATH=/opt/build
ENV JAVA_HOME=/opt/jdk
@ -22,6 +32,10 @@ ENV PATH="${JAVA_HOME}/bin:${PATH}"
RUN groupadd --gid 1000 spring-app \
&& useradd --uid 1000 --gid spring-app --shell /bin/bash --create-home spring-app
RUN apt-get update && \
apt-get install -y --no-install-recommends ca-certificates && \
rm -rf /var/lib/apt/lists/*
USER spring-app:spring-app
WORKDIR /opt/workspace

11
compose.yml Normal file
View File

@ -0,0 +1,11 @@
services:
extractor:
image: anyame-extractor:latest
ports:
- 8081:8080
env_file: .env
networks:
- anyame
networks:
anyame:
driver: bridge

View File

@ -5,7 +5,7 @@ import org.springframework.stereotype.Component;
@Component
public class KodikAPITokenProvider {
@Value("${KODIK_TOKEN}")
@Value("${kodik.token}")
private String kodikToken;
public String getKodikToken() {

View File

@ -2,6 +2,8 @@ package com.backend.extractor.kodik.service.anyame_backend.controller;
import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@ -23,7 +25,7 @@ import com.backend.extractor.kodik.service.anyame_backend.service.KodikURLDecode
@RestController
@RequestMapping("/extract")
public class ExtractController {
Logger logger = LoggerFactory.getLogger(ExtractController.class);
private final KodikExtractService extractService;
private final KodikURLDecoderService decoderService;
@ -41,14 +43,18 @@ public class ExtractController {
links.decodeLinks(decoderService);
return links;
} catch (KodikExtractionException e) {
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "cannot retrieve metadat", e);
logger.error("cannot retrieve metadata", e);
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "cannot retrieve metadata", e);
} catch (IOException e) {
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "i/o error");
} catch (KodikPlayerNotFoundException e) {
logger.error("cannoot find player", e);
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "player not found");
} catch (KodikAPINotFoundException e) {
logger.error("api endpoint not found", e);
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "api endpoint not found");
} catch (KodikDecryptionException e) {
logger.error("cannot decrypt link", e);
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "cannot decode links");
}
}

View File

@ -2,6 +2,8 @@ package com.backend.extractor.kodik.service.anyame_backend.controller;
import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@ -21,6 +23,7 @@ import retrofit2.Response;
@RestController
@RequestMapping("/metadata")
public class MetadataController {
Logger logger = LoggerFactory.getLogger(MetadataController.class);
private final KodikPlayerAPI kodikPlayerAPI;
private final KodikAPITokenProvider tokenProvider;
private final KodikExtractService extractService;
@ -45,7 +48,8 @@ public class MetadataController {
String url = responseResult.getLink();
return extractService.getMetadata(url);
} catch (KodikExtractionException e) {
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "cannot retrieve metadat", e);
logger.error("cannot retrieve metadata", e);
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "cannot retrieve metadata", e);
} catch (IOException e) {
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "i/o error");
}
@ -63,6 +67,7 @@ public class MetadataController {
String url = responseResult.getLink();
return extractService.getMetadata(url);
} catch (KodikExtractionException e) {
logger.error("cannot retrieve metadata", e);
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "cannot retrieve metadata", e);
} catch (IOException e) {
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "i/o error");

View File

@ -1,2 +1,3 @@
spring.application.name=anyame-backend
server.error.include-message=always
kodik.token=${KODIK_TOKEN}