Java 如何设置GitHub Docker CI以运行所有子模块
我是Docker的初学者。我有一个Maven多模块项目,每个子模块都是SpringBoot微服务(因此每个子模块都是可执行的)。我在每个子模块中都添加了DockerFile,我想运行Docker CI,但失败的原因是:Java 如何设置GitHub Docker CI以运行所有子模块,java,spring-boot,docker,github,github-actions,Java,Spring Boot,Docker,Github,Github Actions,我是Docker的初学者。我有一个Maven多模块项目,每个子模块都是SpringBoot微服务(因此每个子模块都是可执行的)。我在每个子模块中都添加了DockerFile,我想运行Docker CI,但失败的原因是: unable to prepare context: path "/discovery-service" not found 发现服务是一个maven子模块名称。我的码头工人亚姆 name: Docker Image CI on: push: branches:
unable to prepare context: path "/discovery-service" not found
发现服务是一个maven子模块名称。我的码头工人亚姆
name: Docker Image CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build the Docker image
run: |
docker build /discovery-service --file Dockerfile --tag my-image-name:$(date +%s)
docker build /config-server --file Dockerfile --tag my-image-name:$(date +%s)
docker build /gateway-service --file Dockerfile --tag my-image-name:$(date +%s)
docker build /business-owner-service --file Dockerfile --tag my-image-name:$(date +%s)
© 2020 GitHub, Inc.
如何创建DockerFile?我想使用Github直接部署到Google Cloud Kubernetes上。免责声明:这可能是一个有点离题的答案,但我打赌它会有所帮助并提供一些有用的信息 解决方案:我建议您使用一个特定的Maven插件
com.spotify:dockerfile Maven插件
,该插件能够创建Docker文件和可能在CI中使用的图像
分项数字:
:目标
和构建
目标构建并将Docker映像推送到本地存储库推送
:带有图像名称的存储库名称repository
:基本dockerfile(如果从根目录使用,则导航到模块目录)dockerfile
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>1.4.10</version>
<executions>
<execution>
<id>default</id>
<goals>
<goal>build</goal>
<goal>push</goal>
</goals>
</execution>
</executions>
<configuration>
<repository>com.company/${project.artifactId}</repository>
<tag>${project.version}</tag>
<dockerfile>${project.parent.basedir}/Dockerfile</dockerfile>
<contextDirectory>${project.parent.basedir}</contextDirectory>
<pullNewerImage>false</pullNewerImage>
<buildArgs>
<BASE_DIRECTORY>${project.artifactId}</BASE_DIRECTORY>
</buildArgs>
</configuration>
</plugin>
com.spotify
. 因此,此插件可能仅在CI使用时是可选的,并且在您的计算机上构建时跳过。我已使其工作,以下是我的工作流程:
steps:
- uses: actions/checkout@v2
- name: Build the Docker image
run: |
docker build comand-API/discovery-service --file comand-API/discovery-service/Dockerfile --tag my-image-name:$(date +%s)
docker build comand-API/config-server --file comand-API/config-server/Dockerfile --tag my-image-name:$(date +%s)
docker build comand-API/gateway-service --file comand-API/gateway-service/Dockerfile --tag my-image-name:$(date +%s)
docker build comand-API/business-owner-service --file comand-API/business-owner-service/Dockerfile --tag my-image-name:$(date +%s)
基本上,我只需要在文件夹目标上丢失/并更新文件路径