module QB::Util::DockerMixin::ClassMethods

Class methods to extend the receiver with when {QB::Util::DockerMixin} is included.

Public Instance Methods

check_docker_tag(string) click to toggle source

Check that `string` is a valid Docker image tag, raising an error if not.

Check is performed via {QB::Util::DockerMixin::ClassMethods#valid_docker_tag}.

@param string see QB::Util::DockerMixin::ClassMethods#valid_docker_tag

@return [nil]

# File lib/qb/util/docker_mixin.rb, line 69
    def check_docker_tag string
      unless valid_docker_tag? string
        raise ArgumentError.new NRSER.squish <<-END
          Argument #{ string.inspect } is not a valid Docker image tag.
        END
      end
      nil
    end
to_docker_tag(semver) click to toggle source

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).

[Docker image tag]: github.com/moby/moby/issues/8445 [Docker image tag (archive)]: archive.is/40soa

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 {QB::Package::Version} instance.

[Semver]: semver.org/

@param [String] semver

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

@return [String]

Legal Docker image tag corresponding to `semver`.

@raise [ArgumentError]

If the resulting string is longer than 
{QB::Package::Version::DOCKER_TAG_MAX_CHARACTERS}.

@raise [ArgumentError]

If the resulting string still contains invalid characters for a Docker
image tag after the substitution.
# 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
valid_docker_tag?(string) click to toggle source

Test if `string` is a valid Docker image tag by seeing if it matches {QB::Util::DockerMixin::DOCKER_TAG_VALID_RE}

@param [String] string

String to test.

@return [Boolean]

True if `string` is a valid Docker image tag.
# File lib/qb/util/docker_mixin.rb, line 56
def valid_docker_tag? string
  DockerMixin::DOCKER_TAG_VALID_RE =~ string
end