Number of fixes and making pipline LIVE ! (#907)

Closes #889 and #332
#710
#901
#885
This commit is contained in:
Anthony Stirling 2024-03-13 19:15:10 +00:00 committed by GitHub
parent ac620082ec
commit ae73595335
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 359 additions and 220 deletions

View file

@ -12,8 +12,7 @@ plugins {
import com.github.jk1.license.render.* import com.github.jk1.license.render.*
group = 'stirling.software' group = 'stirling.software'
version = '0.22.3'
version = '0.22.2'
sourceCompatibility = '17' sourceCompatibility = '17'
repositories { repositories {

View file

@ -1,5 +1,5 @@
apiVersion: v2 apiVersion: v2
appVersion: 0.20.2 appVersion: 0.22.3
description: locally hosted web application that allows you to perform various operations on PDF files description: locally hosted web application that allows you to perform various operations on PDF files
home: https://github.com/Stirling-Tools/Stirling-PDF home: https://github.com/Stirling-Tools/Stirling-PDF
keywords: keywords:

View file

@ -130,7 +130,7 @@ public class AutoRenameController {
// Sanitize the header string by removing characters not allowed in a filename. // Sanitize the header string by removing characters not allowed in a filename.
if (header != null && header.length() < 255) { if (header != null && header.length() < 255) {
header = header.replaceAll("[/\\\\?%*:|\"<>]", ""); header = header.replaceAll("[/\\\\?%*:|\"<>]", "").trim();
return WebResponseUtils.pdfDocToWebResponse(document, header + ".pdf"); return WebResponseUtils.pdfDocToWebResponse(document, header + ".pdf");
} else { } else {
logger.info("File has no good title to be found"); logger.info("File has no good title to be found");

View file

@ -58,7 +58,7 @@ public class AutoSplitPdfController {
PDDocument document = Loader.loadPDF(file.getBytes()); PDDocument document = Loader.loadPDF(file.getBytes());
PDFRenderer pdfRenderer = new PDFRenderer(document); PDFRenderer pdfRenderer = new PDFRenderer(document);
pdfRenderer.setSubsamplingAllowed(true);
List<PDDocument> splitDocuments = new ArrayList<>(); List<PDDocument> splitDocuments = new ArrayList<>();
List<ByteArrayOutputStream> splitDocumentsBoas = new ArrayList<>(); List<ByteArrayOutputStream> splitDocumentsBoas = new ArrayList<>();

View file

@ -59,7 +59,7 @@ public class BlankPageController {
List<Integer> pagesToKeepIndex = new ArrayList<>(); List<Integer> pagesToKeepIndex = new ArrayList<>();
int pageIndex = 0; int pageIndex = 0;
PDFRenderer pdfRenderer = new PDFRenderer(document); PDFRenderer pdfRenderer = new PDFRenderer(document);
pdfRenderer.setSubsamplingAllowed(true);
for (PDPage page : pages) { for (PDPage page : pages) {
logger.info("checking page " + pageIndex); logger.info("checking page " + pageIndex);
textStripper.setStartPage(pageIndex + 1); textStripper.setStartPage(pageIndex + 1);

View file

@ -2,9 +2,7 @@ package stirling.software.SPDF.controller.api.misc;
import java.awt.Image; import java.awt.Image;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
@ -75,8 +73,11 @@ public class CompressController {
long inputFileSize = Files.size(tempInputFile); long inputFileSize = Files.size(tempInputFile);
// Prepare the output file path // Prepare the output file path
Path tempOutputFile = Files.createTempFile("output_", ".pdf");
Path tempOutputFile = null;
byte[] pdfBytes;
try {
tempOutputFile = Files.createTempFile("output_", ".pdf");
// Determine initial optimization level based on expected size reduction, only if in // Determine initial optimization level based on expected size reduction, only if in
// autoMode // autoMode
if (autoMode) { if (autoMode) {
@ -134,11 +135,9 @@ public class CompressController {
} else { } else {
// Increase optimization level for next iteration // Increase optimization level for next iteration
optimizeLevel++; optimizeLevel++;
if (autoMode && optimizeLevel > 3) { if (autoMode && optimizeLevel > 4) {
System.out.println("Skipping level 4 due to bad results in auto mode"); System.out.println("Skipping level 5 due to bad results in auto mode");
sizeMet = true; sizeMet = true;
} else if (optimizeLevel == 5) {
} else { } else {
System.out.println( System.out.println(
"Increasing ghostscript optimisation level to " + optimizeLevel); "Increasing ghostscript optimisation level to " + optimizeLevel);
@ -148,25 +147,33 @@ public class CompressController {
if (expectedOutputSize != null && autoMode) { if (expectedOutputSize != null && autoMode) {
long outputFileSize = Files.size(tempOutputFile); long outputFileSize = Files.size(tempOutputFile);
byte[] fileBytes = Files.readAllBytes(tempOutputFile);
if (outputFileSize > expectedOutputSize) { if (outputFileSize > expectedOutputSize) {
try (PDDocument doc = Loader.loadPDF(new File(tempOutputFile.toString()))) { try (PDDocument doc = Loader.loadPDF(fileBytes)) {
long previousFileSize = 0; long previousFileSize = 0;
double scaleFactor = 1.0; double scaleFactorConst = 0.9f;
double scaleFactor = 0.9f;
while (true) { while (true) {
for (PDPage page : doc.getPages()) { for (PDPage page : doc.getPages()) {
PDResources res = page.getResources(); PDResources res = page.getResources();
if (res != null && res.getXObjectNames() != null) {
for (COSName name : res.getXObjectNames()) { for (COSName name : res.getXObjectNames()) {
PDXObject xobj = res.getXObject(name); PDXObject xobj = res.getXObject(name);
if (xobj instanceof PDImageXObject) { if (xobj != null && xobj instanceof PDImageXObject) {
PDImageXObject image = (PDImageXObject) xobj; PDImageXObject image = (PDImageXObject) xobj;
// Get the image in BufferedImage format // Get the image in BufferedImage format
BufferedImage bufferedImage = image.getImage(); BufferedImage bufferedImage = image.getImage();
// Calculate the new dimensions // Calculate the new dimensions
int newWidth = (int) (bufferedImage.getWidth() * scaleFactor); int newWidth =
int newHeight = (int) (bufferedImage.getHeight() * scaleFactor); (int)
(bufferedImage.getWidth()
* scaleFactorConst);
int newHeight =
(int)
(bufferedImage.getHeight()
* scaleFactorConst);
// If the new dimensions are zero, skip this iteration // If the new dimensions are zero, skip this iteration
if (newWidth == 0 || newHeight == 0) { if (newWidth == 0 || newHeight == 0) {
@ -176,7 +183,9 @@ public class CompressController {
// Otherwise, proceed with the scaling // Otherwise, proceed with the scaling
Image scaledImage = Image scaledImage =
bufferedImage.getScaledInstance( bufferedImage.getScaledInstance(
newWidth, newHeight, Image.SCALE_SMOOTH); newWidth,
newHeight,
Image.SCALE_SMOOTH);
// Convert the scaled image back to a BufferedImage // Convert the scaled image back to a BufferedImage
BufferedImage scaledBufferedImage = BufferedImage scaledBufferedImage =
@ -192,25 +201,26 @@ public class CompressController {
ByteArrayOutputStream compressedImageStream = ByteArrayOutputStream compressedImageStream =
new ByteArrayOutputStream(); new ByteArrayOutputStream();
ImageIO.write( ImageIO.write(
scaledBufferedImage, "jpeg", compressedImageStream); scaledBufferedImage,
"jpeg",
compressedImageStream);
byte[] imageBytes = compressedImageStream.toByteArray(); byte[] imageBytes = compressedImageStream.toByteArray();
compressedImageStream.close(); compressedImageStream.close();
// Convert compressed image back to PDImageXObject
ByteArrayInputStream bais =
new ByteArrayInputStream(imageBytes);
PDImageXObject compressedImage = PDImageXObject compressedImage =
PDImageXObject.createFromByteArray( PDImageXObject.createFromByteArray(
doc, doc,
imageBytes, imageBytes,
image.getCOSObject().toString()); image.getCOSObject().toString());
// Replace the image in the resources with the compressed // Replace the image in the resources with the
// compressed
// version // version
res.put(name, compressedImage); res.put(name, compressedImage);
} }
} }
} }
}
// save the document to tempOutputFile again // save the document to tempOutputFile again
doc.save(tempOutputFile.toString()); doc.save(tempOutputFile.toString());
@ -226,9 +236,10 @@ public class CompressController {
System.out.println("Current scale factor: " + scaleFactor); System.out.println("Current scale factor: " + scaleFactor);
// The file is still too large, reduce scaleFactor and try again // The file is still too large, reduce scaleFactor and try again
scaleFactor *= 0.9; // reduce scaleFactor by 10% scaleFactor *= 0.9f; // reduce scaleFactor by 10%
// Avoid scaleFactor being too small, causing the image to shrink to 0 // Avoid scaleFactor being too small, causing the image to shrink to
if (scaleFactor < 0.2 || previousFileSize == currentSize) { // 0
if (scaleFactor < 0.2f || previousFileSize == currentSize) {
throw new RuntimeException( throw new RuntimeException(
"Could not reach the desired size without excessively degrading image quality, lowest size recommended is " "Could not reach the desired size without excessively degrading image quality, lowest size recommended is "
+ FileUtils.byteCountToDisplaySize(currentSize) + FileUtils.byteCountToDisplaySize(currentSize)
@ -247,7 +258,7 @@ public class CompressController {
} }
// Read the optimized PDF file // Read the optimized PDF file
byte[] pdfBytes = Files.readAllBytes(tempOutputFile); pdfBytes = Files.readAllBytes(tempOutputFile);
// Check if optimized file is larger than the original // Check if optimized file is larger than the original
if (pdfBytes.length > inputFileSize) { if (pdfBytes.length > inputFileSize) {
@ -258,10 +269,11 @@ public class CompressController {
// Read the original file again // Read the original file again
pdfBytes = Files.readAllBytes(tempInputFile); pdfBytes = Files.readAllBytes(tempInputFile);
} }
} finally {
// Clean up the temporary files // Clean up the temporary files
Files.delete(tempInputFile); Files.delete(tempInputFile);
Files.delete(tempOutputFile); Files.delete(tempOutputFile);
}
// Return the optimized PDF as a response // Return the optimized PDF as a response
String outputFilename = String outputFilename =

View file

@ -84,6 +84,7 @@ public class ExtractImageScansController {
// Load PDF document // Load PDF document
try (PDDocument document = Loader.loadPDF(form.getFileInput().getBytes())) { try (PDDocument document = Loader.loadPDF(form.getFileInput().getBytes())) {
PDFRenderer pdfRenderer = new PDFRenderer(document); PDFRenderer pdfRenderer = new PDFRenderer(document);
pdfRenderer.setSubsamplingAllowed(true);
int pageCount = document.getNumberOfPages(); int pageCount = document.getNumberOfPages();
images = new ArrayList<>(); images = new ArrayList<>();

View file

@ -60,6 +60,7 @@ public class FakeScanControllerWIP {
PDDocument document = Loader.loadPDF(inputFile.getBytes()); PDDocument document = Loader.loadPDF(inputFile.getBytes());
PDFRenderer pdfRenderer = new PDFRenderer(document); PDFRenderer pdfRenderer = new PDFRenderer(document);
pdfRenderer.setSubsamplingAllowed(true);
for (int page = 0; page < document.getNumberOfPages(); ++page) { for (int page = 0; page < document.getNumberOfPages(); ++page) {
BufferedImage image = pdfRenderer.renderImageWithDPI(page, 300, ImageType.RGB); BufferedImage image = pdfRenderer.renderImageWithDPI(page, 300, ImageType.RGB);
ImageIO.write(image, "png", new File("scanned-" + (page + 1) + ".png")); ImageIO.write(image, "png", new File("scanned-" + (page + 1) + ".png"));

View file

@ -12,7 +12,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.ModelAttribute;
@ -50,9 +49,6 @@ public class PipelineController {
@PostMapping("/handleData") @PostMapping("/handleData")
public ResponseEntity<byte[]> handleData(@ModelAttribute HandleDataRequest request) public ResponseEntity<byte[]> handleData(@ModelAttribute HandleDataRequest request)
throws JsonMappingException, JsonProcessingException { throws JsonMappingException, JsonProcessingException {
if (!Boolean.TRUE.equals(applicationProperties.getSystem().getEnableAlphaFunctionality())) {
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
MultipartFile[] files = request.getFileInput(); MultipartFile[] files = request.getFileInput();
String jsonString = request.getJson(); String jsonString = request.getJson();

View file

@ -83,6 +83,7 @@ public class RedactController {
if (convertPDFToImage) { if (convertPDFToImage) {
PDDocument imageDocument = new PDDocument(); PDDocument imageDocument = new PDDocument();
PDFRenderer pdfRenderer = new PDFRenderer(document); PDFRenderer pdfRenderer = new PDFRenderer(document);
pdfRenderer.setSubsamplingAllowed(true);
for (int page = 0; page < document.getNumberOfPages(); ++page) { for (int page = 0; page < document.getNumberOfPages(); ++page) {
BufferedImage bim = pdfRenderer.renderImageWithDPI(page, 300, ImageType.RGB); BufferedImage bim = pdfRenderer.renderImageWithDPI(page, 300, ImageType.RGB);
PDPage newPage = new PDPage(new PDRectangle(bim.getWidth(), bim.getHeight())); PDPage newPage = new PDPage(new PDRectangle(bim.getWidth(), bim.getHeight()));

View file

@ -54,7 +54,7 @@ public class SanitizeController {
boolean removeLinks = request.isRemoveLinks(); boolean removeLinks = request.isRemoveLinks();
boolean removeFonts = request.isRemoveFonts(); boolean removeFonts = request.isRemoveFonts();
try (PDDocument document = Loader.loadPDF(inputFile.getBytes())) { PDDocument document = Loader.loadPDF(inputFile.getBytes());
if (removeJavaScript) { if (removeJavaScript) {
sanitizeJavaScript(document); sanitizeJavaScript(document);
} }
@ -81,7 +81,6 @@ public class SanitizeController {
.replaceFirst("[.][^.]+$", "") .replaceFirst("[.][^.]+$", "")
+ "_sanitized.pdf"); + "_sanitized.pdf");
} }
}
private void sanitizeJavaScript(PDDocument document) throws IOException { private void sanitizeJavaScript(PDDocument document) throws IOException {
// Get the root dictionary (catalog) of the PDF // Get the root dictionary (catalog) of the PDF

View file

@ -136,6 +136,7 @@ public class GeneralUtils {
int offset = oneBased ? 1 : 0; int offset = oneBased ? 1 : 0;
for (String page : pages) { for (String page : pages) {
if ("all".equalsIgnoreCase(page)) { if ("all".equalsIgnoreCase(page)) {
for (int i = 0; i < totalPages; i++) { for (int i = 0; i < totalPages; i++) {
result.add(i + offset); result.add(i + offset);
} }

View file

@ -214,6 +214,7 @@ public class PdfUtils {
throws IOException, Exception { throws IOException, Exception {
try (PDDocument document = Loader.loadPDF(inputStream)) { try (PDDocument document = Loader.loadPDF(inputStream)) {
PDFRenderer pdfRenderer = new PDFRenderer(document); PDFRenderer pdfRenderer = new PDFRenderer(document);
pdfRenderer.setSubsamplingAllowed(true);
int pageCount = document.getNumberOfPages(); int pageCount = document.getNumberOfPages();
// Create a ByteArrayOutputStream to save the image(s) to // Create a ByteArrayOutputStream to save the image(s) to

View file

@ -189,7 +189,11 @@ public class ProcessExecutor {
} }
} }
} else if (exitCode != 0) { } else if (exitCode != 0) {
throw new IOException("Command process failed with exit code " + exitCode); throw new IOException(
"Command process failed with exit code "
+ exitCode
+ "\nLogs: "
+ messages);
} }
} finally { } finally {
semaphore.release(); semaphore.release();

View file

@ -1,11 +0,0 @@
fileToPDF.fileTypesList=Microsoft Word: (DOC, DOCX, DOT, DOTX) <br> \
Microsoft Excel: (CSV, XLS, XLSX, XLT, XLTX, SLK, DIF) <br> \
Microsoft PowerPoint: (PPT, PPTX) <br> \
OpenDocument Formats: (ODT, OTT, ODS, OTS, ODP, OTP, ODG, OTG) <br> \
Plain Text: (TXT, TEXT, XML) <br> \
Rich Text Format: (RTF) <br> \
Images: (BMP, GIF, JPEG, PNG, TIF, PBM, PGM, PPM, RAS, XBM, XPM, SVG, SVM, WMF) <br> \
HTML: (HTML) <br> \
Lotus Word Pro: (LWP) <br> \
StarOffice formats: (SDA, SDC, SDD, SDW, STC, STD, STI, STW, SXD, SXG, SXI, SXW) <br> \
Other formats: (DBF, FODS, VSD, VOR, VOR3, VOR4, UOP, PCT, PS, PDF)

View file

@ -22,7 +22,17 @@
</form> </form>
<p class="mt-3" th:text="#{fileToPDF.credit}"></p> <p class="mt-3" th:text="#{fileToPDF.credit}"></p>
<p class="mt-3" th:text="#{fileToPDF.supportedFileTypes}"></p> <p class="mt-3" th:text="#{fileToPDF.supportedFileTypes}"></p>
<p th:utext="#{fileToPDF.fileTypesList}"></p> <p>Microsoft Word: (DOC, DOCX, DOT, DOTX)</p>
<p>Microsoft Excel: (CSV, XLS, XLSX, XLT, XLTX, SLK, DIF)</p>
<p>Microsoft PowerPoint: (PPT, PPTX)</p>
<p>OpenDocument Formats: (ODT, OTT, ODS, OTS, ODP, OTP, ODG, OTG)</p>
<p>Plain Text: (TXT, TEXT, XML)</p>
<p>Rich Text Format: (RTF)</p>
<p>Images: (BMP, GIF, JPEG, PNG, TIF, PBM, PGM, PPM, RAS, XBM, XPM, SVG, SVM, WMF)</p>
<p>HTML: (HTML)</p>
<p>Lotus Word Pro: (LWP)</p>
<p>StarOffice: (SDA, SDC, SDD, SDW, STC, STD, STI, STW, SXD, SXG, SXI, SXW)</p>
<p>Other: (DBF, FODS, VSD, VOR, VOR3, VOR4, UOP, PCT, PS, PDF)</p>
<a href="https://help.libreoffice.org/latest/en-US/text/shared/guide/supported_formats.html">https://help.libreoffice.org/latest/en-US/text/shared/guide/supported_formats.html</a> <a href="https://help.libreoffice.org/latest/en-US/text/shared/guide/supported_formats.html">https://help.libreoffice.org/latest/en-US/text/shared/guide/supported_formats.html</a>
</div> </div>
</div> </div>

View file

@ -22,8 +22,8 @@
<span class="icon-text" th:text="#{home.multiTool.title}"></span> <span class="icon-text" th:text="#{home.multiTool.title}"></span>
</a> </a>
</li> </li>
<li th:if="${@enableAlphaFunctionality}" class="nav-item nav-item-separator"></li> <li class="nav-item nav-item-separator"></li>
<li th:if="${@enableAlphaFunctionality}" class="nav-item"> <li class="nav-item">
<a class="nav-link" href="#" th:href="@{pipeline}" th:classappend="${currentPage}=='pipeline' ? 'active' : ''" th:title="#{home.pipeline.desc}"> <a class="nav-link" href="#" th:href="@{pipeline}" th:classappend="${currentPage}=='pipeline' ? 'active' : ''" th:title="#{home.pipeline.desc}">
<img class="icon" src="images/pipeline.svg" alt="icon"> <img class="icon" src="images/pipeline.svg" alt="icon">
<span class="icon-text" th:text="#{home.pipeline.title}"></span> <span class="icon-text" th:text="#{home.pipeline.title}"></span>

View file

@ -23,9 +23,8 @@
<br> <br>
<input type="text" id="searchBar" onkeyup="filterCards()" th:placeholder="#{home.searchBar}"> <input type="text" id="searchBar" onkeyup="filterCards()" th:placeholder="#{home.searchBar}">
<div class="features-container"> <div class="features-container">
<th:block th:if="${@enableAlphaFunctionality}">
<div th:replace="~{fragments/card :: card(id='pipeline', cardTitle=#{home.pipeline.title}, cardText=#{home.pipeline.desc}, cardLink='pipeline', svgPath='images/pipeline.svg', tags=#{pipeline.tags})}"></div> <div th:replace="~{fragments/card :: card(id='pipeline', cardTitle=#{home.pipeline.title}, cardText=#{home.pipeline.desc}, cardLink='pipeline', svgPath='images/pipeline.svg', tags=#{pipeline.tags})}"></div>
</th:block>
<div th:replace="~{fragments/card :: card(id='view-pdf', cardTitle=#{home.viewPdf.title}, cardText=#{home.viewPdf.desc}, cardLink='view-pdf', svgPath='images/book-opened.svg', tags=#{viewPdf.tags})}"></div> <div th:replace="~{fragments/card :: card(id='view-pdf', cardTitle=#{home.viewPdf.title}, cardText=#{home.viewPdf.desc}, cardLink='view-pdf', svgPath='images/book-opened.svg', tags=#{viewPdf.tags})}"></div>
<div th:replace="~{fragments/card :: card(id='multi-tool', cardTitle=#{home.multiTool.title}, cardText=#{home.multiTool.desc}, cardLink='multi-tool', svgPath='images/tools.svg', tags=#{multiTool.tags})}"></div> <div th:replace="~{fragments/card :: card(id='multi-tool', cardTitle=#{home.multiTool.title}, cardText=#{home.multiTool.desc}, cardLink='multi-tool', svgPath='images/tools.svg', tags=#{multiTool.tags})}"></div>
<div th:replace="~{fragments/card :: card(id='merge-pdfs', cardTitle=#{home.merge.title}, cardText=#{home.merge.desc}, cardLink='merge-pdfs', svgPath='images/union.svg', tags=#{merge.tags})}"></div> <div th:replace="~{fragments/card :: card(id='merge-pdfs', cardTitle=#{home.merge.title}, cardText=#{home.merge.desc}, cardLink='merge-pdfs', svgPath='images/union.svg', tags=#{merge.tags})}"></div>

126
test2.sh Normal file
View file

@ -0,0 +1,126 @@
#!/bin/bash
# Default values
build_type="full"
enable_security="false"
run_compose="true"
# Function to parse command line arguments
parse_args() {
case "$1" in
""|-lite|-ultra-lite) build_type="$1";;
esac
case "$2" in
true|false) enable_security="$2";;
esac
case "$3" in
true|false) run_compose="$3";;
esac
}
# Function to check the health of the service with a timeout of 80 seconds
check_health() {
local service_name=$1
local compose_file=$2
local end=$((SECONDS+80)) # Fixed the timeout to be 80 seconds as per the function comment
echo -n "Waiting for $service_name to become healthy..."
until [ "$(docker inspect --format='{{json .State.Health.Status}}' "$service_name")" == '"healthy"' ] || [ $SECONDS -ge $end ]; do
sleep 3
echo -n "."
if [ $SECONDS -ge $end ]; then
echo -e "\n$service_name health check timed out after 80 seconds."
echo "Printing logs for $service_name:"
docker logs "$service_name"
return 1
fi
done
echo -e "\n$service_name is healthy!"
echo "Printing logs for $service_name:"
docker logs "$service_name"
return 0
}
# Function to build and test a Docker Compose configuration
# Function to build and test a Docker Compose configuration
# Function to build and test a Docker Compose configuration
build_and_test() {
local version_tag="alpha"
local dockerfile_name="./Dockerfile"
local image_base="frooodle/s-pdf"
local security_suffix=""
local docker_compose_base="./exampleYmlFiles/docker-compose-latest"
local compose_suffix=".yml"
local service_name_base="Stirling-PDF"
if [ "$enable_security" == "true" ]; then
security_suffix="-Security"
docker_compose_base+="-security" # Append to base name for Docker Compose files with security
fi
case "$build_type" in
full)
dockerfile_name="./Dockerfile"
;;
lite)
dockerfile_name="./Dockerfile-lite"
;;
ultra-lite)
dockerfile_name="./Dockerfile-ultra-lite"
;;
esac
# Dynamic image tag and service name based on build type and security
local image_tag="${image_base}:latest${build_type}${security_suffix}"
local service_name="${service_name_base}${build_type^}${security_suffix}"
local compose_file="${docker_compose_base}${build_type}${compose_suffix}"
# Gradle build with or without security
echo "Running ./gradlew clean build with security=$enable_security..."
./gradlew clean build
if [ $? -ne 0 ]; then
echo "Gradle build failed, exiting script."
exit 1
fi
# Building Docker image
echo "Building Docker image $image_tag with Dockerfile $dockerfile_name..."
docker build --build-arg VERSION_TAG=$version_tag -t $image_tag -f $dockerfile_name .
if [ "$run_compose" == "true" ]; then
echo "Running Docker Compose for $build_type with security=$enable_security..."
docker-compose -f "$compose_file" up -d
# Health check using the dynamic service name
if ! check_health "$service_name" "$compose_file"; then
echo "$service_name health check failed."
docker-compose -f "$compose_file" down
exit 1
else
# If the health check passes, prompt the user to press any key to tear down the service
read -n 1 -s -r -p "Health check passed. Press any key to tear down the service."
echo "" # Move to a new line
# Tear down the service
docker-compose -f "$compose_file" down
fi
# Tear down the service after the health check passes
#docker-compose -f "$compose_file" down
fi
}
# Main function
main() {
SECONDS=0
parse_args "$@"
build_and_test
echo "All operations completed in $SECONDS seconds."
}
main "$@"