288 Commits

Author SHA1 Message Date
Paul Hinze
8d46b09a11
Fix Docker machines being lost in go side
By pruning machines that are in "unknown" status after each operation,
the Go code path exposed the fact that the Docker provider was not
updating the machine index during an "up" - leaving the state as
"unknown".

This is basically a bug within the Docker provider, so I think it's okay
to update the plugin code to correct this rather than working around the
issue in Go.

All we need to do is call `machine.state` instead of reaching through to
`machine.provider.state` while waiting for the container to be started.
That causes the extra logic for updating the machine index in
`machine.state` to fire.
2022-07-13 14:04:32 -05:00
Chris Roberts
84d3a5fe47 Update compose tests to pass fully through Util::Subprocess 2021-07-12 09:54:56 -07:00
sophia
04977677f1 Pass in docker command opts as a map 2021-07-08 12:15:06 -05:00
Chris Roberts
3d0d0148e9 Update tests to use real UI instance
Replaces use of UI doubles within tests to use actual UI instance
    to ensure calls are passing parameters correctly.
2021-06-23 14:04:48 -07:00
Chris Roberts
c5664e479e Fix matching on build output for docker provider 2021-04-13 13:23:43 -07:00
sophia
66a3b58c08 Add provider capaiblity :has_communicator 2020-06-09 09:33:11 -05:00
sophia
9b6c562016 Set run config for provisioner 2020-05-29 15:33:43 -04:00
sophia
33576b5846 Docker provider to run provisioners if available 2020-05-29 15:33:42 -04:00
Brian Cain
cfb9a6457e
Remove obtaining name from docker container info 2020-05-12 11:26:48 -07:00
Brian Cain
c18ceb20bc
Define custom port_check method for halted docker containers 2020-05-12 11:17:15 -07:00
Brian Cain
b2d9abe344
Fixes #9067: Ensure new containers don't grab existing bound ports
Prior to this commit, if a created but exited container bound a port,
and a new container grabed that same port (say for an ssh port forward),
when the initial container came back up it would fail because the port
also got bound to the second container. This commit fixes that behavior
by first looking at what containers are already bound prior to creating
a container.
2020-05-11 10:17:22 -07:00
Jaroslav Prokop
5208032594 Docker provider: catch container name when using podman.
When user is using podman's docker CLI emulation the containers would
fail to enter running state because the docker driver could not catch
the container name. This commit fixes that by adding a check if podman
docker emulation is used and pick the container hash correctly from the
output.
2020-03-25 19:34:31 +01:00
Sophia Castellarin
2dadeb3ee5
Merge pull request #11461 from soapy1/get-docker-image-id
Get correct docker image from build output
2020-03-24 09:27:20 -05:00
sophia
324294993e Check for docker buildkit output first
When buildkit is enabled docker will write out
`writing image <image id>`
When buildkit is not enables docker will write out
`Successfully builld <image id>`
It is more likely that searching for the `writing image` will not
clash with build output than when searching for `Successfully built`.
eg. when installing python packages with pip, it is common to use
the verbage `Successfully built`.
2020-03-23 13:54:49 -05:00
sophia
380c25a7ae Get last image id from docker output 2020-03-23 10:10:19 -05:00
Terry Burton
c9ca7b8f57
docker provider: Don't explode when removing an image if it is in use
Output from recent Docker has changed:

    Stderr: Error response from daemon: conflict: unable to delete 0ba49dd235e5 (cannot be forced) - image is being used by running container 250bbe980448

