Refactor Docker setup and update file storage paths for improved containerization

This commit is contained in:
liosha84
2025-08-06 20:26:24 +03:00
parent ee3476d768
commit b5bfb677d9
9 changed files with 38 additions and 12 deletions
@@ -7,6 +7,7 @@
FROM openjdk:24 FROM openjdk:24
WORKDIR /jambotron/ WORKDIR /jambotron/
VOLUME /jambotron_data/uploads
COPY './build/libs/jambotron-0.0.1-SNAPSHOT.jar' '/app/jambotron.jar' COPY './build/libs/jambotron-0.0.1-SNAPSHOT.jar' '/app/jambotron.jar'
#COPY --from=BUILD_IMAGE /jambotron/build/libs/jambotron-0.0.1-SNAPSHOT.jar . #COPY --from=BUILD_IMAGE /jambotron/build/libs/jambotron-0.0.1-SNAPSHOT.jar .
#EXPOSE 8080 #EXPOSE 8080
@@ -4,7 +4,7 @@ services:
container_name: 'jambotron-container' container_name: 'jambotron-container'
build: build:
context: ../../ context: ../../
dockerfile: ./src/Docker/Dockerfile dockerfile: /Dockerfile
ports: ports:
# - "8081:80" # - "8081:80"
- "8443:443" - "8443:443"
@@ -12,6 +12,7 @@ services:
- postgres_jambotron - postgres_jambotron
volumes: volumes:
- certs:/certs - certs:/certs
- jambotron_data:/jambotron_data
# env_file: "webapp.env" # env_file: "webapp.env"
environment: environment:
SSL_ENABLED: "true" SSL_ENABLED: "true"
@@ -63,4 +64,6 @@ services:
# file: db_password.txt # file: db_password.txt
volumes: volumes:
certs: certs:
external: true external: true
jambotron_data:
# external: true
+5
View File
@@ -0,0 +1,5 @@
// investigate docker-compose.yml files for details on how to run the application
@echo off
//docker compose -f docker-compose.yml down
//docker compose -f docker-compose.yml build
//docker compose -f docker-compose.yml up -d
+9
View File
@@ -0,0 +1,9 @@
#additional investigation needed to run this script
##!/bin/bash
#
## stop any previously running containers
#docker compose --env-file .env -f DevOps/docker-compose.yml down
## build the images
#docker compose --env-file .env -f DevOps/docker-compose.yml build
## start the containers
#docker compose --env-file .env -f DevOps/docker-compose.yml up -d
@@ -23,6 +23,7 @@ public class JambotronApplication implements CommandLineRunner {
logger.error("Application Run. This is an error message."); logger.error("Application Run. This is an error message.");
logger.debug("Application Run. This is a debug message."); logger.debug("Application Run. This is a debug message.");
logger.info("Application Run. This is an info message."); logger.info("Application Run. This is an info message.");
logger.info("Application Run. This is an info message.!!!!!!");
} }
@Override @Override
public void run(String... arg) throws Exception { public void run(String... arg) throws Exception {
@@ -178,17 +178,19 @@ public class TutorialController {
try { try {
String imageFileName = FilesStorageServiceImpl.getFileNameFromUrl(tutorial.getTitleimage()); String imageFileName = FilesStorageServiceImpl.getFileNameFromUrl(tutorial.getTitleimage());
String servImageFileName = FilesStorageServiceImpl.getFileNameFromUrl(servTutorial.getTitleimage()); String servImageFileName = FilesStorageServiceImpl.getFileNameFromUrl(servTutorial.getTitleimage());
filesStorageService.deletePublicFile(servImageFileName);
if(!servImageFileName.equals(imageFileName)){
filesStorageService.deletePublicFile(servImageFileName);
Path path= filesStorageService.moveFile( Path path= filesStorageService.moveFile(
user.getId().toString(), user.getId().toString(),
tutorial.getTitleimage(), tutorial.getTitleimage(),
String.format("Tutorial_%s",imageFileName ) String.format("Tutorial_%s",imageFileName )
); );
servTutorial.setTitleimage(FilesRoutingHelper.getPublicImageUrl(path.getFileName().toString())); servTutorial.setTitleimage(FilesRoutingHelper.getPublicImageUrl(path.getFileName().toString()));
}
servTutorial = tutorialRepository.save(servTutorial); servTutorial = tutorialRepository.save(servTutorial);
} catch (Exception e) { } catch (Exception e) {
@@ -19,9 +19,14 @@ import java.util.stream.Stream;
@Service @Service
public class FilesStorageServiceImpl implements FilesStorageService { public class FilesStorageServiceImpl implements FilesStorageService {
private final Path root = Paths.get("uploads/user-images/"); // private final Path root = Paths.get("uploads/user-images/");
//
// private final Path rootPublic = Paths.get("uploads/public-images/");
// Update paths to use the Docker volume
private final Path root = Paths.get("/jambotron_data/uploads/user-images/");
private final Path rootPublic = Paths.get("/jambotron_data/uploads/public-images/");
private final Path rootPublic = Paths.get("uploads/public-images/");
@Override @Override
public void init() { public void init() {