Docker

Description

This plugin enables you to build and publish Docker images in a Vela pipeline.

Source Code: https://github.com/go-vela/vela-docker

Registry: https://hub.docker.com/r/target/vela-docker

Usage

NOTE:

Users should refrain from using latest as the tag for the Docker image.

It is recommended to use a semantically versioned tag instead.

Samples of building and publishing an image:

steps:
  - name: publish_hello-world
    image: target/vela-docker:latest
    pull: always
    parameters:
      registry: index.docker.io
      repo: octocat/hello-world
      tags: [ latest ]
steps:
  - name: publish_hello-world
    image: target/vela-docker:latest
    pull: always
    parameters:
      registry: index.docker.io
      tags: [ index.docker.io/octocat/hello-world:latest ]

NOTE: The two above samples are functionally equivalent.

Sample of building an image without publishing:

steps:
  - name: publish hello world
    image: target/vela-docker:latest
    pull: always
    parameters:
+     dry_run: true
      registry: index.docker.io
      repo: octocat/hello-world
      tags: [ latest ]

Sample of building and publishing an image with custom tags:

steps:
  - name: publish hello world
    image: target/vela-docker:latest
    pull: always
    parameters:
      registry: index.docker.io
      repo: octocat/hello-world
-     tags: [ latest ]
+     tags: 
+       - latest
+       - octocat/hello-world:1
+       - index.docker.io/octocat/hello-world:foobar

Sample of building and publishing an image with build arguments:

steps:
  - name: publish hello world
    image: target/vela-docker:latest
    pull: always
    parameters:
+     build_args:
+       - FOO=bar
      registry: index.docker.io
      repo: octocat/hello-world
      tags: [ latest ]

Sample of building and publishing an image with image caching:

steps:
  - name: publish_hello-world
    image: target/vela-docker:latest
    pull: always
    parameters:
+     cache_from: index.docker.io/octocat/hello-world
      registry: index.docker.io
      repo: octocat/hello-world
      tags: [ latest ]

Sample of building and publishing with custom daemon settings:

steps:
  - name: publish_hello-world
    image: target/vela-docker:latest
    pull: always
    parameters:
+     daemon: 
+       registry_mirrors: mirror.index.docker.io
      registry: index.docker.io
      repo: octocat/hello-world
      tags: [ latest ]

Secrets

NOTE: Users should refrain from configuring sensitive information in your pipeline in plain text.

Internal

Users can use Vela internal secrets to substitute these sensitive values at runtime:

steps:
  - name: publish_hello-world
    image: target/vela-docker:latest
    pull: always
+   secrets: [ docker_username, docker_password ]
    parameters:
      registry: index.docker.io
      repo: octocat/hello-world
      tags: [ latest ]
-     username: octocat
-     password: superSecretPassword

This example will add the secrets to the publish_hello-world step as environment variables:

  • DOCKER_USERNAME=<value>
  • DOCKER_PASSWORD=<value>

External

The plugin accepts the following files for authentication:

ParameterVolume Configuration
password/vela/parameters/docker/password, /vela/secrets/docker/password
username/vela/parameters/docker/username, /vela/secrets/docker/username

Users can use Vela external secrets to substitute these sensitive values at runtime:

steps:
  - name: publish_hello-world
    image: target/vela-docker:latest
    pull: always
    parameters:
      registry: index.docker.io
      repo: octocat/hello-world
      tags: [ latest ]
-     username: octocat
-     password: superSecretPassword

This example will read the secret values in the volume stored at /vela/secrets/

Parameters

NOTE:

The plugin supports reading all parameters via environment variables or files.

Any values set from a file take precedence over values set from the environment.

By default build kit is on; it can be turned off by setting DOCKER_BUILDKIT=0 in the environment.

The key.key syntax signifies a new yaml object within the definition.

The following parameters are used to configure the image:

