From 4612619dc46e3273b1616b4732c605494d7882b1 Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Wed, 19 Sep 2018 10:52:59 -0700 Subject: [PATCH] Fixup docker config update --- plugins/providers/docker/config.rb | 19 +++++++++---------- templates/locales/providers_docker.yml | 2 +- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/plugins/providers/docker/config.rb b/plugins/providers/docker/config.rb index 6abc997cc..07c4e5333 100644 --- a/plugins/providers/docker/config.rb +++ b/plugins/providers/docker/config.rb @@ -14,12 +14,12 @@ module VagrantPlugins attr_accessor :build_args # The directory with a Dockerfile to build and use as the basis - # for this container. If this is set, neither "image" nor "git_repo" + # for this container. If this is set, neither "image" nor "git_repo" # should be set. # # @return [String] attr_accessor :build_dir - + # The URL for a git repository with a Dockerfile to build and use # as the basis for this container. If this is set, neither "image" # nor "build_dir" should be set. @@ -197,7 +197,7 @@ module VagrantPlugins has_image = (other.image != UNSET_VALUE) has_build_dir = (other.build_dir != UNSET_VALUE) has_git_repo = (other.git_repo != UNSET_VALUE) - + if (has_image ^ has_build_dir ^ has_git_repo) && !(has_image && has_build_dir && has_git_repo) # image if has_image @@ -208,7 +208,7 @@ module VagrantPlugins result.git_repo = nil end end - + # build_dir if has_build_dir if @image != UNSET_VALUE @@ -218,7 +218,7 @@ module VagrantPlugins result.git_repo = nil end end - + # git_repo if has_git_repo if @build_dir != UNSET_VALUE @@ -296,10 +296,9 @@ module VagrantPlugins def validate(machine) errors = _detected_errors - - # FIXME: is there a more ruby-elegant way to write this? - if (@build_dir? 1 : 0) + (@git_repo? 1 : 0) + (@image? 1 : 0) > 1 - errors << I18n.t("docker_provider.errors.config.both_build_and_image") + + if [@build_dir, @git_repo, @image].compact.size > 1 + errors << I18n.t("docker_provider.errors.config.both_build_and_image_and_git") end if !@build_dir && !@git_repo && !@image @@ -312,7 +311,7 @@ module VagrantPlugins errors << I18n.t("docker_provider.errors.config.build_dir_invalid") end end - + # Comparison logic taken directly from docker's urlutil.go if @git_repo && !( @git_repo =~ /^http(?:s)?:\/\/.*.git(?:#.+)?$/ || @git_repo =~ /^git(?:hub\.com|@|:\/\/)/) errors << I18n.t("docker_provider.errors.config.git_repo_invalid") diff --git a/templates/locales/providers_docker.yml b/templates/locales/providers_docker.yml index 99aefd370..ba90473c6 100644 --- a/templates/locales/providers_docker.yml +++ b/templates/locales/providers_docker.yml @@ -141,7 +141,7 @@ en: and notify them to not use this communicator for anything except the "docker" provider. config: - both_build_and_image: |- + both_build_and_image_and_git: |- Only one of "build_dir", "git_repo" or "image" can be set build_dir_invalid: |- "build_dir" must exist and contain a Dockerfile