Docker API client version bumped to 1.24 everywhere

This commit is contained in:
Raj Chaudhuri committed 2024-03-07 19:27:12 +05:30
1 parent 55a46992d4
commit e50040883f
12 files changed
+118 -27

No files matched your search

+1 -1
View File
@@ -14,7 +14,7 @@ func containerAddrs(args []string) error {
}
bridgeName := args[0]
client, err := docker.NewVersionedClientFromEnv("1.18")
client, err := newVersionedDockerClientFromEnv(defaulDockerAPIVersion)
if err != nil {
return err
}
+6 -6
View File
@@ -9,7 +9,7 @@ import (
)
func inspectContainer(containerNameOrID string) (*docker.Container, error) {
c, err := docker.NewVersionedClientFromEnv("1.18")
c, err := newVersionedDockerClientFromEnv(defaulDockerAPIVersion)
if err != nil {
return nil, fmt.Errorf("unable to connect to docker: %s", err)
}
@@ -174,7 +174,7 @@ func parseContainerArgs(args []string) docker.CreateContainerOptions {
func runContainer(args []string) error {
containerOptions := parseContainerArgs(args)
c, err := docker.NewVersionedClientFromEnv("1.18")
c, err := newVersionedDockerClientFromEnv(defaulDockerAPIVersion)
if err != nil {
return fmt.Errorf("unable to connect to docker: %s", err)
}
@@ -206,7 +206,7 @@ func listContainers(args []string) error {
cmdUsage("list-containers", "[<label>]")
}
c, err := docker.NewVersionedClientFromEnv("1.18")
c, err := newVersionedDockerClientFromEnv(defaulDockerAPIVersion)
if err != nil {
return fmt.Errorf("unable to connect to docker: %s", err)
}
@@ -233,7 +233,7 @@ func stopContainer(args []string) error {
cmdUsage("stop-container", "<container-id> [<container-id2> ...]")
}
c, err := docker.NewVersionedClientFromEnv("1.18")
c, err := newVersionedDockerClientFromEnv(defaulDockerAPIVersion)
if err != nil {
return fmt.Errorf("unable to connect to docker: %s", err)
}
@@ -252,7 +252,7 @@ func killContainer(args []string) error {
cmdUsage("kill-container", "<container-id> [<container-id2> ...]")
}
c, err := docker.NewVersionedClientFromEnv("1.18")
c, err := newVersionedDockerClientFromEnv(defaulDockerAPIVersion)
if err != nil {
return fmt.Errorf("unable to connect to docker: %s", err)
}
@@ -288,7 +288,7 @@ func removeContainer(args []string) error {
}
}
c, err := docker.NewVersionedClientFromEnv("1.18")
c, err := newVersionedDockerClientFromEnv(defaulDockerAPIVersion)
if err != nil {
return fmt.Errorf("unable to connect to docker: %s", err)
}
+23
View File
@@ -0,0 +1,23 @@
package main
import (
"os"
docker "github.com/fsouza/go-dockerclient"
)
const defaulDockerAPIVersion = "1.24"
const swarmDockerAPIVersion = "1.26"
// newVersionedDockerClientFromEnv offers some control over the version
// of the docker client weaveutil uses for a number of operations.
// The version specified by the caller, usually defaulDockerAPIVersion,
// may be overridden by setting an environment variable called
// DOCKER_API_VERSION.
func newVersionedDockerClientFromEnv(apiVersionString string) (*docker.Client, error) {
overridenAPIVersion, ok := os.LookupEnv("DOCKER_API_VERSION")
if ok && overridenAPIVersion != "" {
apiVersionString = overridenAPIVersion
}
return docker.NewVersionedClientFromEnv(apiVersionString)
}
+2
View File
@@ -90,6 +90,8 @@ func usage() {
for cmd := range commands {
fmt.Fprintln(os.Stderr, cmd)
}
fmt.Fprintln(os.Stderr)
fmt.Fprintf(os.Stderr, "Set an environment variable called DOCKER_API_VERSION to control the API version used.\nDefault is: %v\n", defaulDockerAPIVersion)
}
func cmdUsage(cmd string, usage string) {
+3 -3
View File
@@ -75,9 +75,9 @@ func isDockerPluginEnabled(args []string) error {
}
func newDockerClient() (*docker.Client, error) {
// API 1.21 is the first version that supports docker network
// commands
c, err := docker.NewVersionedClientFromEnv("1.21")
// API 1.21 was the first version that supports docker network
// commands. In March 2024, the minimum suupported API is 1.24
c, err := newVersionedDockerClientFromEnv(defaulDockerAPIVersion)
if err != nil {
return nil, fmt.Errorf("unable to connect to docker: %s", err)
}
+2 -4
View File
@@ -4,12 +4,10 @@ import (
"fmt"
"strings"
"github.com/fsouza/go-dockerclient"
docker "github.com/fsouza/go-dockerclient"
"github.com/pkg/errors"
)
const DOCKER_API_VERSION = "1.26"
func swarmManagerPeers(args []string) error {
info, err := dockerInfo()
if err != nil {
@@ -32,7 +30,7 @@ func swarmManagerPeers(args []string) error {
}
func dockerInfo() (*docker.DockerInfo, error) {
client, err := docker.NewVersionedClientFromEnv(DOCKER_API_VERSION)
client, err := newVersionedDockerClientFromEnv(swarmDockerAPIVersion)
if err != nil {
return nil, errors.Wrap(err, "docker.NewVersionedClientFromEnv")
}
+1 -1
View File
@@ -15,7 +15,7 @@ func createVolumeContainer(args []string) error {
label := args[2]
bindMounts := args[3:]
c, err := docker.NewVersionedClientFromEnv("1.18")
c, err := newVersionedDockerClientFromEnv(defaulDockerAPIVersion)
if err != nil {
return fmt.Errorf("unable to connect to docker: %s", err)
}
+16 -1
View File
@@ -2,7 +2,10 @@ package proxy
import (
"net/http"
"slices"
"strings"
docker "github.com/fsouza/go-dockerclient"
)
type createExecInterceptor struct{ proxy *Proxy }
@@ -18,7 +21,19 @@ func (i *createExecInterceptor) InterceptRequest(r *http.Request) error {
return err
}
if _, hasWeaveWait := container.Volumes["/w"]; !hasWeaveWait {
// The .Volumes property seems to have been replaced with .Mounts in Docker
// API 1.20.
// .Volumes was a list, where the key was the mount path or destination
// .Mounts is an array of objects, where the .Destination property
// corresponds to the old .Volumes list key.
//
// if _, hasWeaveWait := container.Volumes["/w"]; !hasWeaveWait {
// return nil
// }
mountIndex := slices.IndexFunc(container.Mounts, func(m docker.Mount) bool {
return m.Destination == "/w"
})
if mountIndex == -1 {
return nil
}
+42 -6
View File
@@ -9,6 +9,7 @@ import (
"os"
"path/filepath"
"regexp"
"slices"
"strings"
"sync"
"syscall"
@@ -125,6 +126,16 @@ func (j attachJob) Stop() {
j.timer.Stop()
}
const defaulDockerAPIVersion = "1.24"
func dockerAPIVersion() string {
overridenAPIVersion, ok := os.LookupEnv("DOCKER_API_VERSION")
if ok && overridenAPIVersion != "" {
return overridenAPIVersion
}
return defaulDockerAPIVersion
}
func StubProxy(c Config) (*Proxy, error) {
p := &Proxy{
Config: c,
@@ -139,7 +150,14 @@ func StubProxy(c Config) (*Proxy, error) {
// to insulate ourselves from breaking changes to the API, as
// happened in 1.20 (Docker 1.8.0) when the presentation of
// volumes changed in `inspect`.
client, err := weavedocker.NewVersionedClient(c.DockerHost, "1.18")
// Updated in March 2024: We can't do that any more. Protocol
// version has to be updated to minimum 1.24.
// The presentation of volumes aspect has been handled later in
// this file. There may be other breaking changes if we change
// the protocol again, so will wait and watch.
// The default, 1.24, can be overridden using an environment
// variable called DOCKER_API_VERSION.
client, err := weavedocker.NewVersionedClient(c.DockerHost, dockerAPIVersion())
if err != nil {
return nil, err
}
@@ -212,15 +230,33 @@ func (proxy *Proxy) findVolume(v string) (string, error) {
return "", fmt.Errorf("Could not find the weavewait volume: %s", err)
}
if container.Volumes == nil {
return "", fmt.Errorf("Could not find the weavewait volume")
// The .Volumes property seems to have been replaced with .Mounts in Docker
// API 1.20.
// .Volumes was a list, where the key was the mount path or destination
// .Mounts is an array of objects, where the .Destination property
// corresponds to the old .Volumes list key.
//
// if container.Volumes == nil {
// return "", fmt.Errorf("Could not find the weavewait volume - no volumes : %+v", container)
// }
//
// volume, ok := container.Volumes[v]
// if !ok {
// return "", fmt.Errorf("Could not find the weavewait volume named '%v' : %+v", v, container)
// }
mounts := container.Mounts
if mounts == nil {
return "", fmt.Errorf("Could not find the weavewait volume - no volumes : %+v", container)
}
volume, ok := container.Volumes[v]
if !ok {
return "", fmt.Errorf("Could not find the weavewait volume")
mountIndex := slices.IndexFunc(mounts, func(m docker.Mount) bool {
return m.Destination == v
})
if mountIndex < 0 {
return "", fmt.Errorf("Could not find the weavewait volume named '%v' : %+v", v, container)
}
volume := container.Mounts[mountIndex].Name
return volume, nil
}
+16 -1
View File
@@ -2,7 +2,22 @@
All changes made to the weave net codebase during the reweave effort will be documented in this file.
## 2.8.2 latest
## latest
### Changed
* The docker API client version, used by the proxy package and the weaveutil command, was bumped from 1.18 to 1.24. As of March 2024, Docker API versions below 1.24 are deprecated. This means that the minimum supported Docker version is now 1.12.0
### Added
* Provision was made in weaveutil program and the weave script to override the API version used, via the environment variable `DOCKER_API_VERSION`. The same variable is used by standard docker clients
### Fixed
* Fixed `proxy.go` in the proxy package to handle changes in the Docker API. In the 1.24 API, container objects expose a `.Mounts` property rather than a `.Volumes` property.
* The `weave` script was modified to add a `-t` switch when invoking functionality inside a container. This ensures that output is visible even when using the Weave docker proxy
## 2.8.2 (7b087168)
### Changed
+1 -1
View File
@@ -1,4 +1,4 @@
IMAGE_VERSION ?= 2.8.2
IMAGE_VERSION ?= 2.8.3-beta1
REGISTRY_USER ?= rajchaudhuri
ALPINE_BASEIMAGE ?= alpine:3.19.1
+5 -3
View File
@@ -9,10 +9,10 @@ IMAGE_VERSION=latest
IMAGE_VERSION=${WEAVE_VERSION:-$IMAGE_VERSION}
# Minimum tested version of Docker + Weave Net
MIN_DOCKER_VERSION=1.10.0
MIN_DOCKER_VERSION=1.12.0
# These are needed for remote execs, hence we introduce them here
DOCKERHUB_USER=${DOCKERHUB_USER:-weaveworks}
DOCKERHUB_USER=${DOCKERHUB_USER:-rajchaudhuri}
BASE_EXEC_IMAGE=$DOCKERHUB_USER/weaveexec
EXEC_IMAGE=$BASE_EXEC_IMAGE:$IMAGE_VERSION
WEAVEDB_IMAGE=$DOCKERHUB_USER/weavedb:latest
@@ -95,8 +95,8 @@ where <peer> = <ip_address_or_fqdn>[:<port>]
<peer_id> = <nickname> | <weave internal peer ID>
<mode> = consensus[=<count>] | seed=<mac>,... | observer
To troubleshoot and visualize Weave networks, try Weave Cloud: http://www.weave.works/product/cloud/
EOF
# To troubleshoot and visualize Weave networks, try Weave : http://www.weave.works/product/cloud/
}
usage() {
@@ -155,6 +155,8 @@ exec_remote() {
-e COVERAGE \
-e CHECKPOINT_DISABLE \
-e AWSVPC \
-e DOCKER_API_VERSION \
-t \
$WEAVEEXEC_DOCKER_ARGS $EXEC_IMAGE --local "$@"
}