Fixes #7245
2020-01-30 20:06:32 +00:00
Brian Cain
2901dae948
Add option for docker executor to handle stderr from results
Instead of always joining stdout and stderr, only join the two if the
caller explicitly asks for it. Otherwise, only return stdout.
2019-11-22 12:04:09 -08:00
Brian Cain
4d70856b8a
Enhance docker build matching for determining built container ID
Prior to this commit, docker would look for a container ID based on
"Successfully built" string. This output does not exist if a user has
enabled the experimental feature buildkit. This commit updates the build
behavior to match against both kinds of outputs, and instead of using
`scan`, it uses MatchData and groups the container id with match group
name `:id` instead of making hard assumptions with the matches being
contained inside arrays from scan.
2019-11-19 10:59:28 -08:00
Juha Ruotsalainen
4fc8b07974
Removed the word 'done'.
There are cases, when 'done' is prefix with a duration, like `... 0.1s done`.
2019-11-19 10:02:03 -08:00
Rumpu-Jussi
f3629ebd09
Buildkit-based output processed a bit differently. 2019-11-19 10:02:03 -08:00
Juha Ruotsalainen
8041d0ae78
Build quietly and capture the image hash
At least on macOS combo Catalina + Docker engine 19.03.4 + Docker desktop 2.1.0.4 + vagrant 2.2.6 the original `matches = result.scan(/Successfully built (.+)$/i)` -line fails to generate a match. With this change I can `vagrant up --provider=docker` successfully.
2019-11-19 10:02:03 -08:00
Dan Čermák
435a32684f
Only return interfaces where addr is not nil
tunnel interfaces on Linux have addr set to nil which makes the function
list_interfaces fail with a backtrace.
2019-10-10 10:49:03 -07:00
Brian Cain
e6d47329ee
Add note about removing prefix workaround 2019-10-09 16:07:21 -07:00
Brian Cain
8458a21657
Determine prefix with netmask 2019-10-09 15:40:36 -07:00
Brian Cain
62b7e35169
Fixes #11094: Determine prefix for docker public networks
Prior to this commit, the docker action was using the method `prefix` on
an IPv4 and IPv6 address. This works fine for ruby versions 2.5 and
newer, however the ruby shipped with Vagrant is before 2.5, and
therefore the IPv4 and IPv6 classes do not have the prefix method,
resulting in an error. This commit fixes that by using a different
method of determining the prefix.
2019-10-09 09:56:59 -07:00
Brian Cain
f1ea4eaac0
Ensure build_args are passed into docker compose config file
Prior to this commit, the docker compose build method would not properly
set build_args if given in a Vagrantfile. This commit fixes that by
using the passed in key `extra_args` from the docker build action.
2019-10-07 12:48:59 -07:00
Anders Kaseorg
5b4dcf9443
providers/docker: Fix usability check
In commit 7980178d194bb21bde2e21858fbc969e4cc7eb3f (#10879) I added a
`usable?` class method to `VagrantPlugins::DockerProvider::Provider`.
However, commit 34e53a5a4b208edcc3e25c1f0e3aa0ef56e8d8d9 (#10890)
incorrectly changed it to an instance method.  This rendered it
ineffective because it’s called on the class, not an instance.  Change
it back to a class method.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
2019-09-10 15:10:43 -07:00
Brian Cain
09af983caa
Fixes #11051: Only use host vm if specified
Prior to this commit, the docker login action assumed that if there was
a password to authenticate with, Vagrant was using a host vm to run
docker. This is likely due to some legacy decisions with how Vagrant
used to manage running docker. This commit fixes that by only grabbing a
host_vm lock if the host_vm is actually in use, otherwise login
normally.
2019-09-05 14:54:40 -07:00
Brian Cain
fb80e8da9f
Merge pull request #10890 from briancain/add-usability-check-for-docker-plus-tests
Add usability check for docker plus tests
2019-06-05 07:58:23 -07:00
Brian Cain
34e53a5a4b
Add docker provider class test
This commit introduces aa provider_test class for the Docker provider
2019-06-04 13:24:07 -07:00
Anders Kaseorg
7980178d19 providers/docker: Add usability test
Signed-off-by: Anders Kaseorg <andersk@mit.edu>
2019-05-30 13:13:43 -07:00
Brian Cain
ca0fd64ded
Fixes #10798: Enhance how docker compose driver path expands
Prior to this commit, the docker compose driver would _always_ path
expand a host volume no matter what. This is not always the correct
option, for example if that host volume is actually a reference to a key
inside a `volumes` hash instead of a path on disk. This commit changes
that by looking to see if the requested host volume is actually a
defined key inside the compose config, and if not, it will path expand
it like before. Otherwise it will leave the key "as is".
2019-04-29 16:14:37 -07:00
Brian Cain
4f80a9e6d5
Add test for requesting public ip range for docker network provider 2019-03-22 09:02:40 -07:00
Brian Cain
6bffdca972
Add beginning of connect network tests for docker provider 2019-03-21 16:06:24 -07:00
Brian Cain
88a18fe2c5
Add public network tests for docker provider 2019-03-21 16:06:11 -07:00
Brian Cain
82700d95b3
Ensure subnet is used if specified from user config options 2019-03-21 15:29:04 -07:00
Brian Cain
8c169714c5
Ensure variable names exist in method 2019-03-21 11:39:16 -07:00
Brian Cain
96a19aa00c
Fix how options to cli args are handled
Since options could also be defined as strings, convert it all to string
and compare those instead
2019-03-21 11:15:41 -07:00
Brian Cain
5215354d16
Fix missing docker error classes, and finish out initial #call tests 2019-03-21 10:50:45 -07:00
Brian Cain
1027636e41
Split up and rename unit tests for docker network operations 2019-03-20 15:14:39 -07:00
Brian Cain
eb75431c4a
Update docker driver and docker driver unit tests 2019-03-20 14:50:28 -07:00
Chris Roberts
623a1815ae Allow use of subnet option when defining private network with dhcp type 2019-03-19 14:35:40 -07:00
Chris Roberts
670bef6596 Allow custom subnet to be provided when private network type is dhcp 2019-03-19 14:20:14 -07:00
Chris Roberts
afb6c20581 Fix option mask to be expected netmask 2019-03-19 14:03:03 -07:00
Chris Roberts
a1c7eec441 Include synchronization as the environment lock is per process only 2019-03-19 13:46:14 -07:00
Chris Roberts
a645ce3c25 Docker provider networking support updates
Use `mask` option for defining subnet on network configuration. Allow
options to be passed through using hash scoping and docker_network and
docker_connect prefixes. Enable public networks. Allow configuration
to define pre-existing networks by name.
2019-03-19 11:44:33 -07:00
Chris Roberts
1224622387 Remove container inspection caching and Exception rescue
Container inspection is caching data on first lookup. This will
result in incorrect data being returned on subsequent lookups if
a different `cid` value is provided. Also removed rescue of
the `Exception` class as this generally should never happen; rescue
of StandardError will be enough.
2019-03-19 11:44:22 -07:00
Chris Roberts
c251e090b3 Remove Mutex for synchronization. Environment#lock satisfies requirement. 2019-03-19 11:44:02 -07:00
Brian Cain
6664936c0b
Make ignored vagrant network options a constant 2019-03-12 10:40:58 -07:00
Brian Cain
5ed5868067
Inspect networks before creating new ones
This commit updates the behavior of how the docker provider creates new
docker networks. It looks at each existing network to see if the
requested subnet has already been configured in the docker engine. If
so, Vagrant will use that network rather than creating a new one. This
includes networks not created by Vagrant. Vagrant will not clean up
these networks if created outside of Vagrant.
2019-03-12 10:36:57 -07:00