NameDescriptionRequiredDefaultEnvironment Variables
add_hostsset a custom host-to-IP mapping - format (host:ip)falseN/APARAMETER_ADD_HOSTS
DOCKER_ADD_HOSTS
build_argsset variables to pass to the image at build-timefalseN/APARAMETER_BUILD_ARGS
DOCKER_BUILD_ARGS
cache_fromset of images to consider as cache sourcesfalseN/APARAMETER_CACHE_FROM
DOCKER_CACHE_FROM
cgroup_parentset a parent cgroup for the containerfalseN/APARAMETER_CGROUP_PARENT
DOCKER_CGROUP_PARENT
compressenable compressing the build context using gzipfalsefalsePARAMETER_COMPRESS
DOCKER_COMPRESS
contextset of files and/or directory to build the image fromtrue.PARAMETER_CONTEXT
DOCKER_CONTEXT
cpuset the cpu parameter, see cpu settings belowfalseN/APARAMETER_CPU
DOCKER_CPU
daemonset the daemon parameter, see daemon settings belowfalseN/APARAMETER_DAEMON
DOCKER_DAEMON
disable_content_trustenable skipping verification of the imagefalsetruePARAMETER_DISABLE_CONTENT_TRUST
DOCKER_DISABLE_CONTENT_TRUST
dry_runenable building the image without publishingfalsefalsePARAMETER_DRY_RUN
DOCKER_DRY_RUN
fileset the name of the DockerfilefalseN/APARAMETER_FILE
DOCKER_FILE
force_rmenable always removing the intermediate containers after a successful buildfalsefalsePARAMETER_FORCE_RM
DOCKER_FORCE_RM
image_id_fileset the file to write the image ID tofalseN/APARAMETER_IMAGE_ID_FILE
DOCKER_IMAGE_ID_FILE
isolationset container isolation technologyfalseN/APARAMETER_ISOLATION
DOCKER_ISOLATION
labelsset metadata for an imagefalseN/APARAMETER_LABELS
DOCKER_LABELS
log_levelset the log level for the plugintrueinfoPARAMETER_LOG_LEVEL
DOCKER_LOG_LEVEL
memoryset memory limitfalseN/APARAMETER_MEMORY
DOCKER_MEMORY
memory_swapsset the swap limit equal to memory plus swap: ‘-1’ to enable unlimited swapfalseN/APARAMETER_MEMORY_SWAPS
DOCKER_MEMORY_SWAPS
networkset the networking mode for the RUN instructions during buildfalseN/APARAMETER_NETWORK
DOCKER_NETWORK
no_cachedisable caching when building the imagefalsefalsePARAMETER_NO_CACHE
DOCKER_NO_CACHE
outputset the output destination - format (type=local,dest=path)falseN/APARAMETER_OUTPUTS
DOCKER_OUTPUTS
passwordset password for communication with the registrytrueN/APARAMETER_PASSWORD
DOCKER_PASSWORD
platformset a platform if server is multi-platform capablefalseN/APARAMETER_PLATFORM
DOCKER_PLATFORM
progressset type of progress output - options (auto|plain|tty)falseN/APARAMETER_PROGRESS
DOCKER_PROGRESS
pullenable always attempting to pull a newer version of the imagefalsefalsePARAMETER_PULL
DOCKER_PULL
quietenable suppressing the build output and print image ID on successfalsefalsePARAMETER_QUIET
DOCKER_QUIET
registryset Docker registry address to communicate withtrueindex.docker.ioPARAMETER_REGISTRY
DOCKER_REGISTRY
removeenable removing the intermediate containers after a successful buildfalsetruePARAMETER_REMOVE
DOCKER_REMOVE
reposet Docker repository for the imagefalseN/APARAMETER_REPO
DOCKER_REPO
secretset secret file to expose to the build (only if BuildKit enabled) - format (id=mysecret,src=/local/secret)falseN/APARAMETER_SECRETS
DOCKER_SECRETS
security_optsset options for securityfalseN/APARAMETER_SECURITY_OPTS
DOCKER_SECURITY_OPTS
shm_sizesset the size of /dev/shmfalseN/APARAMETER_SHM_SIZES
DOCKER_SHM_SIZES
squashenable squashing newly built layers into a single new layerfalsefalsePARAMETER_SQUASH
DOCKER_SQUASH
ssh_componentsset SSH agent socket or keys to expose to the build (only if BuildKit enabled) - format (default|[=|[,]])falseN/APARAMETER_SSH_COMPONENTS
DOCKER_SSH_COMPONENTS
streamenable stream attaching to the server to negotiate build contextfalsefalsePARAMETER_STREAM
DOCKER_STREAM
tagsset the tags for the Docker image - format (name:tag)trueN/APARAMETER_TAGS
DOCKER_TAGS
targetset the target build stage to buildfalseN/APARAMETER_TARGET
DOCKER_TARGET
ulimitsset options for ulimitsfalseN/APARAMETER_ULIMITS
DOCKER_ULIMITS
usernameset user name for communication with the registrytrueN/APARAMETER_USERNAME
DOCKER_USERNAME

CPU

The following settings are used to configure the cpu parameter:

NameDescriptionRequiredDefault
periodset limit on the CPU CFS (Completely Fair Scheduler) periodfalseN/A
quotaset limit on the CPU CFS (Completely Fair Scheduler) quotafalseN/A
sharesset CPU shares (relative weight)falseN/A
set_cpusset CPUs in which to allow execution (0-3, 0,1)falseN/A
set_memsset MEMs in which to allow execution (0-3, 0,1)falseN/A

Daemon

The following settings are used to configure the daemon parameter:

NameDescriptionRequiredDefault
bipset a network bridge IPfalseN/A
dnsset the DNS settings, see dns settings belowfalseN/A
experimentalenable experimental featuresfalseN/A
insecure_registriesset the insecure Docker registriesfalseN/A
ipv6enable IPv6 networkingfalseN/A
mtuset the network MTU for the containfalseN/A
registry_mirrorsset the Docker registry mirrorsfalseN/A
storageset the storage settings, see storage settings belowfalseN/A

DNS

The following settings are used to configure the dns daemon setting:

NameDescriptionRequiredDefault
serversset the DNS nameserversfalseN/A
searchesset the DNS search domainsfalseN/A

Storage

The following settings are used to configure the storage daemon setting:

NameDescriptionRequiredDefault
driverset the storage driver for the daemonfalseN/A
optsset the storage options for the daemonfalseN/A

Template

COMING SOON!

Troubleshooting

You can start troubleshooting this plugin by tuning the level of logs being displayed:

steps:
  - name: publish_hello-world
    image: target/vela-docker:latest
    pull: always
    parameters:
      registry: index.docker.io
      repo: octocat/hello-world
      tags: [ latest ]
+     log_level: trace

Below are a list of common problems and how to solve them: