Setup

Docker Setup

Beim Bereitstellen und Deployen der Anwendung in Docker-Containern ist zu berücksichtigen, dass die Anwendung als .jar deployt wird, die Produktdaten jedoch in entpackter Form in den Container kopiert und konfiguriert werden. Hierfür muss zunächst in der pom.xml der vaadin.productionMode auf true gesetzt werden.

        <properties>
            <vaadin.productionMode>true</vaadin.productionMode>
        </properties>
        <build>
            <plugins>
                <plugin>
                    <groupId>com.vaadin</groupId>
                    <artifactId>vaadin-maven-plugin</artifactId>
                    <version>${vaadin.version}</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>build-frontend</goal>
                            </goals>
                            <phase>compile</phase>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>

Beispiel Dockerfile:

FROM eclipse-temurin:21-jre-jammy
RUN apt-get update \
    && ln -sf /usr/share/zoneinfo/Europe/Berlin /etc/localtime \
    && dpkg-reconfigure -f noninteractive tzdata
ARG UID=999
ARG GID=999
ENV JAVA_TOOL_OPTIONS "-Xms480m -Xmx1024m"
RUN groupadd --gid $GID spring \
    && useradd -r -m -d /opt/spring -s /sbin/nologin --gid $GID --uid $UID -c "Spring user" spring \
    && chmod 755 /opt/spring \
    && mkdir -p /var/opt/spring \
    && chown spring: /var/opt/spring \
    && chmod 755 /var/opt/spring
WORKDIR /opt/spring
COPY ${PATH_TO_APPLICATION_JAR} application.jar
COPY ${PATH_TO_PRODUCT_FOLDER} /var/opt/spring/produkte
COPY ${PATH_TO_GIT_KEY} /opt/spring/productdesigner.key # the name of the key used in the keyPath configuration in the application.yml, if git mode is used
COPY ${PATH_TO_MAVEN_SETTINGS} /opt/spring/.m2/settings.xml
RUN chown -R spring: /var/opt/spring
USER $UID
EXPOSE 8080
CMD ["java", \
    "-Dspring.profiles.active=production", \
    "-jar", \
    "application.jar", \
    "--server.port=8080", \
    "--server.forward-headers-strategy=FRAMEWORK"]

Der Product Designer löst Abhängigkeiten des Produktprojekts via Maven auf. Dazu muss das Deployment ggf. eine passende settings.xml erhalten, um auf nicht-öffentliche Repositories wie Nexus zugreifen zu können. Wird der Product Designer nicht nur lesend genutzt, muss ein SSH-Schlüssel passend zum keyPath in der Version Control Mode-Section der application.yml in das Image kopiert werden.

Beispiel docker-compose.yml:

version: '2.4'

services:
  productdesigner-sample:
    container_name: ${CONTAINER_NAME}-sample
    build:
      context: ../
      dockerfile: ./path/to/Dockerfile
      args:
      - PATH_TO_APPLICATION_JAR=${PATH_TO_APPLICATION_JAR}
      - PATH_TO_PRODUCT_FOLDER=${PATH_TO_PRODUCT_FOLDER}
      - PATH_TO_GIT_KEY=${PATH_TO_GIT_KEY}
      - PATH_TO_MAVEN_SETTINGS=${PATH_TO_MAVEN_SETTINGS}
    environment:
      SPRING_PROFILES_ACTIVE: production
      ips-product-designer.ips-project-path: /var/opt/spring/produkte
    labels:
      url: ${CONTAINER_NAME}-sample
      entry-path: ui

networks:
    default:
        name: network-${CONTAINER_NAME}
        labels:
            retention: ${CONTAINER_RETENTION}