Docker and Build Push Example: pipelines.yml

JFrog Pipelines Documentation

Products
JFrog Pipelines
Content Type
User Guide
ft:sourceType
Paligo

This topic provides an example of a Docker and Push YAML examine named pipelines.yaml. For information about the Pipeline Example Docker and Build Push, see Docker and Build Push Example: pipelines.yml.

The pipelines.yml file is made up of resources, pipelines and steps, as shown below:

Resources

This example uses the following types of resources:

  • GitRepo

  • Image

  • BuildInfo

GitRepo

A GitRepo resource is used to connect JFrog Pipelines to a source control repository. Adding it creates a webhook to the repo so that future commits will automatically create a new version with the webhook payload.

resources

  - name: dbp_repo
    type: GitRepo
    configuration:
      gitProvider: my_github                       # <-- replace with your integration
      path: jfrog/jfrog-pipelines-docker-sample    # <-- replace with your repository name
      branches:
        include: master

Tag

Description

Required/Optional

name

dbp_repo is the name of the GitRepo resource pointing to the repository containing the Dockerfile and other source code required to build the image.

This name is used to refer to the resource in steps, and must be unique across all repositories in your JFrog Pipelines environment.

Required

gitProvider

The name of the GitHub Integration.

Required

path

The path of the repository from the integration root.

Required

branches

  • include -- (optional) Regular expression to include branches from the repo

  • exclude-- (optional) Regular expression to exclude branches from the repo

The include: master tag indicates that the GitRepo resource is listening to the master branch.

Optional

Image

An Image resource is used to add a reference to a Docker image to your pipeline. An Image resource can be used as both input and output. Steps like DockerBuild will generate it as an output and steps like DockerPublish will use it as input to publish to a Docker registry. In our example, it is used as an outputResource for the DockerPush step.

resources

  - name: dbp_image
    type: Image
    configuration:
      registry: art                                # <-- replace with your artifactory integration
      sourceRepository: docker_local               # <-- required if registry is Artifactory
      imageName: docker.artprod.mycompany.com/docker_local/dbp  # < -- replace with your image path and name
      imageTag: latest
      autoPull: true

Tag

Description

Required/Optional

name

dbp_image is the name that identifies the resource.

Required

registry

art is the name of a Docker Registry Integration.

Required

sourceRepository

docker_local is the name of the repository in Artifactory to which the images will be published.

Required if registry is in JFrog Artifactory

imageName

The file path of the Docker image, of the form imageRepo/imageName.

Required

imageTag

The version tag of the initial version of the Docker image.

Required

autoPull

When true, the image is automatically pulled to the machine running the step.

Defaults to false.

Optional

BuildInfo

BuildInfo is automatically created when the DockerBuild step is used to generate packages. BuildInfo is then published to the configured Artifactory repo (sourceArtifactory: art) through the PublishBuildInfo step, by providing that resource in the DockerPush step.

resources

  - name: dbp_build_info
    type: BuildInfo
    configuration:
      sourceArtifactory: art
      buildName: dbp_build
      buildNumber: 1    

  - name: dbp_promoted_build_info
    type: BuildInfo
    configuration:
      sourceArtifactory: art
      buildName: dbp_build
      buildNumber: 1

Tag

Description

Required/Optional

name

dbp_build_info and dbp_promoted_build_info are the name of the BuildInfo resources, which is the metadata associated with the build in Artifactory.

This name is used to refer to the resource in steps, and must be unique across all repositories in your JFrog Pipelines environment.

Required

sourceArtifactory

art is the name of the Artifactory Integration or JFrog Platform Access Token Integration .

Required

buildName

dbp_build is the name of the build to associate with the BuildInfo.

Optional

buildNumber

The number of the build to associate with the BuildInfo.

Optional

Pipelines

pipeline_dbp, the pipeline definition for building and pushing the Docker image.

Steps

The pipeline_dbp pipeline contains the following native steps:

  • DockerBuild

  • DockerPush

  • PublishBuildInfo

  • PromoteBuild

DockerBuild

The DockerBuild native step performs a build to produce a Docker image from a Dockerfile in a Git source repository.

This step builds a Docker image from a GitRepo source repository resource. You must provide in the step configuration the name and directory of the Dockerfile that contains the command to be processed by a docker build command, as well as the name and tag of the resulting image. The image is built on the build node, and information about that image is stored in the run state.

steps

      - name: docker_build
        type: DockerBuild
        configuration:
          affinityGroup: dbp_group
          dockerFileLocation: .
          dockerFileName: Dockerfile
          dockerImageName: docker.artprod.mycompany.com/docker_local/dbp  # replace with your image path and name
          dockerImageTag: ${run_number}
          inputResources:
            - name: dbp_repo
          integrations:
            - name: art                            # <-- replace with your artifactory integration

