Module: QB::Util::DockerMixin::ClassMethods
- Defined in:
- lib/qb/util/docker_mixin.rb
Overview
Class methods to extend the receiver with when QB::Util::DockerMixin is included.
Instance Method Summary collapse
-
#check_docker_tag(string) ⇒ nil
Check that
stringis a valid Docker image tag, raising an error if not. -
#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.
-
#valid_docker_tag?(string) ⇒ Boolean
Test if
stringis a valid Docker image tag by seeing if it matches DOCKER_TAG_VALID_RE.
Instance Method Details
#check_docker_tag(string) ⇒ nil
Check that string is a valid Docker image tag, raising an error if not.
Check is performed via #valid_docker_tag.
41 42 43 44 45 46 47 48 |
# File 'lib/qb/util/docker_mixin.rb', line 41 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) ⇒ 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.
87 88 89 90 91 |
# File 'lib/qb/util/docker_mixin.rb', line 87 def to_docker_tag semver semver.gsub('+', '_').tap { |docker_tag| check_docker_tag docker_tag } end |
#valid_docker_tag?(string) ⇒ Boolean
Test if string is a valid Docker image tag by seeing if it matches
DOCKER_TAG_VALID_RE
28 29 30 |
# File 'lib/qb/util/docker_mixin.rb', line 28 def valid_docker_tag? string DockerMixin::DOCKER_TAG_VALID_RE =~ string end |