容器内的微服务正在使用mavenCli,但目标文件夹没有生成



我在docker容器内部有一个微服务。这个微服务是基于open-api-generator maven插件来生成基于mustache模板和原型的子项目。

我使用maven来打包项目并创建容器。这是我的docker文件

FROM --platform=linux/arm64 maven:3.8.3-openjdk-17 as build
ENV TIME_ZONE America/Guayaquil
ENV TZ=$TIME_ZONE
ENV JAVA_OPTS "-Djava.awt.headless=true -Xmx1250m -Xms256m - 
Dmaven.artifact.threads=10"
WORKDIR /app
RUN mkdir /app/archetype
RUN mkdir /app/archetype/src
ADD archetype/src/ /app/archetype/src/
ADD archetype/*.xml /app/archetype/
ADD archetype/*.json /app/archetype/
ADD archetype/*.md /app/archetype
RUN mkdir /app/openapi
RUN mkdir /app/openapi/templates
ADD openapi/templates/* /app/openapi/templates/
RUN mkdir /app/base
COPY ./base/. /app/base
RUN mkdir /app/devops
RUN mkdir /app/domain
COPY /pom.xml /app/pom.xml
COPY /openapi.yml /app/openapi.yml
COPY /src /app/src
RUN mvn -f /app/pom.xml clean package -Dmaven.artifact.threads=20 -e -X
EXPOSE 9010
ENTRYPOINT exec java -jar /app/target/generator-code-1.0.0-SNAPSHOT.jar -e java.io.tmpDir=/app

抱歉,如果有更好的方式来写docker文件,我开始使用docker。

一切正常。正确执行Maven命令后,jar将在target文件夹中生成。项目正常启动(项目有一个前端web,以便以yml格式上传开放api合同)。

现在问题开始了(顺便说一下,它在本地与IntelliJ一起正常工作)

然后我填写我的web字段,我上传新的openapi。为了使用open-API-generator maven插件并生成类,微服务需要执行maven命令(clean install)。我使用mavenCli是为了在我的微服务中执行maven命令。

子项目生成,但使用的是构建容器时创建的target文件夹中的文件。当clean install命令被执行时,它应该在新文件时替换target文件夹,但什么也没有发生。

没有错误,警告。我看到容器文件和目标文件夹没有更新。

我希望我能正确地解释我自己。

如果有任何方法或任何配置,我需要执行,以正确设置目标文件夹?

这是我的POM.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.peigo.ec.generator</groupId>
<artifactId>peigo-generator-code</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Generator</name>
<description>Project Generator Peigo</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<openapi-generator.version>4.2.3</openapi-generator.version>
<cloud-client.version>2.2.5.RELEASE</cloud-client.version>
<base.package>com.peigo.generator</base.package>
<java.version>11</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<openapi.source.directory>${project.build.directory}/generated-sources/openapi</openapi.source.directory>

<maven-failsafe-plugin.version>2.22.2</maven-failsafe-plugin.version>
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
</properties>
<dependencies>
...
...
...
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<encoding default-value="UTF-8">UTF-8</encoding>
<argLine>-Dfile.encoding=${project.build.sourceEncoding}</argLine>
</configuration>
</plugin>
<!-- Used for integration tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${maven-failsafe-plugin.version}</version>
<configuration>
<encoding default-value="UTF-8">UTF-8</encoding>
<argLine>-Dfile.encoding=${project.build.sourceEncoding} -Djava.io.tmpdir=${project.build.directory}</argLine>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<release>${java.version}</release>
</configuration>
</plugin>
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>5.4.0</version>
<executions>
<execution>
<id>generate</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<!-- This section includes the "global" configuration options, so called because they apply to all generators. Users generally don't need to care about this detail, except to make sure their configuration information lands in the correct place - <configuration> vs <configOptions>. -->
<!-- The OpenAPI spec is in a file in this repository called "openapi.yml". It can also be a hyperlink. -->
<inputSpec>${project.basedir}/openapi.yml</inputSpec>
<!-- There are many generators available. We are using jaxrs-spec. -->
<generatorName>spring</generatorName>
<library>spring-boot</library>
<!-- APIs are service interfaces or implementations. -->
<generateApis>true</generateApis>
<!-- Models are DTOs, generally from the schemas portion of the spec. -->
<generateModels>true</generateModels>
<!-- In this example, we're not generating the POM, README, etc. -->
<generateSupportingFiles>false</generateSupportingFiles>
<!-- This is the default value, but be explicit so it's clear when we refer to the value elsewhere. -->
<output>${openapi.source.directory}</output>
<!-- We are showing off template customization today. The custom templates are stored here. -->
<templateDirectory>${project.basedir}/openapi/templates</templateDirectory>
<configOptions>
<!-- These are the "local" configuration options that apply only to this generator. -->
<!-- https://openapi-generator.tech/docs/generators/jaxrs-spec -->
<!-- These are the packages we want our APIs and Models generated in, respectively. -->
<apiPackage>com.ec.peigo.infrastructure.adapter.input</apiPackage>
<modelPackage>com.ec.peigo.domain.model</modelPackage>
<useBeanValidation>true</useBeanValidation>
<performBeanValidation>true</performBeanValidation>
<serializableModel>true</serializableModel>
<skipDefaultInterface>false</skipDefaultInterface>
<dateLibrary>java17</dateLibrary>
<useSwaggerAnnotations>true</useSwaggerAnnotations>
<!-- These values are largely up to you, and depend on your goals and philosophy. This SSCCE should support all permutations of the below. -->
<!-- I prefer to have interface methods return model objects, not JAX-RS Response objects. I can still generate any response I want by throwing WebApplicationException classes. -->
<!-- If this is set to true, then all generated service methods will return javax.ws.rs.core.Response objects. -->
<!-- If this is set to false, then all generated service methods will return their respective model objects. -->
<returnResponse>false</returnResponse>
<!-- I prefer to generate interfaces, not implementation. This allows me to make sure that my client and server implementations are in sync. -->
<!-- If this is set to true, then service interfaces will be generated. -->
<!-- If this is set to false, then service implementations will be generated. -->
<interfaceOnly>false</interfaceOnly>
<!-- This is a useful feature for web frameworks that support the JAX-RS 2.1 feature of implementing asynchronous processing by returning CompletionStage instances. In all cases, generated service methods return either Response or a model object, depending on the above configuration. This configuration option affects all methods. Users cannot choose to make individual methods synchronous versus asynchronous. -->
<!-- If this is set to true, then all generated service method return types will be changed from T to CompletionStage<T>. -->
<!-- If this is set to false, then all generate service method return types will be unchanged. -->
<supportAsync>false</supportAsync>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<id>add-source</id>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<!-- Add the generated source to the project so it gets compiled -->
<source>${openapi.source.directory}/src/gen/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>

试试这个:-

ENTRYPOINT exec java -jar /app/app/target/generator-code-1.0.0-SNAPSHOT.jar -e java.io.tmpDir=/app

jar应该在-/app/app/target

我猜原因应该是WORKDIR /app

要调试你的dockerfile,你可以在不同的地方添加这个命令

RUN ls -lrt

它将显示目录内容为list