From 89022c0a2422ed3b1fb1607fd6dcd5c99c8aec98 Mon Sep 17 00:00:00 2001 From: Ludy Date: Sun, 2 Mar 2025 20:35:41 +0100 Subject: [PATCH] Devcontainer (#3097) # Description of Changes Please provide a summary of the changes, including: - What was changed - Why the change was made - Any challenges encountered Closes #(issue_number) --- ## Checklist ### General - [ ] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [ ] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md) (if applicable) - [ ] I have performed a self-review of my own code - [ ] My changes generate no new warnings ### Documentation - [ ] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### UI Changes (if applicable) - [ ] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ### Testing (if applicable) - [ ] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing) for more details. --- .devcontainer/devcontainer.json | 114 ++++++++++++++++++++++++++++++++ Dockerfile.dev | 56 ++++++++++++++++ scripts/init-setup.sh | 8 +++ 3 files changed, 178 insertions(+) create mode 100644 .devcontainer/devcontainer.json create mode 100644 Dockerfile.dev create mode 100644 scripts/init-setup.sh diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..6827e109 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,114 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-dockerfile +{ + "name": "Stirling-PDF Dev Container", + "build": { + // Sets the run context to one level up instead of the .devcontainer folder. + "context": "..", + // Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename. + "dockerfile": "../Dockerfile.dev", + }, + // Use 'forwardPorts' to make a list of ports inside the container available locally. + "appPort": [8080], + "workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind,consistency=delegated", + "mounts": [ + "source=logs-volume,target=/workspace/logs,type=volume" + ], + "workspaceFolder": "/workspace", + // Configure tool-specific properties. + "customizations": { + "vscode": { + "settings": { + "terminal.integrated.shell.linux": "/bin/bash", + "editor.wordSegmenterLocales": "", + "editor.guides.bracketPairs": "active", + "editor.guides.bracketPairsHorizontal": "active", + "cSpell.enabled": false, + "[java]": { + "editor.defaultFormatter": "josevseb.google-java-format-for-vs-code" + }, + "java.compile.nullAnalysis.mode": "automatic", + "java.configuration.updateBuildConfiguration": "interactive", + "java.format.enabled": true, + "java.format.settings.profile": "GoogleStyle", + "java.format.settings.google.version": "1.25.2", + "java.format.settings.google.extra": "--aosp --skip-sorting-imports --skip-javadoc-formatting", + "java.saveActions.cleanup": true, + "java.cleanup.actions": [ + "invertEquals", + "instanceofPatternMatch" + ], + "java.completion.engine": "dom", + "java.completion.enabled": true, + "java.completion.importOrder": [ + "java", + "javax", + "org", + "com", + "net", + "io", + "jakarta", + "lombok", + "me", + "stirling" + ], + "java.project.resourceFilters": [ + ".devcontainer/", + ".git/", + ".github/", + ".gradle/", + ".venv/", + ".venv*/", + ".vscode/", + "bin/", + "build/", + "configs/", + "customFiles/", + "docs/", + "exampleYmlFiles", + "gradle/", + "images/", + "logs/", + "pipeline/", + "scripts/", + "testings/", + ".git-blame-ignore-revs", + ".gitattributes", + ".gitignore", + ".pre-commit-config.yaml" + ], + "java.signatureHelp.enabled": true, + "java.signatureHelp.description.enabled": true, + "java.maven.downloadSources": true, + "java.import.gradle.enabled": true, + "java.eclipse.downloadSources": true, + "java.import.gradle.wrapper.enabled": true, + "spring.initializr.defaultLanguage": "Java", + "spring.initializr.defaultGroupId": "stirling.software.SPDF", + "spring.initializr.defaultArtifactId": "SPDF" + }, + "extensions": [ + "elagil.pre-commit-helper", // Support for pre-commit hooks to enforce code quality + "josevseb.google-java-format-for-vs-code", // Google Java code formatter to follow the Google Java Style Guide + "ms-python.black-formatter", // Python code formatter using Black + "ms-python.flake8", // Flake8 linter for Python to enforce code quality + "ms-python.python", // Official Microsoft Python extension with IntelliSense, debugging, and Jupyter support + "ms-vscode-remote.vscode-remote-extensionpack", // Remote Development Pack for SSH, WSL, and Containers + "Oracle.oracle-java", // Oracle Java extension with additional features for Java development + "streetsidesoftware.code-spell-checker", // Spell checker for code to avoid typos + "vmware.vscode-boot-dev-pack", // Developer tools for Spring Boot by VMware + "vmware.vscode-spring-boot", // Spring Boot tools by VMware for enhanced Spring development + "vscjava.vscode-java-pack", // Java Extension Pack with essential Java tools for VS Code + "vscjava.vscode-spring-boot-dashboard", // Spring Boot dashboard for managing and visualizing Spring Boot applications + "vscjava.vscode-spring-initializr", // Support for Spring Initializr to create new Spring projects + "EditorConfig.EditorConfig", // EditorConfig support for maintaining consistent coding styles + "ms-azuretools.vscode-docker", // Docker extension for Visual Studio Code + "charliermarsh.ruff" // Ruff extension for Ruff language support + ] + } + }, + // Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root. + "remoteUser": "devuser", + "shutdownAction": "stopContainer", + "postStartCommand": "chmod +x scripts/init-setup.sh && ./scripts/init-setup.sh" +} diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 00000000..afe840e2 --- /dev/null +++ b/Dockerfile.dev @@ -0,0 +1,56 @@ +# dockerfile.dev + +# Basisimage: Gradle mit JDK 17 (Debian-basiert) +FROM gradle:8.12-jdk17 + +# Als Root-Benutzer arbeiten, um benötigte Pakete zu installieren +USER root + +# Update und Installation zusätzlicher Pakete (Debian/Ubuntu-basiert) +RUN apt-get update && apt-get install -y \ + wget \ + ca-certificates \ + tzdata \ + tini \ + bash \ + curl \ + libreoffice \ + poppler-utils \ + qpdf \ + tesseract-ocr \ + tesseract-ocr-eng \ + fonts-dejavu \ + fonts-noto \ + python3 \ + python3-pip \ + python3-venv \ + && apt-get clean && rm -rf /var/lib/apt/lists/* + +# Setze die Environment Variable für setuptools +ENV SETUPTOOLS_USE_DISTUTILS=local + +# Installation der benötigten Python-Pakete +RUN python3 -m venv /opt/venv \ + && . /opt/venv/bin/activate \ + && pip install --upgrade setuptools \ + && pip install --no-cache-dir WeasyPrint pdf2image pillow unoserver opencv-python-headless pre-commit + +# Füge den venv-Pfad zur globalen PATH-Variable hinzu, damit die Tools verfügbar sind +ENV PATH="/opt/venv/bin:$PATH" + +# Erstelle notwendige Verzeichnisse und lege einen Nicht‑Root Benutzer an +RUN mkdir -p /home/devuser/{configs,logs,customFiles,pipeline/watchedFolders,pipeline/finishedFolders} \ + && adduser --disabled-password --gecos '' devuser \ + && chown -R devuser:devuser /home/devuser + +RUN mkdir -p /home/devuser/logs && chown devuser:devuser /home/devuser/logs +RUN mkdir -p /workspace/logs && chown devuser:devuser /workspace/logs +RUN mkdir -p /workspace/src && chown devuser:devuser /workspace/src +RUN mkdir -p /workspace/src/main && chown devuser:devuser /workspace/src/main +RUN mkdir -p /workspace/src/main/resources && chown devuser:devuser /workspace/src/main/resources + +# Setze das Arbeitsverzeichnis (wird später per Bind-Mount überschrieben) +WORKDIR /workspace + +# Wechsel zum Nicht‑Root Benutzer +USER devuser diff --git a/scripts/init-setup.sh b/scripts/init-setup.sh new file mode 100644 index 00000000..a495add7 --- /dev/null +++ b/scripts/init-setup.sh @@ -0,0 +1,8 @@ +#!/bin/bash +set -e + +whoami + +cd "$(dirname "$0")/.." + +./gradlew bootRun