DockerBuildAndPush

JFrog Pipelines Documentation

Products
JFrog Pipelines
Content Type
User Guide
ft:sourceType
Paligo

See it Live

Click here to see this Global template in action.

The DockerBuildAndPush template creates a pipeline that builds a Docker image from an SCM repository and pushes it to a Docker registry. Version 1.0.0 of this template uses JFrog CLI v1 and version 1.1.0 uses JFrog CLI v2. Template version 1.0.0 requires targetRepository and sourceRepository settings (see template readme) and template version 1.1.0 does not use these settings.

DockerBuildAndPush YAML

resources:
  - name: {{ .Values.GitRepo.name | default "GitRepoRes" }}
    type: GitRepo
    configuration:
      gitProvider: {{ .Values.GitRepo.gitProvider }}
      path: {{ .Values.GitRepo.path }}
      {{- if or (.Values.GitRepo.branches.include) (.Values.GitRepo.branches.exclude) }}
      branches:
        {{- if .Values.GitRepo.branches.include }}
          include: {{ .Values.GitRepo.branches.include }}
        {{- end }}
        {{- if .Values.GitRepo.branches.exclude }}
          exclude: {{ .Values.GitRepo.branches.exclude }}
        {{- end }}
      {{- end }}

  - name: {{ .Values.Image.name | default "ImageRes" }}
    type: Image
    configuration:
      registry: {{ .Values.artifactoryIntegration }}
      imageName: {{ .Values.DockerBuild.dockerImageName }}
      imageTag: {{ .Values.DockerBuild.dockerImageTag | default "latest" }}
      autoPull: {{ .Values.Image.autopull | default true }}

  {{- if .Values.BuildInfo }}
  - name: {{ .Values.BuildInfo.name | default "BuildInfo" }}
    type: BuildInfo
    configuration:
      sourceArtifactory: {{ .Values.artifactoryIntegration }}
      buildName: {{ .Values.DockerPush.name | default "DockerPush" }}
      buildNumber: {{ .Values.BuildInfo.buildNumber | default 1 }}
  {{- end }}

pipelines:
  - name: {{ .Values.Pipeline.name | default "Pipeline" }}
    configuration:
      jfrogCliVersion: 2
    steps:
      - name: {{ .Values.DockerBuild.name | default "DockerBuild" }}
        type: DockerBuild
        configuration:
          affinityGroup: DockerBuildAndPush
          dockerFileLocation: {{ .Values.DockerBuild.dockerFileLocation | default "." | quote }}
          dockerFileName: {{ .Values.DockerBuild.dockerFileName | default "Dockerfile" }}
          dockerImageName: {{ .Values.DockerBuild.dockerImageName }}
          dockerImageTag: {{ .Values.DockerBuild.dockerImageTag }}
          inputResources:
            - name: {{ .Values.GitRepo.name | default "GitRepoRes" }}
          integrations:
            - name: {{ .Values.artifactoryIntegration }}

      - name: {{ .Values.DockerPush.name | default "DockerPush" }}
        type: DockerPush
        configuration:
          {{- if .Values.BuildInfo }}
          autoPublishBuildInfo: {{ .Values.BuildInfo.autoPublishBuildInfo | default true }}
          {{- end }}
          affinityGroup: DockerBuildAndPush
          integrations:
            - name: {{ .Values.artifactoryIntegration }}
          inputSteps:
            - name: {{ .Values.DockerBuild.name | default "DockerBuild" }}
          outputResources:
            - name: {{ .Values.Image.name | default "ImageRes" }}
            {{- if .Values.BuildInfo }}
            - name: {{ .Values.BuildInfo.name | default "BuildInfo" }}
            {{- end }}

values.yml: This is a sample values.yml. This can be edited to create your own version of the file.

GitRepo:                                            # Required.
  name: fooGitRepo                                  # Name of the GitRepo resource. Defaults to GitRepoRes.
  gitProvider: github                               # Required. Name of the SCM integration which will be used to fetch the SCM. repository.
  path: jfrog/jfrog-pipelines-simple-example        # Required. Path to the SCM repository.
  branches:
    exclude: 'master'                               # Regex pattern to exclude branches.
    include: ^{{gitBranch}}$                        # Regex pattern to include branches.

artifactoryIntegration: art                         # Required. Name of the artifactory integration using which the docker image will be pushed.

Image:                                              # Required.
  name: fooImage                                    # Name of the Image resource. Defaults to ImageRes.
  autoPull: false                                   # Defaults to true.

DockerBuild:                                        # Required.
  name: foobuild                                    # Name of the DockerBuild step. Defaults to DockerBuild.
  dockerImageName: foo                              # Required. Name of the docker image getting built.
  dockerFileName: foo                               # Required. Name of the Dockerfile.
  dockerFileLocation: '.'                           # Required. Path to Dockerfile.
  dockerImageTag: ${run_number}                     # Name of the docker image tag. Defaults to latest.

Pipeline:
  name: foo                                         # Name of the pipeline. Defaults to Pipeline.

DockerPush:                                         # Required.
  name: foopush                                     # Name of the DockerPush step. Defaults to DockerPush.

BuildInfo:                                          # Optional, if the BuildInfo needs to be published.
  autoPublishBuildInfo: true                        # Defaults to true.
  name: fooBuildInfo                                # Name of the BuildInfo resource. Defaults to BuildInfo.