[英]Github Actions: Push docker image build by gradle task
For building images of my current project, I use the gradle task bootBuildImage
.为了构建我当前项目的映像,我使用 gradle 任务
bootBuildImage
。 This task creates a OCI image using Cloud Native Buildpacks .此任务使用 Cloud Native Buildpacks 创建 OCI 映像。
- name: Build image with Gradle
run: ./gradlew bootBuildImage
With the next step I'm trying to push this docker image to my private GitHub registry using build-push-action .在下一步中,我尝试使用build-push-action将此 docker 映像推送到我的私有 GitHub 注册表。
- name: Push image to Registry
uses: docker/build-push-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
registry: docker.pkg.github.com
repository: sullrich84/wettkampfdb-backend
tags: latest
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
As I can tell from the logs, the problem with this step is that it seems to rely on a Dockerfile
located in the workspaces root directory which does not exist.从日志中我可以看出,此步骤的问题在于它似乎依赖于位于工作区根目录中的
Dockerfile
,而该目录不存在。
unable to prepare context: unable to evaluate symlinks in Dockerfile path:
lstat /github/workspace/Dockerfile: no such file or directory
Is it possible to push the image created via bootBuildImage
to my private GitHub registry without using/creating a dedicated Dockerfile
?是否可以在不使用/创建专用
Dockerfile
的情况下将通过bootBuildImage
创建的映像推送到我的私有 GitHub 注册表?
If you are just looking for something to deal with docker push
, you can just use the native docker
command to do it.如果您只是在寻找一些东西来处理
docker push
,您可以使用本机docker
命令来完成它。
Something like this.像这样的东西。
- name: run docker push
run: |
@docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
@docker push $BUILD_TAG
@docker push $LATEST_TAG
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_USERNAME: ${{ secrets.DOCKER_PASSWORD }}
The github-action you are using is not for pushing an image you define by repository
and tag
but rahter build and push
https://github.com/docker/build-push-action#build-push-action您使用的 github-action 不是用于推送您通过
repository
和tag
定义的图像,而是用于build and push
https://github.com/docker/build-push-action#build-push-action
Builds and pushes Docker images and will log in to a Docker registry if required.
构建并推送 Docker 映像,如果需要,将登录到 Docker 注册表。
Specifically this is also related to https://github.com/docker/build-push-action/issues/17 - so just building without pushing is possible, not vice versa.具体来说,这也与https://github.com/docker/build-push-action/issues/17有关 - 所以只构建而不推送是可能的,反之亦然。
This github action does yet not allow just pushing.这个 github 动作还不允许仅仅推动。
This is for now very common for a lot of CI/CD solutions, where build and push are one task.这对于很多 CI/CD 解决方案来说现在很常见,其中构建和推送是一项任务。
I use publishRegistry option of gradle bootBuildImage.我使用 gradle bootBuildImage 的 publishRegistry 选项。
Set parameter in your build.gradle (below is gradle.kts)在您的 build.gradle 中设置参数(下面是 gradle.kts)
tasks.bootBuildImage {
imageName = "${imageName}:${project.version}"
isPublish = true
docker {
publishRegistry {
url = dockerUrl
username = dockerUsername
password = dockerPassword
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.