Tag

Description of usage

Required/Optional

name

docker_build is the name that identifies the step.

This is the name that is used when the step is assigned as an input to the next step, docker_push.

Required

affinityGroup

Must specify an affinity group string that is the same as specified in a subsequent DockerPush step.

Both DockerBuild and DockerPush steps are assigned to the dbp_group affinityGroup so that they share the same state. If they are not, the output of the DockerBuild step won't be available to the DockerPush step.

Optional

dockerFileLocation

Directory containing the Dockerfile or the file that has Docker build configuration

Required

dockerFileName

Name of the Dockerfile

Required

dockerImageName

The name of the Docker image to create. This can be set using environment variables or triggering a run using parameters.

Required

dockerImageTag

The tag for the Docker image to create. This can be set using environment variables or triggering a run using parameters.

In our example, the tag for the image is set to the pipeline's run number, which is the number of the run currently executing.

Required

inputResources

Must specify:

  • a ??? resource (that contains the DockerFile)

This step accepts `dbp_repo` as an inputResource to build the image based on the provided Dockerfile.

Optionally, may also specify:

  • an Image resource of a base Image to include in the built Image

  • a FileSpec resource that specifies what files to include in the built Image. These files are automatically copied to dockerFileLocation.

Required/Optional

integrations

Must specify an Artifactory Integration.

Required

DockerPush

The DockerPush native step pushes the specified Docker Image to Artifactory.

steps

      - name: docker_push
        type: DockerPush
        configuration:
          affinityGroup: dbp_group
          targetRepository: docker-local
          integrations:
            - name: art                            # <-- replace with your artifactory integration
          inputSteps:
            - name: docker_build
          outputResources:
            - name: dbp_image

Tag

Description of usage

Required/Optional

name

docker_push is the name that identifies the step.

Required

affinityGroup

Must specify an affinity group string that is the same as specified in the prior DockerBuild step.

Optional

targetRepository

The name of the Docker repository in Artifactory.

Required

integrations

Must specify an Artifactory Integration or JFrog Platform Access Token Integration .

Required

inputSteps

Must specify the named DockerBuild step in the same affinity group.

The output (result) of the previous docker_build step is used as an inputStep for this step.

Required

outputResources

May specify an Image resource. If one is specified, the imageTag property of that resource will be updated with the dockerImageTag of the preceding DockerBuild step.

This step outputs `dbp_image` as an outputResource, which can be used to trigger downstream dependent steps or pipelines if needed.

Optional

May be required

PublishBuildInfo

The PublishBuildInfo step publishes BuildInfo attached to the image to Artifactory. BuildInfo provides a manifest for the build and includes metadata about the modules, dependencies and other environment variables.

BuildInfo can also be published by any of the language-specific publish steps, when its autoPublishBuildInfo tag is set to true.

steps

      - name: publish_dbp_build
        type: PublishBuildInfo
        configuration:
          inputSteps:
            - name: docker_push
          outputResources:
            - name: dbp_build_info

Tag

Description of usage

Required/Optional

name

publish_dbp_build is the name that identifies the step.

Required

inputSteps

Must specify the name of the DockerPush step. The output (result) of the previous step is used as an inputStep for this step.

The step must nothave set autoPublishBuildInfo to true.

Required

outputResources

Must specify a BuildInfo resource to publish.

Required

PromoteBuild

The PromoteBuild native step promotes the dbp_build_info BuildInfo and moves or copies the related artifacts from one Artifactory repository to another.

steps

This step requires either a PublishBuildInfo step as previous step or a BuildInfo resource as an input to successfully execute.

      - name: promote_dbp_build
        type: PromoteBuild
        configuration:
          targetRepository: demo-pipelines
          integrations:
            - name: art
          inputResources:
            - name: dbp_build_info
          outputResources:
            - name: dbp_promoted_build_info

Tag

Description of usage

Required/Optional

name

promote_dbp_build is the name that identifies the step.

Required

targetRepository

demo-pipelines is the name of the repository in Artifactory to promote the build to.

Required

integrations

Must specify an Artifactory Integration or JFrog Platform Access Token Integration .

Required

inputResources

Must specify a named BuildInfo resource whose buildName and buildNumber properties identify the build to promote.

Required

outputResources

Must specify a named BuildInfo resource to map to the promoted build. The BuildInfo will be updated with the buildName and buildNumber of the input BuildInfo resource, and its targetRepo with the value of targetRepository .

Required