I would like to build a docker image based on an existing docker image(caching) from Artifactory.
I have checked the following configuration in the documentation:
https://www.jfrog.com/confluence/display/JFROG/DockerBuild
To build a Docker image that relies on a private base image:
Define the base image as an Image resource, with autoPull set to true.
Specify the Image resource as one of the inputResources of the DockerBuild step.
Build a Docker image with a private base image
This example builds a Docker image that relies on a private base image stored in an
Artifactory Docker repository.
resources:
# Application source repository
- name: gosvc_app
type: GitRepo
configuration:
gitProvider: myGithub
path: myuser/myrepo # replace with your repository name
branches:
include: master
# Docker image in an Artifactory repository
- name: base_image
type: Image
configuration:
registry: myArtifactory
sourceRepository: docker-local # replace with your repository name
imageName: docker.artprod.mycompany.com/baseimage
imageTag: latest
autoPull: true
pipelines:
- name: demo_pipeline
steps:
- name: bld_image
type: DockerBuild
configuration:
dockerFileLocation: .
dockerFileName: Dockerfile
dockerImageName: docker.artprod.mycompany.com/gosvc
dockerImageTag: ${run_number}
inputResources:
- name: gosvc_app
- name: base_image
integrations:
- name: MyArtifactory
Running this pipeline throws the following error:
"pipeline demo_pipeline has cyclic connection involving step bld_image.
A pipeline can not have cyclic connections.
If I configure DockerBuild with only the Image resource i am getting the following error.
Running this pipeline throws the following error:
"DockerBuild step bld_image must have exactly one input resource of type GitRepo"
So in one part of the documentation you can use 2 resources under 'inputResources' and while using this configuration throws the above error.
And in other part of the documentation it uses only the Image resource which throws the error of "...exactly one input resource of type GitRepo".
So how can i achieve building a docker image base on a docker image(caching) stored in Artifactory?
Solution for using a remote cache docker image with buildx in the Artifactory:
steps:
- name: {{ .Values.DockerBuild.name | default "DockerBuild" }}
type: DockerBuild
execution:
onStart:
- docker buildx create --name jfrog-builder --use
- docker buildx install
- jf c add example --url="$int_{{ .Values.artifactoryIntegration }}_url" --user="$int_{{ .Values.artifactoryIntegration }}_user" --password="$int_{{ .Values.artifactoryIntegration }}_password"
- echo $int_{{ .Values.artifactoryIntegration }}_apikey | docker login --username $int_{{ .Values.artifactoryIntegration }}_user --password-stdin {{ .Values.artifactoryUrl }}
configuration:
dockerFileLocation: {{ .Values.DockerBuild.dockerFileLocation | quote }}
dockerFileName: {{ .Values.DockerBuild.dockerFileName }}
dockerImageName: {{ .Values.DockerBuild.dockerImageName }}
dockerImageTag: {{ .Values.DockerBuild.dockerImageTag }}
dockerOptions: "--cache-from type=registry,ref={{ .Values.DockerBuild.dockerImageName }}:{{ .Values.DockerBuild.dockerImageCacheTag }} --cache-to type=registry,ref={{ .Values.DockerBuild.dockerImageName }}:{{ .Values.DockerBuild.dockerImageCacheTag }},mode=max --load"
inputResources:
- name: {{ .Values.GitRepo.name | default "GitRepoRes" }}