Method: QB::Util::DockerMixin::ClassMethods#to_docker_tag

Defined in:
lib/qb/util/docker_mixin.rb

#to_docker_tag(semver) ⇒ String

Convert a Semver version string to a string suitable for use as a Docker image tag, which, as of writing, are restricted to

[A-Za-z0-9_.-]

and 128 characters max (used to be 30, but seems it's been increased).

This restriction prohibits Semver strings that use + to separate the build segments.

We replace + with _.

_ is not a legal character in Semver or Ruby Gem versions, making it clear that the resulting string is for Docker use, and allowing parsing to get back to an equal Package::Version instance.

Parameters:

  • semver (String)

    A legal [Semver][] version string to convert.

Returns:

  • (String)

    Legal Docker image tag corresponding to semver.

Raises:

  • (ArgumentError)

    If the resulting string is longer than DOCKER_TAG_MAX_CHARACTERS.

  • (ArgumentError)

    If the resulting string still contains invalid characters for a Docker image tag after the substitution.



115
116
117
118
119
# File 'lib/qb/util/docker_mixin.rb', line 115

def to_docker_tag semver
  semver.gsub('+', '_').tap { |docker_tag|
    check_docker_tag docker_tag
  }
end