The following examples use a GoLang Git repository represented by a GitRepo resource named gosvc_app
to create a Docker image that is published to Artifactory. They assume that an Artifactory integration named MyArtifactory
(JFrog Platform Access Token Integration) has been created, and that the Artifactory instance has a Docker repository mapped to docker.artprod.company
.
These examples require an Artifactory Integration or JFrog Platform Access Token Integration and a GitHub Integration.
The Pipelines DSL for a similar example is available in this repository in the JFrog GitHub account.
For a full tutorial, see Pipeline Example: Docker Build and Push.
For more information on DockerBuild Pipeline steps, see DockerBuild.
The following resources declarations support these examples. Not all of these resources are used in all examples.
Resources
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 # Files in an Artifactory repository - name: icon_files type: FileSpec configuration: sourceArtifactory: myArtifactory pattern: my-local-repo/all-my-images/ target: icons/
Build a Docker image from a source repository
This example builds a Docker image to a Docker registry in Artifactory. The tag for the image is set to the pipeline's run number.
pipelines: - name: demo_pipeline steps: - name: bld_image type: DockerBuild configuration: dockerFileLocation: . dockerFileName: Dockerfile dockerImageName: docker.artprod.mycompany.com/gosvc # replace with your fully qualified Docker registry/image name dockerImageTag: ${run_number} inputResources: - name: gosvc_app integrations: - name: MyArtifactory
Build a Docker image with dockerOptions
This example demonstrates use of the dockerOptions
tag to set the build-arg
option for the Docker command. An environment variable named build_number_env_variable
is dynamically set to the pipeline's run number. The example assumes the environment variable is used in the Dockerfile commands.
pipelines: - name: demo_pipeline steps: - name: bld_image type: DockerBuild configuration: dockerFileLocation: . dockerFileName: Dockerfile dockerImageName: docker.artprod.mycompany.com/gosvc # replace with your fully qualified Docker registry/image name dockerImageTag: ${run_number} dockerOptions: --build-arg build_number_env_variable=${run_number} inputResources: - name: gosvc_app integrations: - name: MyArtifactory
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.
pipelines: - name: demo_pipeline steps: - name: bld_image type: DockerBuild configuration: dockerFileLocation: . dockerFileName: Dockerfile dockerImageName: docker.artprod.mycompany.com/gosvc # replace with your fully qualified Docker registry/image name dockerImageTag: ${run_number} inputResources: - name: gosvc_app - name: base_image integrations: - name: MyArtifactory
Build a Docker image with files outside the current path
This example demonstrates building a Docker image that includes files outside of the current path. It pulls icon files stored in an Artifactory repository for integration art named my-local-repo
. It is assumed that the Dockerfile has a command that will include the files in /icons
into the image.
pipelines: - name: demo_pipeline steps: - name: bld_image type: DockerBuild configuration: dockerFileLocation: . dockerFileName: Dockerfile dockerImageName: docker.artprod.mycompany.com/gosvc # replace with your fully qualified Docker registry/image name dockerImageTag: ${run_number} inputResources: - name: gosvc_app - name: icon_files integrations: - name: MyArtifactory