Compare commits
5 Commits
dynamicPor
...
aws
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c297b4c561 | ||
|
|
50b4473a0a | ||
|
|
58b07d0d0d | ||
|
|
32a505609a | ||
|
|
69da443096 |
104
.github/workflows/push-docker.yml
vendored
104
.github/workflows/push-docker.yml
vendored
@@ -6,6 +6,7 @@ on:
|
|||||||
branches:
|
branches:
|
||||||
- master
|
- master
|
||||||
- main
|
- main
|
||||||
|
- aws
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
@@ -74,100 +75,30 @@ jobs:
|
|||||||
id: repoowner
|
id: repoowner
|
||||||
run: echo "lowercase=$(echo ${{ github.repository_owner }} | awk '{print tolower($0)}')" >> $GITHUB_OUTPUT
|
run: echo "lowercase=$(echo ${{ github.repository_owner }} | awk '{print tolower($0)}')" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: Generate tags
|
- name: Configure AWS credentials
|
||||||
id: meta
|
uses: aws-actions/configure-aws-credentials@v4
|
||||||
uses: docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96 # v5.6.1
|
|
||||||
with:
|
with:
|
||||||
images: |
|
role-to-assume: ${{ secrets.AWS_GITHUB_ROLE }}
|
||||||
${{ secrets.DOCKER_HUB_USERNAME }}/s-pdf
|
aws-region: ${{ secrets.AWS_REGION }}
|
||||||
ghcr.io/${{ steps.repoowner.outputs.lowercase }}/s-pdf
|
|
||||||
ghcr.io/${{ steps.repoowner.outputs.lowercase }}/stirling-pdf
|
|
||||||
${{ secrets.DOCKER_HUB_ORG_USERNAME }}/stirling-pdf
|
|
||||||
tags: |
|
|
||||||
type=raw,value=${{ steps.versionNumber.outputs.versionNumber }},enable=${{ github.ref == 'refs/heads/master' }}
|
|
||||||
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/master' }}
|
|
||||||
type=raw,value=alpha,enable=${{ github.ref == 'refs/heads/main' }}
|
|
||||||
|
|
||||||
- name: Build and push main Dockerfile
|
- name: Login to AWS Public ECR
|
||||||
id: build-push-regular
|
uses: aws-actions/amazon-ecr-login@v2
|
||||||
uses: docker/build-push-action@0adf9959216b96bec444f325f1e493d4aa344497 # v6.14.0
|
|
||||||
with:
|
with:
|
||||||
builder: ${{ steps.buildx.outputs.name }}
|
registry-type: public
|
||||||
context: .
|
|
||||||
file: ./Dockerfile
|
|
||||||
push: true
|
|
||||||
cache-from: type=gha
|
|
||||||
cache-to: type=gha,mode=max
|
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
|
||||||
build-args: VERSION_TAG=${{ steps.versionNumber.outputs.versionNumber }}
|
|
||||||
platforms: linux/amd64,linux/arm64/v8
|
|
||||||
provenance: true
|
|
||||||
sbom: true
|
|
||||||
|
|
||||||
- name: Sign regular images
|
|
||||||
if: github.ref == 'refs/heads/master'
|
|
||||||
env:
|
|
||||||
DIGEST: ${{ steps.build-push-regular.outputs.digest }}
|
|
||||||
TAGS: ${{ steps.meta.outputs.tags }}
|
|
||||||
COSIGN_PRIVATE_KEY: ${{ secrets.COSIGN_PRIVATE_KEY }}
|
|
||||||
COSIGN_PASSWORD: ${{ secrets.COSIGN_PASSWORD }}
|
|
||||||
run: |
|
|
||||||
echo "$TAGS" | tr ',' '\n' | while read -r tag; do
|
|
||||||
cosign sign --yes \
|
|
||||||
--key env://COSIGN_PRIVATE_KEY \
|
|
||||||
"${tag}@${DIGEST}"
|
|
||||||
done
|
|
||||||
|
|
||||||
- name: Generate tags ultra-lite
|
|
||||||
id: meta2
|
|
||||||
uses: docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96 # v5.6.1
|
|
||||||
if: github.ref != 'refs/heads/main'
|
|
||||||
with:
|
|
||||||
images: |
|
|
||||||
${{ secrets.DOCKER_HUB_USERNAME }}/s-pdf
|
|
||||||
ghcr.io/${{ steps.repoowner.outputs.lowercase }}/s-pdf
|
|
||||||
ghcr.io/${{ steps.repoowner.outputs.lowercase }}/stirling-pdf
|
|
||||||
${{ secrets.DOCKER_HUB_ORG_USERNAME }}/stirling-pdf
|
|
||||||
tags: |
|
|
||||||
type=raw,value=${{ steps.versionNumber.outputs.versionNumber }}-ultra-lite,enable=${{ github.ref == 'refs/heads/master' }}
|
|
||||||
type=raw,value=latest-ultra-lite,enable=${{ github.ref == 'refs/heads/master' }}
|
|
||||||
|
|
||||||
- name: Build and push Dockerfile-ultra-lite
|
|
||||||
id: build-push-lite
|
|
||||||
uses: docker/build-push-action@0adf9959216b96bec444f325f1e493d4aa344497 # v6.14.0
|
|
||||||
if: github.ref != 'refs/heads/main'
|
|
||||||
with:
|
|
||||||
context: .
|
|
||||||
file: ./Dockerfile.ultra-lite
|
|
||||||
push: true
|
|
||||||
cache-from: type=gha
|
|
||||||
cache-to: type=gha,mode=max
|
|
||||||
tags: ${{ steps.meta2.outputs.tags }}
|
|
||||||
labels: ${{ steps.meta2.outputs.labels }}
|
|
||||||
build-args: VERSION_TAG=${{ steps.versionNumber.outputs.versionNumber }}
|
|
||||||
platforms: linux/amd64,linux/arm64/v8
|
|
||||||
provenance: true
|
|
||||||
sbom: true
|
|
||||||
|
|
||||||
- name: Generate tags fat
|
- name: Generate tags fat
|
||||||
id: meta3
|
id: meta3
|
||||||
uses: docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96 # v5.6.1
|
uses: docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96 # v5.6.1
|
||||||
if: github.ref != 'refs/heads/main'
|
|
||||||
with:
|
with:
|
||||||
images: |
|
images: |
|
||||||
${{ secrets.DOCKER_HUB_USERNAME }}/s-pdf
|
public.ecr.aws/${{ secrets.AWS_PUBLIC_ECR_ALIAS }}/stirling-pdf
|
||||||
ghcr.io/${{ steps.repoowner.outputs.lowercase }}/s-pdf
|
|
||||||
ghcr.io/${{ steps.repoowner.outputs.lowercase }}/stirling-pdf
|
|
||||||
${{ secrets.DOCKER_HUB_ORG_USERNAME }}/stirling-pdf
|
|
||||||
tags: |
|
tags: |
|
||||||
type=raw,value=${{ steps.versionNumber.outputs.versionNumber }}-fat,enable=${{ github.ref == 'refs/heads/master' }}
|
type=raw,value=${{ steps.versionNumber.outputs.versionNumber }}-fat,enable=${{ github.ref == 'refs/heads/aws' }}
|
||||||
type=raw,value=latest-fat,enable=${{ github.ref == 'refs/heads/master' }}
|
type=raw,value=latest-fat,enable=${{ github.ref == 'refs/heads/aws' }}
|
||||||
|
|
||||||
- name: Build and push main Dockerfile fat
|
- name: Build and push main Dockerfile fat
|
||||||
id: build-push-fat
|
id: build-push-fat
|
||||||
uses: docker/build-push-action@0adf9959216b96bec444f325f1e493d4aa344497 # v6.14.0
|
uses: docker/build-push-action@0adf9959216b96bec444f325f1e493d4aa344497 # v6.14.0
|
||||||
if: github.ref != 'refs/heads/main'
|
|
||||||
with:
|
with:
|
||||||
builder: ${{ steps.buildx.outputs.name }}
|
builder: ${{ steps.buildx.outputs.name }}
|
||||||
context: .
|
context: .
|
||||||
@@ -182,14 +113,5 @@ jobs:
|
|||||||
provenance: true
|
provenance: true
|
||||||
sbom: true
|
sbom: true
|
||||||
|
|
||||||
- name: Sign fat images
|
|
||||||
if: github.ref == 'refs/heads/master'
|
|
||||||
env:
|
|
||||||
DIGEST: ${{ steps.build-push-fat.outputs.digest }}
|
|
||||||
TAGS: ${{ steps.meta3.outputs.tags }}
|
|
||||||
COSIGN_PRIVATE_KEY: ${{ secrets.COSIGN_PRIVATE_KEY }}
|
|
||||||
COSIGN_PASSWORD: ${{ secrets.COSIGN_PASSWORD }}
|
|
||||||
run: |
|
|
||||||
echo "$TAGS" | tr ',' '\n' | while read -r tag; do
|
|
||||||
cosign sign --key env://COSIGN_PRIVATE_KEY --yes "${tag}@${DIGEST}"
|
|
||||||
done
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package stirling.software.SPDF;
|
package stirling.software.SPDF;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.ServerSocket;
|
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
@@ -29,6 +28,7 @@ import stirling.software.SPDF.UI.WebBrowser;
|
|||||||
import stirling.software.SPDF.config.ConfigInitializer;
|
import stirling.software.SPDF.config.ConfigInitializer;
|
||||||
import stirling.software.SPDF.config.InstallationPathConfig;
|
import stirling.software.SPDF.config.InstallationPathConfig;
|
||||||
import stirling.software.SPDF.model.ApplicationProperties;
|
import stirling.software.SPDF.model.ApplicationProperties;
|
||||||
|
import stirling.software.SPDF.utils.UrlUtils;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@EnableScheduling
|
@EnableScheduling
|
||||||
@@ -64,6 +64,12 @@ public class SPDFApplication {
|
|||||||
app.setHeadless(false);
|
app.setHeadless(false);
|
||||||
props.put("java.awt.headless", "false");
|
props.put("java.awt.headless", "false");
|
||||||
props.put("spring.main.web-application-type", "servlet");
|
props.put("spring.main.web-application-type", "servlet");
|
||||||
|
|
||||||
|
int desiredPort = 8080;
|
||||||
|
String port = UrlUtils.findAvailablePort(desiredPort);
|
||||||
|
props.put("server.port", port);
|
||||||
|
System.setProperty("server.port", port);
|
||||||
|
log.info("Desktop UI mode: Using port {}", port);
|
||||||
}
|
}
|
||||||
|
|
||||||
app.setAdditionalProfiles(getActiveProfile(args));
|
app.setAdditionalProfiles(getActiveProfile(args));
|
||||||
@@ -160,7 +166,17 @@ public class SPDFApplication {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Value("${server.port:8080}")
|
@Value("${server.port:8080}")
|
||||||
public void setServerPortStatic(String port) {
|
public void setServerPort(String port) {
|
||||||
|
if ("auto".equalsIgnoreCase(port)) {
|
||||||
|
// Use Spring Boot's automatic port assignment (server.port=0)
|
||||||
|
SPDFApplication.serverPortStatic =
|
||||||
|
"0"; // This will let Spring Boot assign an available port
|
||||||
|
} else {
|
||||||
|
SPDFApplication.serverPortStatic = port;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setServerPortStatic(String port) {
|
||||||
if ("auto".equalsIgnoreCase(port)) {
|
if ("auto".equalsIgnoreCase(port)) {
|
||||||
// Use Spring Boot's automatic port assignment (server.port=0)
|
// Use Spring Boot's automatic port assignment (server.port=0)
|
||||||
SPDFApplication.serverPortStatic =
|
SPDFApplication.serverPortStatic =
|
||||||
@@ -197,36 +213,11 @@ public class SPDFApplication {
|
|||||||
return new String[] {"default"};
|
return new String[] {"default"};
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isPortAvailable(int port) {
|
|
||||||
try (ServerSocket socket = new ServerSocket(port)) {
|
|
||||||
return true;
|
|
||||||
} catch (IOException e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Optionally keep this method if you want to provide a manual port-incrementation fallback.
|
|
||||||
private static String findAvailablePort(int startPort) {
|
|
||||||
int port = startPort;
|
|
||||||
while (!isPortAvailable(port)) {
|
|
||||||
port++;
|
|
||||||
}
|
|
||||||
return String.valueOf(port);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getStaticBaseUrl() {
|
public static String getStaticBaseUrl() {
|
||||||
return baseUrlStatic;
|
return baseUrlStatic;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getNonStaticBaseUrl() {
|
|
||||||
return baseUrlStatic;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getStaticPort() {
|
public static String getStaticPort() {
|
||||||
return serverPortStatic;
|
return serverPortStatic;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getNonStaticPort() {
|
|
||||||
return serverPortStatic;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,7 +62,6 @@ public class RuntimePathConfig {
|
|||||||
String weasyPrintPath = isDocker ? "/opt/venv/bin/weasyprint" : "weasyprint";
|
String weasyPrintPath = isDocker ? "/opt/venv/bin/weasyprint" : "weasyprint";
|
||||||
String unoConvertPath = isDocker ? "/opt/venv/bin/unoconvert" : "unoconvert";
|
String unoConvertPath = isDocker ? "/opt/venv/bin/unoconvert" : "unoconvert";
|
||||||
|
|
||||||
|
|
||||||
// Check for custom operation paths
|
// Check for custom operation paths
|
||||||
Operations operations = properties.getSystem().getCustomPaths().getOperations();
|
Operations operations = properties.getSystem().getCustomPaths().getOperations();
|
||||||
if (operations != null) {
|
if (operations != null) {
|
||||||
@@ -82,5 +81,4 @@ public class RuntimePathConfig {
|
|||||||
private boolean isRunningInDocker() {
|
private boolean isRunningInDocker() {
|
||||||
return Files.exists(Paths.get("/.dockerenv"));
|
return Files.exists(Paths.get("/.dockerenv"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,7 +52,8 @@ public class CompressController {
|
|||||||
this.pdfDocumentFactory = pdfDocumentFactory;
|
this.pdfDocumentFactory = pdfDocumentFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void compressImagesInPDF(Path pdfFile, double initialScaleFactor, boolean grayScale) throws Exception {
|
private void compressImagesInPDF(Path pdfFile, double initialScaleFactor, boolean grayScale)
|
||||||
|
throws Exception {
|
||||||
byte[] fileBytes = Files.readAllBytes(pdfFile);
|
byte[] fileBytes = Files.readAllBytes(pdfFile);
|
||||||
try (PDDocument doc = Loader.loadPDF(fileBytes)) {
|
try (PDDocument doc = Loader.loadPDF(fileBytes)) {
|
||||||
double scaleFactor = initialScaleFactor;
|
double scaleFactor = initialScaleFactor;
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
package stirling.software.SPDF.utils;
|
package stirling.software.SPDF.utils;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.ServerSocket;
|
||||||
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
public class UrlUtils {
|
public class UrlUtils {
|
||||||
@@ -14,4 +17,20 @@ public class UrlUtils {
|
|||||||
|
|
||||||
return scheme + "://" + serverName + ":" + serverPort + contextPath;
|
return scheme + "://" + serverName + ":" + serverPort + contextPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isPortAvailable(int port) {
|
||||||
|
try (ServerSocket socket = new ServerSocket(port)) {
|
||||||
|
return true;
|
||||||
|
} catch (IOException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String findAvailablePort(int startPort) {
|
||||||
|
int port = startPort;
|
||||||
|
while (!isPortAvailable(port)) {
|
||||||
|
port++;
|
||||||
|
}
|
||||||
|
return String.valueOf(port);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ public class SPDFApplicationTest {
|
|||||||
private ApplicationProperties applicationProperties;
|
private ApplicationProperties applicationProperties;
|
||||||
|
|
||||||
@InjectMocks
|
@InjectMocks
|
||||||
private SPDFApplication SPDFApplication;
|
private SPDFApplication sPDFApplication;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
@@ -49,8 +49,4 @@ public class SPDFApplicationTest {
|
|||||||
assertEquals("8080", SPDFApplication.getStaticPort());
|
assertEquals("8080", SPDFApplication.getStaticPort());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetNonStaticPort() {
|
|
||||||
assertEquals("8080", SPDFApplication.getNonStaticPort());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user