diff --git a/.ci/get-docker-com.sh b/.ci/get-docker-com.sh deleted file mode 100755 index d9c0142a21..0000000000 --- a/.ci/get-docker-com.sh +++ /dev/null @@ -1,313 +0,0 @@ -#!/bin/sh -set -e -# -# This script is meant for quick & easy install via: -# 'curl -sSL https://get.docker.com/ | sh' -# or: -# 'wget -qO- https://get.docker.com/ | sh' -# -# For test builds (ie. release candidates): -# 'curl -fsSL https://test.docker.com/ | sh' -# or: -# 'wget -qO- https://test.docker.com/ | sh' -# -# For experimental builds: -# 'curl -fsSL https://experimental.docker.com/ | sh' -# or: -# 'wget -qO- https://experimental.docker.com/ | sh' -# -# Docker Maintainers: -# To update this script on https://get.docker.com, -# use hack/release.sh during a normal release, -# or the following one-liner for script hotfixes: -# aws s3 cp --acl public-read hack/install.sh s3://get.docker.com/index -# - -url="https://get.docker.com/" -apt_url="https://apt.dockerproject.org" -yum_url="https://yum.dockerproject.org" -gpg_fingerprint="58118E89F3A912897C070ADBF76221572C52609D" - -key_servers=" -ha.pool.sks-keyservers.net -pgp.mit.edu -keyserver.ubuntu.com -" - -command_exists() { - command -v "$@" > /dev/null 2>&1 -} - -semverParse() { - major="${1%%.*}" - minor="${1#$major.}" - minor="${minor%%.*}" - patch="${1#$major.$minor.}" - patch="${patch%%[-.]*}" -} - -do_install() { - case "$(uname -m)" in - *64) - ;; - *) - cat >&2 <<-'EOF' - Error: you are not using a 64bit platform. - Docker currently only supports 64bit platforms. - EOF - exit 1 - ;; - esac - - user="$(id -un 2>/dev/null || true)" - - sh_c='sh -c' - if [ "$user" != 'root' ]; then - if command_exists sudo; then - sh_c='sudo -E sh -c' - elif command_exists su; then - sh_c='su -c' - else - cat >&2 <<-'EOF' - Error: this installer needs the ability to run commands as root. - We are unable to find either "sudo" or "su" available to make this happen. - EOF - exit 1 - fi - fi - - curl='' - if command_exists curl; then - curl='curl -sSL' - elif command_exists wget; then - curl='wget -qO-' - elif command_exists busybox && busybox --list-modules | grep -q wget; then - curl='busybox wget -qO-' - fi - - # check to see which repo they are trying to install from - if [ -z "$repo" ]; then - repo='main' - if [ "https://test.docker.com/" = "$url" ]; then - repo='testing' - elif [ "https://experimental.docker.com/" = "$url" ]; then - repo='experimental' - fi - fi - - # perform some very rudimentary platform detection - lsb_dist='' - dist_version='' - if command_exists lsb_release; then - lsb_dist="$(lsb_release -si)" - fi - if [ -z "$lsb_dist" ] && [ -r /etc/lsb-release ]; then - lsb_dist="$(. /etc/lsb-release && echo "$DISTRIB_ID")" - fi - if [ -z "$lsb_dist" ] && [ -r /etc/debian_version ]; then - lsb_dist='debian' - fi - if [ -z "$lsb_dist" ] && [ -r /etc/fedora-release ]; then - lsb_dist='fedora' - fi - if [ -z "$lsb_dist" ] && [ -r /etc/oracle-release ]; then - lsb_dist='oracleserver' - fi - if [ -z "$lsb_dist" ]; then - if [ -r /etc/centos-release ] || [ -r /etc/redhat-release ]; then - lsb_dist='centos' - fi - fi - if [ -z "$lsb_dist" ] && [ -r /etc/os-release ]; then - lsb_dist="$(. /etc/os-release && echo "$ID")" - fi - - lsb_dist="$(echo "$lsb_dist" | tr '[:upper:]' '[:lower:]')" - - case "$lsb_dist" in - - ubuntu) - if command_exists lsb_release; then - dist_version="$(lsb_release --codename | cut -f2)" - fi - if [ -z "$dist_version" ] && [ -r /etc/lsb-release ]; then - dist_version="$(. /etc/lsb-release && echo "$DISTRIB_CODENAME")" - fi - ;; - - debian) - dist_version="$(cat /etc/debian_version | sed 's/\/.*//' | sed 's/\..*//')" - case "$dist_version" in - 8) - dist_version="jessie" - ;; - 7) - dist_version="wheezy" - ;; - esac - ;; - - oracleserver) - # need to switch lsb_dist to match yum repo URL - lsb_dist="oraclelinux" - dist_version="$(rpm -q --whatprovides redhat-release --queryformat "%{VERSION}\n" | sed 's/\/.*//' | sed 's/\..*//' | sed 's/Server*//')" - ;; - - fedora|centos) - dist_version="$(rpm -q --whatprovides redhat-release --queryformat "%{VERSION}\n" | sed 's/\/.*//' | sed 's/\..*//' | sed 's/Server*//')" - ;; - - *) - if command_exists lsb_release; then - dist_version="$(lsb_release --codename | cut -f2)" - fi - if [ -z "$dist_version" ] && [ -r /etc/os-release ]; then - dist_version="$(. /etc/os-release && echo "$VERSION_ID")" - fi - ;; - - - esac - - - # Run setup for each distro accordingly - case "$lsb_dist" in - ubuntu|debian) - export DEBIAN_FRONTEND=noninteractive - - did_apt_get_update= - apt_get_update() { - if [ -z "$did_apt_get_update" ]; then - ( set -x; $sh_c 'sleep 3; apt-get update' ) - did_apt_get_update=1 - fi - } - - # aufs is preferred over devicemapper; try to ensure the driver is available. - if ! grep -q aufs /proc/filesystems && ! $sh_c 'modprobe aufs'; then - if uname -r | grep -q -- '-generic' && dpkg -l 'linux-image-*-generic' | grep -qE '^ii|^hi' 2>/dev/null; then - kern_extras="linux-image-extra-$(uname -r) linux-image-extra-virtual" - - apt_get_update - ( set -x; $sh_c 'sleep 3; apt-get install -y -q '"$kern_extras" ) || true - - if ! grep -q aufs /proc/filesystems && ! $sh_c 'modprobe aufs'; then - echo >&2 'Warning: tried to install '"$kern_extras"' (for AUFS)' - echo >&2 ' but we still have no AUFS. Docker may not work. Proceeding anyways!' - ( set -x; sleep 10 ) - fi - else - echo >&2 'Warning: current kernel is not supported by the linux-image-extra-virtual' - echo >&2 ' package. We have no AUFS support. Consider installing the packages' - echo >&2 ' linux-image-virtual kernel and linux-image-extra-virtual for AUFS support.' - ( set -x; sleep 10 ) - fi - fi - - # install apparmor utils if they're missing and apparmor is enabled in the kernel - # otherwise Docker will fail to start - if [ "$(cat /sys/module/apparmor/parameters/enabled 2>/dev/null)" = 'Y' ]; then - if command -v apparmor_parser >/dev/null 2>&1; then - echo 'apparmor is enabled in the kernel and apparmor utils were already installed' - else - echo 'apparmor is enabled in the kernel, but apparmor_parser missing' - apt_get_update - ( set -x; $sh_c 'sleep 3; apt-get install -y -q apparmor' ) - fi - fi - - if [ ! -e /usr/lib/apt/methods/https ]; then - apt_get_update - ( set -x; $sh_c 'sleep 3; apt-get install -y -q apt-transport-https ca-certificates' ) - fi - if [ -z "$curl" ]; then - apt_get_update - ( set -x; $sh_c 'sleep 3; apt-get install -y -q curl ca-certificates' ) - curl='curl -sSL' - fi - ( - set -x - for key_server in $key_servers ; do - $sh_c "apt-key adv --keyserver hkp://${key_server}:80 --recv-keys ${gpg_fingerprint}" && break - done - $sh_c "apt-key adv -k ${gpg_fingerprint} >/dev/null" - $sh_c "mkdir -p /etc/apt/sources.list.d" - $sh_c "echo deb [arch=$(dpkg --print-architecture)] ${apt_url}/repo ${lsb_dist}-${dist_version} ${repo} > /etc/apt/sources.list.d/docker.list" - $sh_c 'sleep 3; apt-get update' - if [ -z "$DOCKER_VERSION" ]; then - $sh_c 'apt-get -o Dpkg::Options::="--force-confnew" install -y -q docker-engine' - else - $sh_c "apt-get -o Dpkg::Options::=\"--force-confnew\" install -y -q docker-engine=$DOCKER_VERSION" - fi - ) - exit 0 - ;; - - fedora|centos|oraclelinux) - $sh_c "cat >/etc/yum.repos.d/docker-${repo}.repo" <<-EOF - [docker-${repo}-repo] - name=Docker ${repo} Repository - baseurl=${yum_url}/repo/${repo}/${lsb_dist}/${dist_version} - enabled=1 - gpgcheck=1 - gpgkey=${yum_url}/gpg - EOF - if [ "$lsb_dist" = "fedora" ] && [ "$dist_version" -ge "22" ]; then - ( - set -x - $sh_c 'sleep 3; dnf -y -q install docker-engine' - ) - else - ( - set -x - $sh_c 'sleep 3; yum -y -q install docker-engine' - ) - fi - exit 0 - ;; - gentoo) - if [ "$url" = "https://test.docker.com/" ]; then - # intentionally mixed spaces and tabs here -- tabs are stripped by "<<-'EOF'", spaces are kept in the output - cat >&2 <<-'EOF' - - You appear to be trying to install the latest nightly build in Gentoo.' - The portage tree should contain the latest stable release of Docker, but' - if you want something more recent, you can always use the live ebuild' - provided in the "docker" overlay available via layman. For more' - instructions, please see the following URL:' - - https://github.com/tianon/docker-overlay#using-this-overlay' - - After adding the "docker" overlay, you should be able to:' - - emerge -av =app-emulation/docker-9999' - - EOF - exit 1 - fi - - ( - set -x - $sh_c 'sleep 3; emerge app-emulation/docker' - ) - exit 0 - ;; - esac - - # intentionally mixed spaces and tabs here -- tabs are stripped by "<<-'EOF'", spaces are kept in the output - cat >&2 <<-'EOF' - - Either your platform is not easily detectable, is not supported by this - installer script (yet - PRs welcome! [hack/install.sh]), or does not yet have - a package for Docker. Please visit the following URL for more detailed - installation instructions: - - https://docs.docker.com/engine/installation/ - - EOF - exit 1 -} - -# wrapped up in a function so that we have some protection against only getting -# half the file during "curl | sh" -do_install diff --git a/.ci/setup_docker.sh b/.ci/setup_docker.sh deleted file mode 100755 index df9cf205a9..0000000000 --- a/.ci/setup_docker.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/env bash - -set -exu - -DOCKER_VERSION="${DOCKER_VERSION:-}" -DOCKER_HOST="${DOCKER_HOST:-}" - -if [[ -n $DOCKER_VERSION ]]; then - sudo -E apt-get -q -y --purge remove docker-engine docker-ce - - curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - - sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" - sudo apt-get update - sudo apt-cache madison docker-ce - sudo apt-get install "docker-ce=$DOCKER_VERSION" -fi - -if [[ -n $DOCKER_HOST ]]; then - sudo mkdir -p /etc/systemd/system/docker.service.d/ - - echo " -[Service] -ExecStart= -ExecStart=/usr/bin/dockerd -H $DOCKER_HOST -H unix:///var/run/docker.sock - " | sudo tee -a /etc/systemd/system/docker.service.d/override.conf - - sudo systemctl daemon-reload - sudo service docker restart || sudo journalctl -xe - sudo service docker status -fi - -while (! docker ps ); do - echo "Waiting for Docker to launch..." - sleep 1 -done -docker version -docker info - -docker run --rm hello-world diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 7dec19aef0..9bcef2d889 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -4,5 +4,13 @@ updates: directory: "/" schedule: interval: weekly + day: monday open-pull-requests-limit: 99 rebase-strategy: disabled + ignore: + - dependency-name: "org.glassfish.jersey.connectors:jersey-apache-connector" + update-types: [ "version-update:semver-major" ] + - dependency-name: "org.glassfish.jersey.core:jersey-client" + update-types: [ "version-update:semver-major" ] + - dependency-name: "org.glassfish.jersey.inject:jersey-hk2" + update-types: [ "version-update:semver-major" ] diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml index d03b3f5f54..f570cce432 100644 --- a/.github/release-drafter.yml +++ b/.github/release-drafter.yml @@ -1,5 +1,5 @@ tag-template: $NEXT_PATCH_VERSION -name-template: '$NEXT_PATCH_VERSION 🌈' +name-template: '$NEXT_PATCH_VERSION' categories: - title: '🚀 Features' labels: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0335a352e6..d7b105d1de 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,10 +3,11 @@ name: CI on: pull_request: {} push: { branches: [ main ] } + workflow_dispatch: jobs: build: - runs-on: ubuntu-20.04 + runs-on: ubuntu-24.04 strategy: fail-fast: false matrix: @@ -14,9 +15,6 @@ jobs: - { name: "default", javaVersion: 8 } - { name: "default", javaVersion: 17 } - { name: "default", javaVersion: 21 } - - { name: "over TCP", dockerHost: "tcp://127.0.0.1:2375", javaVersion: 8 } - - { name: "Docker 19.03.9", dockerVersion: "5:19.03.9~3-0~ubuntu-focal", javaVersion: 8 } - steps: - uses: actions/checkout@v4 - name: Set up JDK @@ -24,14 +22,34 @@ jobs: with: java-version: ${{matrix.javaVersion}} distribution: temurin + cache: maven - name: Configure Docker + id: setup_docker + uses: docker/setup-docker-action@v4 + with: + channel: stable + - name: Build with Maven env: - DOCKER_VERSION: ${{matrix.dockerVersion}} - DOCKER_HOST: ${{matrix.dockerHost}} - run: .ci/setup_docker.sh + DOCKER_HOST: ${{steps.setup_docker.outputs.sock}} + run: ./mvnw --no-transfer-progress verify + + tcp: + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v4 + - name: Set up JDK + uses: actions/setup-java@v4 + with: + java-version: 8 + distribution: temurin + cache: maven + - name: Configure Docker + id: setup_docker + uses: docker/setup-docker-action@v4 + with: + channel: stable + tcp-port: 2375 - name: Build with Maven env: - DOCKER_HOST: ${{matrix.dockerHost}} - run: | - [[ -z "$DOCKER_HOST" ]] && unset DOCKER_HOST - ./mvnw --no-transfer-progress verify + DOCKER_HOST: ${{steps.setup_docker.outputs.tcp}} + run: ./mvnw --no-transfer-progress verify diff --git a/.github/workflows/main.yml b/.github/workflows/release-drafter.yml similarity index 100% rename from .github/workflows/main.yml rename to .github/workflows/release-drafter.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ec59b2603e..16777daa66 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -8,7 +8,7 @@ on: jobs: build: - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v4 - name: Set up JDK 8 @@ -16,10 +16,17 @@ jobs: with: java-version: 8 distribution: temurin + server-id: central + server-username: MAVEN_USERNAME + server-password: MAVEN_CENTRAL_TOKEN + gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} + gpg-passphrase: MAVEN_GPG_PASSPHRASE - name: Set version run: ./mvnw versions:set -DnewVersion="${{github.event.release.tag_name}}" # TODO check main's CI status - name: Deploy with Maven env: - MAVEN_DEPLOYMENT_REPOSITORY: ${{ secrets.MAVEN_DEPLOYMENT_REPOSITORY }} - run: ./mvnw deploy -DaltReleaseDeploymentRepository="$MAVEN_DEPLOYMENT_REPOSITORY" -DskipTests + MAVEN_USERNAME: ${{ secrets.SONATYPE_CENTRAL_USERNAME }} + MAVEN_CENTRAL_TOKEN: ${{ secrets.SONATYPE_CENTRAL_PASSWORD }} + MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }} + run: ./mvnw -Prelease deploy -DskipTests diff --git a/circle.sh b/circle.sh index c84ca3fe65..b5b7cdbb03 100755 --- a/circle.sh +++ b/circle.sh @@ -6,7 +6,7 @@ case "$1" in mkdir .docker cp $CIRCLE_PROJECT_REPONAME/etc/certs/* .docker - # configure docker deamon to use SSL and provide the path to the certificates + # configure docker daemon to use SSL and provide the path to the certificates docker_opts='DOCKER_OPTS="$DOCKER_OPTS -H tcp://127.0.0.1:2376 --tlsverify --tlscacert='$HOME'/.docker/ca.pem --tlscert='$HOME'/.docker/server-cert.pem --tlskey='$HOME'/.docker/server-key.pem"' sudo sh -c "echo '$docker_opts' >> /etc/default/docker" diff --git a/docker-java-api/pom.xml b/docker-java-api/pom.xml index 82d176e38f..aafe5cde04 100644 --- a/docker-java-api/pom.xml +++ b/docker-java-api/pom.xml @@ -42,7 +42,7 @@ org.projectlombok lombok - 1.18.30 + 1.18.38 provided @@ -50,14 +50,14 @@ org.junit.jupiter junit-jupiter - 5.10.0 + 5.13.4 test com.tngtech.archunit archunit-junit5 - 0.18.0 + 1.4.1 test @@ -84,6 +84,18 @@ com.github.siom79.japicmp japicmp-maven-plugin + + + + com.github.dockerjava.api.command.UpdateContainerCmd#getCpuPeriod() + com.github.dockerjava.api.command.UpdateContainerCmd#withCpuPeriod(java.lang.Integer) + com.github.dockerjava.api.command.UpdateContainerCmd#getCpuQuota() + com.github.dockerjava.api.command.UpdateContainerCmd#withCpuQuota(java.lang.Integer) + com.github.dockerjava.api.command.InspectContainerResponse#getSizeRootFs() + com.github.dockerjava.api.command.InspectContainerResponse#getSizeRw() + + + diff --git a/docker-java-api/src/main/java/com/github/dockerjava/api/command/InspectContainerResponse.java b/docker-java-api/src/main/java/com/github/dockerjava/api/command/InspectContainerResponse.java index 94207fd2ca..f06bd4ed94 100644 --- a/docker-java-api/src/main/java/com/github/dockerjava/api/command/InspectContainerResponse.java +++ b/docker-java-api/src/main/java/com/github/dockerjava/api/command/InspectContainerResponse.java @@ -61,10 +61,10 @@ public class InspectContainerResponse extends DockerObject { private String id; @JsonProperty("SizeRootFs") - private Integer sizeRootFs; + private Long sizeRootFs; @JsonProperty("SizeRw") - private Integer sizeRw; + private Long sizeRw; @JsonProperty("Image") private String imageId; @@ -124,11 +124,11 @@ public String getId() { return id; } - public Integer getSizeRootFs() { + public Long getSizeRootFs() { return sizeRootFs; } - public Integer getSizeRw() { + public Long getSizeRw() { return sizeRw; } diff --git a/docker-java-api/src/main/java/com/github/dockerjava/api/command/UpdateContainerCmd.java b/docker-java-api/src/main/java/com/github/dockerjava/api/command/UpdateContainerCmd.java index 82fbca5f86..d53bcdcdfc 100644 --- a/docker-java-api/src/main/java/com/github/dockerjava/api/command/UpdateContainerCmd.java +++ b/docker-java-api/src/main/java/com/github/dockerjava/api/command/UpdateContainerCmd.java @@ -1,9 +1,16 @@ package com.github.dockerjava.api.command; +import com.github.dockerjava.api.model.BlkioRateDevice; +import com.github.dockerjava.api.model.BlkioWeightDevice; +import com.github.dockerjava.api.model.Device; +import com.github.dockerjava.api.model.DeviceRequest; +import com.github.dockerjava.api.model.RestartPolicy; +import com.github.dockerjava.api.model.Ulimit; import com.github.dockerjava.api.model.UpdateContainerResponse; import javax.annotation.CheckForNull; import javax.annotation.Nonnull; +import java.util.List; /** * @author Kanstantsin Shautsou @@ -13,22 +20,47 @@ public interface UpdateContainerCmd extends SyncDockerCmd getBlkioWeightDevice(); + + UpdateContainerCmd withBlkioWeightDevice(List blkioWeightDevice); @CheckForNull - Integer getCpuPeriod(); + List getBlkioDeviceReadBps(); - UpdateContainerCmd withCpuPeriod(Integer cpuPeriod); + UpdateContainerCmd withBlkioDeviceReadBps(List blkioDeviceReadBps); @CheckForNull - Integer getCpuQuota(); + List getBlkioDeviceWriteBps(); - UpdateContainerCmd withCpuQuota(Integer cpuQuota); + UpdateContainerCmd withBlkioDeviceWriteBps(List blkioDeviceWriteBps); + + @CheckForNull + List getBlkioDeviceReadIOps(); + + UpdateContainerCmd withBlkioDeviceReadIOps(List blkioDeviceReadIOps); + + @CheckForNull + List getBlkioDeviceWriteIOps(); + + UpdateContainerCmd withBlkioDeviceWriteIOps(List blkioDeviceWriteIOps); + + @CheckForNull + Long getCpuPeriod(); + + UpdateContainerCmd withCpuPeriod(Long cpuPeriod); + + @CheckForNull + Long getCpuQuota(); + + UpdateContainerCmd withCpuQuota(Long cpuQuota); @CheckForNull String getCpusetCpus(); @@ -45,6 +77,31 @@ public interface UpdateContainerCmd extends SyncDockerCmd getDevices(); + + UpdateContainerCmd withDevices(List devices); + + @CheckForNull + List getDeviceCgroupRules(); + + UpdateContainerCmd withDeviceCgroupRules(List deviceCgroupRules); + + @CheckForNull + List getDeviceRequests(); + + UpdateContainerCmd withDeviceRequests(List deviceRequests); + @CheckForNull Long getKernelMemory(); @@ -65,6 +122,36 @@ public interface UpdateContainerCmd extends SyncDockerCmd getUlimits(); + + UpdateContainerCmd withUlimits(List ulimits); + + @CheckForNull + RestartPolicy getRestartPolicy(); + + UpdateContainerCmd withRestartPolicy(RestartPolicy restartPolicy); + interface Exec extends DockerCmdSyncExec { } } diff --git a/docker-java-api/src/main/java/com/github/dockerjava/api/command/WaitContainerCmd.java b/docker-java-api/src/main/java/com/github/dockerjava/api/command/WaitContainerCmd.java index 3117cf7e4c..7b910cd699 100644 --- a/docker-java-api/src/main/java/com/github/dockerjava/api/command/WaitContainerCmd.java +++ b/docker-java-api/src/main/java/com/github/dockerjava/api/command/WaitContainerCmd.java @@ -2,9 +2,11 @@ import javax.annotation.CheckForNull; import javax.annotation.Nonnull; +import javax.annotation.Nullable; import com.github.dockerjava.api.async.ResultCallback; import com.github.dockerjava.api.exception.NotFoundException; +import com.github.dockerjava.api.model.WaitContainerCondition; import com.github.dockerjava.api.model.WaitResponse; /** @@ -20,8 +22,20 @@ public interface WaitContainerCmd extends AsyncDockerCmd> T exec(T resultCallback); diff --git a/docker-java-api/src/main/java/com/github/dockerjava/api/model/Capability.java b/docker-java-api/src/main/java/com/github/dockerjava/api/model/Capability.java index fe71864c0f..57fb97c7b7 100644 --- a/docker-java-api/src/main/java/com/github/dockerjava/api/model/Capability.java +++ b/docker-java-api/src/main/java/com/github/dockerjava/api/model/Capability.java @@ -1,5 +1,7 @@ package com.github.dockerjava.api.model; +import com.fasterxml.jackson.annotation.JsonCreator; + /** * The Linux capabilities supported by Docker. The list of capabilities is defined in Docker's types.go, {@link #ALL} was added manually. * @@ -299,5 +301,11 @@ public enum Capability { /** * Trigger something that will wake up the system (set CLOCK_REALTIME_ALARM and CLOCK_BOOTTIME_ALARM timers). */ - WAKE_ALARM + WAKE_ALARM; + + @JsonCreator + public static Capability fromValue(String cap) { + String result = !cap.startsWith("CAP_") ? cap : cap.split("_", 2)[1]; + return Capability.valueOf(result); + } } diff --git a/docker-java-api/src/main/java/com/github/dockerjava/api/model/HostConfig.java b/docker-java-api/src/main/java/com/github/dockerjava/api/model/HostConfig.java index 2ad622ca6f..603bc63479 100644 --- a/docker-java-api/src/main/java/com/github/dockerjava/api/model/HostConfig.java +++ b/docker-java-api/src/main/java/com/github/dockerjava/api/model/HostConfig.java @@ -73,6 +73,9 @@ public static HostConfig newHostConfig() { @JsonProperty("NanoCpus") private Long nanoCPUs; + @JsonProperty("Annotations") + private Map annotations; + @JsonProperty("CapAdd") private Capability[] capAdd; @@ -304,6 +307,11 @@ public Integer getBlkioWeight() { return blkioWeight; } + @CheckForNull + public Map getAnnotations() { + return annotations; + } + public Capability[] getCapAdd() { return capAdd; } @@ -636,6 +644,11 @@ public HostConfig withBlkioWeightDevice(List blkioWeightDevic return this; } + public HostConfig withAnnotations(Map annotations) { + this.annotations = annotations; + return this; + } + /** * @see #capAdd */ diff --git a/docker-java-api/src/main/java/com/github/dockerjava/api/model/ImageOptions.java b/docker-java-api/src/main/java/com/github/dockerjava/api/model/ImageOptions.java new file mode 100644 index 0000000000..bc8b89acb4 --- /dev/null +++ b/docker-java-api/src/main/java/com/github/dockerjava/api/model/ImageOptions.java @@ -0,0 +1,27 @@ +package com.github.dockerjava.api.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +import java.io.Serializable; + +/** + * @since {@link RemoteApiVersion#VERSION_1_48} + */ +@EqualsAndHashCode +@ToString +public class ImageOptions extends DockerObject implements Serializable { + private static final long serialVersionUID = 1L; + @JsonProperty("Subpath") + private String subpath; + + public String getSubpath() { + return subpath; + } + + public ImageOptions withSubpath(String subpath) { + this.subpath = subpath; + return this; + } +} diff --git a/docker-java-api/src/main/java/com/github/dockerjava/api/model/Info.java b/docker-java-api/src/main/java/com/github/dockerjava/api/model/Info.java index c436e73918..67348b86b3 100644 --- a/docker-java-api/src/main/java/com/github/dockerjava/api/model/Info.java +++ b/docker-java-api/src/main/java/com/github/dockerjava/api/model/Info.java @@ -97,6 +97,12 @@ public class Info extends DockerObject implements Serializable { @JsonProperty("LoggingDriver") private String loggingDriver; + @JsonProperty("CgroupDriver") + private String cGroupDriver; + + @JsonProperty("CgroupVersion") + private String cGroupVersion; + /** * @since {@link com.github.dockerjava.core.RemoteApiVersion#VERSION_1_20} */ @@ -486,6 +492,22 @@ public String getLoggingDriver() { return loggingDriver; } + /** + * @see #cGroupDriver + */ + @CheckForNull + public String getCGroupDriver() { + return cGroupDriver; + } + + /** + * @see #cGroupVersion + */ + @CheckForNull + public String getCGroupVersion() { + return cGroupVersion; + } + /** * @see #loggingDriver */ @@ -494,6 +516,22 @@ public Info withLoggingDriver(String loggingDriver) { return this; } + /** + * @see #cGroupDriver + */ + public Info withCGroupDriver(String cGroupDriver) { + this.cGroupDriver = cGroupDriver; + return this; + } + + /** + * @see #cGroupVersion + */ + public Info withCGroupVersion(String cGroupVersion) { + this.cGroupVersion = cGroupVersion; + return this; + } + /** * @see #experimentalBuild */ @@ -1070,14 +1108,33 @@ public Info withIsolation(String isolation) { return this; } + /** + * @see #securityOptions + */ public List getSecurityOptions() { return securityOptions; } + /** + * @see #securityOptions + */ + public Info withSecurityOptions(List securityOptions) { + this.securityOptions = securityOptions; + return this; + } + /** * @see #runtimes */ public Map getRuntimes() { return runtimes; } + + /** + * @see #runtimes + */ + public Info withRuntimes(Map runtimes) { + this.runtimes = runtimes; + return this; + } } diff --git a/docker-java-api/src/main/java/com/github/dockerjava/api/model/Mount.java b/docker-java-api/src/main/java/com/github/dockerjava/api/model/Mount.java index 9bfe9b16ef..3f17343c30 100644 --- a/docker-java-api/src/main/java/com/github/dockerjava/api/model/Mount.java +++ b/docker-java-api/src/main/java/com/github/dockerjava/api/model/Mount.java @@ -57,6 +57,12 @@ public class Mount extends DockerObject implements Serializable { @JsonProperty("TmpfsOptions") private TmpfsOptions tmpfsOptions; + /** + * @since 1.48 + */ + @JsonProperty("ImageOptions") + private ImageOptions imageOptions; + /** * @see #type */ @@ -177,4 +183,23 @@ public Mount withTmpfsOptions(TmpfsOptions tmpfsOptions) { } return this; } + + /** + * @see #imageOptions + */ + @CheckForNull + public ImageOptions getImageOptions() { + return imageOptions; + } + + /** + * @see #imageOptions + */ + public Mount withImageOptions(ImageOptions imageOptions) { + this.imageOptions = imageOptions; + if (imageOptions != null) { + this.type = MountType.IMAGE; + } + return this; + } } diff --git a/docker-java-api/src/main/java/com/github/dockerjava/api/model/MountType.java b/docker-java-api/src/main/java/com/github/dockerjava/api/model/MountType.java index 219782a56b..b522c96127 100644 --- a/docker-java-api/src/main/java/com/github/dockerjava/api/model/MountType.java +++ b/docker-java-api/src/main/java/com/github/dockerjava/api/model/MountType.java @@ -18,6 +18,10 @@ public enum MountType { //@since 1.40 @JsonProperty("npipe") - NPIPE + NPIPE, + + //@since 1.48 + @JsonProperty("image") + IMAGE, } diff --git a/docker-java-api/src/main/java/com/github/dockerjava/api/model/WaitContainerCondition.java b/docker-java-api/src/main/java/com/github/dockerjava/api/model/WaitContainerCondition.java new file mode 100644 index 0000000000..8af0efa358 --- /dev/null +++ b/docker-java-api/src/main/java/com/github/dockerjava/api/model/WaitContainerCondition.java @@ -0,0 +1,26 @@ +package com.github.dockerjava.api.model; + +import javax.annotation.Nonnull; + +/** + * Docker Engine API wait conditions (added in v1.30). + * + * @since {@link RemoteApiVersion#VERSION_1_30} + */ +public enum WaitContainerCondition { + NOT_RUNNING("not-running"), + NEXT_EXIT("next-exit"), + REMOVED("removed"); + + @Nonnull + private final String value; + + WaitContainerCondition(@Nonnull String value) { + this.value = value; + } + + @Nonnull + public String getValue() { + return value; + } +} diff --git a/docker-java-core/src/main/java/com/github/dockerjava/core/DefaultDockerClientConfig.java b/docker-java-core/src/main/java/com/github/dockerjava/core/DefaultDockerClientConfig.java index 8011a2a5e2..dad75b3607 100644 --- a/docker-java-core/src/main/java/com/github/dockerjava/core/DefaultDockerClientConfig.java +++ b/docker-java-core/src/main/java/com/github/dockerjava/core/DefaultDockerClientConfig.java @@ -5,6 +5,8 @@ import com.github.dockerjava.api.model.AuthConfigurations; import com.github.dockerjava.core.NameParser.HostnameReposName; import com.github.dockerjava.core.NameParser.ReposTag; + +import java.util.Map.Entry; import java.util.Optional; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.SystemUtils; @@ -128,9 +130,11 @@ private static Properties loadIncludedDockerProperties(Properties systemProperti } private static void replaceProperties(Properties properties, Properties replacements) { - for (Object objectKey : properties.keySet()) { - String key = objectKey.toString(); - properties.setProperty(key, replaceProperties(properties.getProperty(key), replacements)); + for (Entry entry : properties.entrySet()) { + final String key = entry.getKey().toString(); + // no entry.getValue here because it does not have the same semantics as getProperty (defaults handling) + final String value = properties.getProperty(key); + entry.setValue(replaceProperties(value, replacements)); } } diff --git a/docker-java-core/src/main/java/com/github/dockerjava/core/command/UpdateContainerCmdImpl.java b/docker-java-core/src/main/java/com/github/dockerjava/core/command/UpdateContainerCmdImpl.java index 14357ba08a..47ab710eb5 100644 --- a/docker-java-core/src/main/java/com/github/dockerjava/core/command/UpdateContainerCmdImpl.java +++ b/docker-java-core/src/main/java/com/github/dockerjava/core/command/UpdateContainerCmdImpl.java @@ -4,6 +4,12 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.github.dockerjava.api.command.UpdateContainerCmd; import com.github.dockerjava.api.exception.NotFoundException; +import com.github.dockerjava.api.model.BlkioRateDevice; +import com.github.dockerjava.api.model.BlkioWeightDevice; +import com.github.dockerjava.api.model.Device; +import com.github.dockerjava.api.model.DeviceRequest; +import com.github.dockerjava.api.model.RestartPolicy; +import com.github.dockerjava.api.model.Ulimit; import com.github.dockerjava.api.model.UpdateContainerResponse; import com.github.dockerjava.core.RemoteApiVersion; import org.apache.commons.lang3.builder.EqualsBuilder; @@ -12,6 +18,7 @@ import javax.annotation.CheckForNull; import javax.annotation.Nonnull; +import java.util.List; /** * @author Kanstantsin Shautsou @@ -28,14 +35,38 @@ public class UpdateContainerCmdImpl extends AbstrDockerCmd blkioWeightDevice; + + @JsonProperty("BlkioDeviceReadBps") + private List blkioDeviceReadBps; + + @JsonProperty("BlkioDeviceWriteBps") + private List blkioDeviceWriteBps; + + @JsonProperty("BlkioDeviceReadIOps") + private List blkioDeviceReadIOps; + + @JsonProperty("BlkioDeviceWriteIOps") + private List blkioDeviceWriteIOps; + @JsonProperty("CpuShares") private Integer cpuShares; @JsonProperty("CpuPeriod") - private Integer cpuPeriod; + private Long cpuPeriod; @JsonProperty("CpuQuota") - private Integer cpuQuota; + private Long cpuQuota; + + @JsonProperty("CpuRealtimePeriod") + private Long cpuRealtimePeriod; + + @JsonProperty("CpuRealtimeRuntime") + private Long cpuRealtimeRuntime; + + @JsonProperty("NanoCpus") + private Long nanoCPUs; @JsonProperty("CpusetCpus") private String cpusetCpus; @@ -43,6 +74,18 @@ public class UpdateContainerCmdImpl extends AbstrDockerCmd devices; + + @JsonProperty("DeviceCgroupRules") + private List deviceCgroupRules; + + /** + * @since {@link com.github.dockerjava.core.RemoteApiVersion#VERSION_1_40} + */ + @JsonProperty("DeviceRequests") + private List deviceRequests; + @JsonProperty("Memory") private Long memory; @@ -55,11 +98,43 @@ public class UpdateContainerCmdImpl extends AbstrDockerCmd ulimits; + + @JsonProperty("RestartPolicy") + private RestartPolicy restartPolicy; + public UpdateContainerCmdImpl(UpdateContainerCmd.Exec exec, String containerId) { super(exec); withContainerId(containerId); } + /** + * @see #containerId + */ + @CheckForNull + @JsonIgnore + public String getContainerId() { + return containerId; + } + + /** + * @see #containerId + */ + public UpdateContainerCmd withContainerId(@Nonnull String containerId) { + this.containerId = containerId; + return this; + } + /** * @see #blkioWeight */ @@ -77,19 +152,68 @@ public UpdateContainerCmd withBlkioWeight(Integer blkioWeight) { } /** - * @see #containerId + * @see #blkioWeightDevice */ @CheckForNull - @JsonIgnore - public String getContainerId() { - return containerId; + public List getBlkioWeightDevice() { + return blkioWeightDevice; + } + + public UpdateContainerCmd withBlkioWeightDevice(List blkioWeightDevice) { + this.blkioWeightDevice = blkioWeightDevice; + return this; } /** - * @see #containerId + * @see #blkioDeviceReadBps */ - public UpdateContainerCmd withContainerId(@Nonnull String containerId) { - this.containerId = containerId; + @CheckForNull + public List getBlkioDeviceReadBps() { + return blkioDeviceReadBps; + } + + public UpdateContainerCmd withBlkioDeviceReadBps(List blkioDeviceReadBps) { + this.blkioDeviceReadBps = blkioDeviceReadBps; + return this; + } + + /** + * @see #blkioDeviceWriteBps + */ + @CheckForNull + public List getBlkioDeviceWriteBps() { + return blkioDeviceWriteBps; + } + + public UpdateContainerCmd withBlkioDeviceWriteBps(List blkioDeviceWriteBps) { + this.blkioDeviceWriteBps = blkioDeviceWriteBps; + return this; + } + + /** + * @see #blkioDeviceReadIOps + */ + @CheckForNull + public List getBlkioDeviceReadIOps() { + return blkioDeviceReadIOps; + } + + public UpdateContainerCmd withBlkioDeviceReadIOps(List blkioDeviceReadIOps) { + this.blkioDeviceReadIOps = blkioDeviceReadIOps; + return this; + } + + /** + * @see #blkioDeviceWriteIOps + */ + @CheckForNull + public List getBlkioDeviceWriteIOps() { + return blkioDeviceWriteIOps; + } + + @Override + public UpdateContainerCmd withBlkioDeviceWriteIOps(List blkioDeviceWriteIOps) { + this.blkioDeviceWriteIOps = blkioDeviceWriteIOps; return this; } @@ -97,14 +221,14 @@ public UpdateContainerCmd withContainerId(@Nonnull String containerId) { * @see #cpuPeriod */ @CheckForNull - public Integer getCpuPeriod() { + public Long getCpuPeriod() { return cpuPeriod; } /** * @see #cpuPeriod */ - public UpdateContainerCmd withCpuPeriod(Integer cpuPeriod) { + public UpdateContainerCmd withCpuPeriod(Long cpuPeriod) { this.cpuPeriod = cpuPeriod; return this; } @@ -113,14 +237,14 @@ public UpdateContainerCmd withCpuPeriod(Integer cpuPeriod) { * @see #cpuQuota */ @CheckForNull - public Integer getCpuQuota() { + public Long getCpuQuota() { return cpuQuota; } /** * @see #cpuQuota */ - public UpdateContainerCmd withCpuQuota(Integer cpuQuota) { + public UpdateContainerCmd withCpuQuota(Long cpuQuota) { this.cpuQuota = cpuQuota; return this; } @@ -173,6 +297,71 @@ public UpdateContainerCmd withCpuShares(Integer cpuShares) { return this; } + /** + * @see #cpuRealtimePeriod + */ + @CheckForNull + public Long getCpuRealtimePeriod() { + return cpuRealtimePeriod; + } + + public UpdateContainerCmd withCpuRealtimePeriod(Long cpuRealtimePeriod) { + this.cpuRealtimePeriod = cpuRealtimePeriod; + return this; + } + + /** + * @see #cpuRealtimeRuntime + */ + @CheckForNull + public Long getCpuRealtimeRuntime() { + return cpuRealtimeRuntime; + } + + public UpdateContainerCmd withCpuRealtimeRuntime(Long cpuRealtimeRuntime) { + this.cpuRealtimeRuntime = cpuRealtimeRuntime; + return this; + } + + /** + * @see #devices + */ + @CheckForNull + public List getDevices() { + return devices; + } + + public UpdateContainerCmd withDevices(List devices) { + this.devices = devices; + return this; + } + + /** + * @see #deviceCgroupRules + */ + @CheckForNull + public List getDeviceCgroupRules() { + return deviceCgroupRules; + } + + public UpdateContainerCmd withDeviceCgroupRules(List deviceCgroupRules) { + this.deviceCgroupRules = deviceCgroupRules; + return this; + } + + /** + * @see #deviceRequests + */ + @CheckForNull + public List getDeviceRequests() { + return deviceRequests; + } + + public UpdateContainerCmd withDeviceRequests(List deviceRequests) { + this.deviceRequests = deviceRequests; + return this; + } + /** * @see #kernelMemory */ @@ -237,6 +426,84 @@ public UpdateContainerCmd withMemorySwap(Long memorySwap) { return this; } + /** + * @see #nanoCPUs + */ + @CheckForNull + public Long getNanoCPUs() { + return nanoCPUs; + } + + public UpdateContainerCmd withNanoCPUs(Long nanoCPUs) { + this.nanoCPUs = nanoCPUs; + return this; + } + + /** + * @see #oomKillDisable + */ + @CheckForNull + public Boolean getOomKillDisable() { + return oomKillDisable; + } + + public UpdateContainerCmd withOomKillDisable(Boolean oomKillDisable) { + this.oomKillDisable = oomKillDisable; + return this; + } + + /** + * @see #init + */ + @CheckForNull + public Boolean getInit() { + return init; + } + + public UpdateContainerCmd withInit(Boolean init) { + this.init = init; + return this; + } + + /** + * @see #pidsLimit + */ + @CheckForNull + public Long getPidsLimit() { + return pidsLimit; + } + + public UpdateContainerCmd withPidsLimit(Long pidsLimit) { + this.pidsLimit = pidsLimit; + return this; + } + + /** + * @see #ulimits + */ + @CheckForNull + public List getUlimits() { + return ulimits; + } + + public UpdateContainerCmd withUlimits(List ulimits) { + this.ulimits = ulimits; + return this; + } + + /** + * @see #restartPolicy + */ + @CheckForNull + public RestartPolicy getRestartPolicy() { + return restartPolicy; + } + + public UpdateContainerCmd withRestartPolicy(RestartPolicy restartPolicy) { + this.restartPolicy = restartPolicy; + return this; + } + /** * @throws NotFoundException No such container */ diff --git a/docker-java-core/src/main/java/com/github/dockerjava/core/command/WaitContainerCmdImpl.java b/docker-java-core/src/main/java/com/github/dockerjava/core/command/WaitContainerCmdImpl.java index 91b2255bca..b627e2ccde 100644 --- a/docker-java-core/src/main/java/com/github/dockerjava/core/command/WaitContainerCmdImpl.java +++ b/docker-java-core/src/main/java/com/github/dockerjava/core/command/WaitContainerCmdImpl.java @@ -2,7 +2,10 @@ import java.util.Objects; +import javax.annotation.Nullable; + import com.github.dockerjava.api.command.WaitContainerCmd; +import com.github.dockerjava.api.model.WaitContainerCondition; import com.github.dockerjava.api.model.WaitResponse; /** @@ -15,6 +18,8 @@ public class WaitContainerCmdImpl extends AbstrAsyncDockerCmd r WebTarget webTarget = getBaseResource().path("/containers/{id}/wait").resolveTemplate("id", command.getContainerId()); + WaitContainerCondition condition = command.getCondition(); + if (condition != null) { + webTarget = webTarget.queryParam("condition", condition.getValue()); + } + LOGGER.trace("POST: {}", webTarget); webTarget.request().accept(MediaType.APPLICATION_JSON).post((Object) null, new TypeReference() { diff --git a/docker-java-transport-httpclient5/pom.xml b/docker-java-transport-httpclient5/pom.xml index 48b751d567..872c28e40b 100644 --- a/docker-java-transport-httpclient5/pom.xml +++ b/docker-java-transport-httpclient5/pom.xml @@ -29,13 +29,13 @@ org.apache.httpcomponents.client5 httpclient5 - 5.0.3 + 5.5 net.java.dev.jna jna - 5.13.0 + 5.17.0 diff --git a/docker-java-transport-httpclient5/src/main/java/com/github/dockerjava/httpclient5/ApacheDockerHttpClientImpl.java b/docker-java-transport-httpclient5/src/main/java/com/github/dockerjava/httpclient5/ApacheDockerHttpClientImpl.java index 4820c65e50..c97a2bc453 100644 --- a/docker-java-transport-httpclient5/src/main/java/com/github/dockerjava/httpclient5/ApacheDockerHttpClientImpl.java +++ b/docker-java-transport-httpclient5/src/main/java/com/github/dockerjava/httpclient5/ApacheDockerHttpClientImpl.java @@ -4,31 +4,34 @@ import com.github.dockerjava.transport.NamedPipeSocket; import com.github.dockerjava.transport.SSLConfig; import com.github.dockerjava.transport.UnixSocket; + +import org.apache.hc.client5.http.SystemDefaultDnsResolver; import org.apache.hc.client5.http.classic.methods.HttpUriRequestBase; +import org.apache.hc.client5.http.config.ConnectionConfig; import org.apache.hc.client5.http.config.RequestConfig; +import org.apache.hc.client5.http.impl.DefaultSchemePortResolver; import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; -import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; import org.apache.hc.client5.http.impl.classic.HttpClients; +import org.apache.hc.client5.http.impl.io.DefaultHttpClientConnectionOperator; import org.apache.hc.client5.http.impl.io.ManagedHttpClientConnectionFactory; import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager; -import org.apache.hc.client5.http.socket.ConnectionSocketFactory; -import org.apache.hc.client5.http.socket.PlainConnectionSocketFactory; -import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory; +import org.apache.hc.client5.http.io.HttpClientConnectionOperator; +import org.apache.hc.client5.http.ssl.DefaultClientTlsStrategy; +import org.apache.hc.client5.http.ssl.TlsSocketStrategy; +import org.apache.hc.core5.http.ClassicHttpResponse; import org.apache.hc.core5.http.ConnectionClosedException; import org.apache.hc.core5.http.ContentLengthStrategy; import org.apache.hc.core5.http.Header; import org.apache.hc.core5.http.HttpHeaders; import org.apache.hc.core5.http.HttpHost; import org.apache.hc.core5.http.NameValuePair; -import org.apache.hc.core5.http.config.Registry; -import org.apache.hc.core5.http.config.RegistryBuilder; import org.apache.hc.core5.http.impl.DefaultContentLengthStrategy; -import org.apache.hc.core5.http.impl.io.EmptyInputStream; import org.apache.hc.core5.http.io.SocketConfig; import org.apache.hc.core5.http.io.entity.ByteArrayEntity; +import org.apache.hc.core5.http.io.entity.EmptyInputStream; import org.apache.hc.core5.http.io.entity.InputStreamEntity; -import org.apache.hc.core5.http.protocol.BasicHttpContext; import org.apache.hc.core5.http.protocol.HttpContext; +import org.apache.hc.core5.http.protocol.HttpCoreContext; import org.apache.hc.core5.net.URIAuthority; import org.apache.hc.core5.util.TimeValue; import org.apache.hc.core5.util.Timeout; @@ -38,7 +41,6 @@ import javax.net.ssl.SSLContext; import java.io.IOException; import java.io.InputStream; -import java.net.InetSocketAddress; import java.net.Socket; import java.net.URI; import java.time.Duration; @@ -61,7 +63,13 @@ protected ApacheDockerHttpClientImpl( Duration connectionTimeout, Duration responseTimeout ) { - Registry socketFactoryRegistry = createConnectionSocketFactoryRegistry(sslConfig, dockerHost); + SSLContext sslContext; + try { + sslContext = sslConfig != null ? sslConfig.getSSLContext() : null; + } catch (Exception e) { + throw new RuntimeException(e); + } + HttpClientConnectionOperator connectionOperator = createConnectionOperator(dockerHost, sslContext); switch (dockerHost.getScheme()) { case "unix": @@ -75,7 +83,7 @@ protected ApacheDockerHttpClientImpl( ? rawPath.substring(0, rawPath.length() - 1) : rawPath; host = new HttpHost( - socketFactoryRegistry.lookup("https") != null ? "https" : "http", + sslContext != null ? "https" : "http", dockerHost.getHost(), dockerHost.getPort() ); @@ -85,7 +93,10 @@ protected ApacheDockerHttpClientImpl( } PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager( - socketFactoryRegistry, + connectionOperator, + null, + null, + null, new ManagedHttpClientConnectionFactory( null, null, @@ -109,77 +120,49 @@ protected ApacheDockerHttpClientImpl( .setSoTimeout(Timeout.ZERO_MILLISECONDS) .build() ); - connectionManager.setValidateAfterInactivity(TimeValue.NEG_ONE_SECOND); connectionManager.setMaxTotal(maxConnections); connectionManager.setDefaultMaxPerRoute(maxConnections); - RequestConfig.Builder defaultRequest = RequestConfig.custom(); - if (connectionTimeout != null) { - defaultRequest.setConnectTimeout(connectionTimeout.toNanos(), TimeUnit.NANOSECONDS); - } - if (responseTimeout != null) { - defaultRequest.setResponseTimeout(responseTimeout.toNanos(), TimeUnit.NANOSECONDS); - } + connectionManager.setDefaultConnectionConfig(ConnectionConfig.custom() + .setValidateAfterInactivity(TimeValue.NEG_ONE_SECOND) + .setConnectTimeout(connectionTimeout != null ? Timeout.of(connectionTimeout.toNanos(), TimeUnit.NANOSECONDS) : null) + .build()); httpClient = HttpClients.custom() .setRequestExecutor(new HijackingHttpRequestExecutor(null)) .setConnectionManager(connectionManager) - .setDefaultRequestConfig(defaultRequest.build()) + .setDefaultRequestConfig(RequestConfig.custom() + .setResponseTimeout(responseTimeout != null ? Timeout.of(responseTimeout.toNanos(), TimeUnit.NANOSECONDS) : null) + .build()) .disableConnectionState() .build(); } - private Registry createConnectionSocketFactoryRegistry( - SSLConfig sslConfig, - URI dockerHost + private HttpClientConnectionOperator createConnectionOperator( + URI dockerHost, + SSLContext sslContext ) { - RegistryBuilder socketFactoryRegistryBuilder = RegistryBuilder.create(); - - if (sslConfig != null) { - try { - SSLContext sslContext = sslConfig.getSSLContext(); - if (sslContext != null) { - socketFactoryRegistryBuilder.register("https", new SSLConnectionSocketFactory(sslContext)); - } - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - return socketFactoryRegistryBuilder - .register("tcp", PlainConnectionSocketFactory.INSTANCE) - .register("http", PlainConnectionSocketFactory.INSTANCE) - .register("unix", new ConnectionSocketFactory() { - @Override - public Socket createSocket(HttpContext context) throws IOException { - return UnixSocket.get(dockerHost.getPath()); + String dockerHostScheme = dockerHost.getScheme(); + String dockerHostPath = dockerHost.getPath(); + TlsSocketStrategy tlsSocketStrategy = sslContext != null ? + new DefaultClientTlsStrategy(sslContext) : DefaultClientTlsStrategy.createSystemDefault(); + return new DefaultHttpClientConnectionOperator( + socksProxy -> { + if ("unix".equalsIgnoreCase(dockerHostScheme)) { + return UnixSocket.get(dockerHostPath); + } else if ("npipe".equalsIgnoreCase(dockerHostScheme)) { + return new NamedPipeSocket(dockerHostPath); + } else { + return socksProxy == null ? new Socket() : new Socket(socksProxy); } - - @Override - public Socket connectSocket(TimeValue timeValue, Socket socket, HttpHost httpHost, InetSocketAddress inetSocketAddress, - InetSocketAddress inetSocketAddress1, HttpContext httpContext) throws IOException { - return PlainConnectionSocketFactory.INSTANCE.connectSocket(timeValue, socket, httpHost, inetSocketAddress, - inetSocketAddress1, httpContext); - } - }) - .register("npipe", new ConnectionSocketFactory() { - @Override - public Socket createSocket(HttpContext context) { - return new NamedPipeSocket(dockerHost.getPath()); - } - - @Override - public Socket connectSocket(TimeValue timeValue, Socket socket, HttpHost httpHost, InetSocketAddress inetSocketAddress, - InetSocketAddress inetSocketAddress1, HttpContext httpContext) throws IOException { - return PlainConnectionSocketFactory.INSTANCE.connectSocket(timeValue, socket, httpHost, inetSocketAddress, - inetSocketAddress1, httpContext); - } - }) - .build(); + }, + DefaultSchemePortResolver.INSTANCE, + SystemDefaultDnsResolver.INSTANCE, + name -> "https".equalsIgnoreCase(name) ? tlsSocketStrategy : null); } @Override public Response execute(Request request) { - HttpContext context = new BasicHttpContext(); + HttpContext context = new HttpCoreContext(); HttpUriRequestBase httpUriRequest = new HttpUriRequestBase(request.method(), URI.create(pathPrefix + request.path())); httpUriRequest.setScheme(host.getSchemeName()); httpUriRequest.setAuthority(new URIAuthority(host.getHostName(), host.getPort())); @@ -203,7 +186,7 @@ public Response execute(Request request) { } try { - CloseableHttpResponse response = httpClient.execute(host, httpUriRequest, context); + ClassicHttpResponse response = httpClient.executeOpen(host, httpUriRequest, context); return new ApacheResponse(httpUriRequest, response); } catch (IOException e) { @@ -222,9 +205,9 @@ static class ApacheResponse implements Response { private final HttpUriRequestBase request; - private final CloseableHttpResponse response; + private final ClassicHttpResponse response; - ApacheResponse(HttpUriRequestBase httpUriRequest, CloseableHttpResponse response) { + ApacheResponse(HttpUriRequestBase httpUriRequest, ClassicHttpResponse response) { this.request = httpUriRequest; this.response = response; } diff --git a/docker-java-transport-httpclient5/src/main/java/com/github/dockerjava/httpclient5/HijackingHttpRequestExecutor.java b/docker-java-transport-httpclient5/src/main/java/com/github/dockerjava/httpclient5/HijackingHttpRequestExecutor.java index 59888a5dd1..df8fbd059f 100644 --- a/docker-java-transport-httpclient5/src/main/java/com/github/dockerjava/httpclient5/HijackingHttpRequestExecutor.java +++ b/docker-java-transport-httpclient5/src/main/java/com/github/dockerjava/httpclient5/HijackingHttpRequestExecutor.java @@ -44,7 +44,7 @@ public ClassicHttpResponse execute( InputStream hijackedInput = (InputStream) context.getAttribute(HIJACKED_INPUT_ATTRIBUTE); if (hijackedInput != null) { - return executeHijacked(request, conn, context, hijackedInput); + return executeHijacked(request, conn, (HttpCoreContext) context, hijackedInput); } return super.execute(request, conn, informationCallback, context); @@ -53,12 +53,12 @@ public ClassicHttpResponse execute( private ClassicHttpResponse executeHijacked( ClassicHttpRequest request, HttpClientConnection conn, - HttpContext context, + HttpCoreContext context, InputStream hijackedInput ) throws HttpException, IOException { try { - context.setAttribute(HttpCoreContext.SSL_SESSION, conn.getSSLSession()); - context.setAttribute(HttpCoreContext.CONNECTION_ENDPOINT, conn.getEndpointDetails()); + context.setSSLSession(conn.getSSLSession()); + context.setEndpointDetails(conn.getEndpointDetails()); final ProtocolVersion transportVersion = request.getVersion(); if (transportVersion != null) { context.setProtocolVersion(transportVersion); diff --git a/docker-java-transport-jersey/pom.xml b/docker-java-transport-jersey/pom.xml index fbef13f1eb..a600c208de 100644 --- a/docker-java-transport-jersey/pom.xml +++ b/docker-java-transport-jersey/pom.xml @@ -26,11 +26,6 @@ ${project.version} - - com.fasterxml.jackson.jaxrs - jackson-jaxrs-json-provider - ${jackson-jaxrs.version} - org.glassfish.jersey.connectors jersey-apache-connector diff --git a/docker-java-transport-okhttp/pom.xml b/docker-java-transport-okhttp/pom.xml index df14ad0777..3bac0cead0 100644 --- a/docker-java-transport-okhttp/pom.xml +++ b/docker-java-transport-okhttp/pom.xml @@ -35,7 +35,7 @@ net.java.dev.jna jna - 5.13.0 + 5.17.0 diff --git a/docker-java-transport-okhttp/src/main/java/com/github/dockerjava/okhttp/UnixSocketFactory.java b/docker-java-transport-okhttp/src/main/java/com/github/dockerjava/okhttp/UnixSocketFactory.java index dc19b13518..d25bcb3d33 100644 --- a/docker-java-transport-okhttp/src/main/java/com/github/dockerjava/okhttp/UnixSocketFactory.java +++ b/docker-java-transport-okhttp/src/main/java/com/github/dockerjava/okhttp/UnixSocketFactory.java @@ -20,7 +20,7 @@ public Socket createSocket() { try { return UnixSocket.get(socketPath); } catch (IOException e) { - throw new RuntimeException(e); + throw new RuntimeException("Failed create socket with path " + socketPath, e); } } diff --git a/docker-java-transport-tck/pom.xml b/docker-java-transport-tck/pom.xml index 2e4bd79ce0..69d40cc3c3 100644 --- a/docker-java-transport-tck/pom.xml +++ b/docker-java-transport-tck/pom.xml @@ -34,7 +34,7 @@ org.assertj assertj-core - 3.24.2 + 3.27.4 @@ -46,7 +46,7 @@ org.testcontainers testcontainers - 1.19.1 + 1.21.3 diff --git a/docker-java-transport/pom.xml b/docker-java-transport/pom.xml index 2ca377dd66..96f1f850ab 100644 --- a/docker-java-transport/pom.xml +++ b/docker-java-transport/pom.xml @@ -30,14 +30,14 @@ org.immutables value - 2.8.2 + 2.10.1 provided net.java.dev.jna jna - 5.13.0 + 5.17.0 provided diff --git a/docker-java-transport/src/main/java/com/github/dockerjava/transport/UnixSocket.java b/docker-java-transport/src/main/java/com/github/dockerjava/transport/UnixSocket.java index de447db61a..eb7a49b51a 100644 --- a/docker-java-transport/src/main/java/com/github/dockerjava/transport/UnixSocket.java +++ b/docker-java-transport/src/main/java/com/github/dockerjava/transport/UnixSocket.java @@ -3,6 +3,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.lang.reflect.InvocationTargetException; import java.net.Socket; import java.net.SocketAddress; import java.net.SocketException; @@ -24,7 +25,8 @@ public class UnixSocket extends AbstractSocket { public static Socket get(String path) throws IOException { try { return new UnixSocket(path); - } catch (Exception e) { + } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | + IllegalAccessException e) { //noinspection deprecation return DomainSocket.get(path); } @@ -34,7 +36,8 @@ public static Socket get(String path) throws IOException { private final SocketChannel socketChannel; - private UnixSocket(String path) throws Exception { + private UnixSocket(String path) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, + IllegalAccessException, IOException { Class unixDomainSocketAddress = Class.forName("java.net.UnixDomainSocketAddress"); this.socketAddress = (SocketAddress) unixDomainSocketAddress.getMethod("of", String.class) diff --git a/docker-java/pom.xml b/docker-java/pom.xml index e3c3690f13..f1cc09f64f 100644 --- a/docker-java/pom.xml +++ b/docker-java/pom.xml @@ -118,30 +118,30 @@ org.awaitility awaitility - 4.0.1 + 4.3.0 test com.fasterxml.jackson.core jackson-databind - - 2.8.8 + + 2.19.2 test com.fasterxml.jackson.core jackson-annotations - - 2.8.8 + + 2.19.2 test org.projectlombok lombok - 1.18.30 + 1.18.38 provided diff --git a/docker-java/src/main/java/com/github/dockerjava/core/DockerClientBuilder.java b/docker-java/src/main/java/com/github/dockerjava/core/DockerClientBuilder.java index a3e4c3909d..8100f285e6 100644 --- a/docker-java/src/main/java/com/github/dockerjava/core/DockerClientBuilder.java +++ b/docker-java/src/main/java/com/github/dockerjava/core/DockerClientBuilder.java @@ -94,7 +94,7 @@ public DockerClient build() { } else { Logger log = LoggerFactory.getLogger(DockerClientBuilder.class); log.warn( - "'dockerHttpClient' should be set." + + "'dockerHttpClient' should be set. " + "Falling back to Jersey, will be an error in future releases." ); diff --git a/docker-java/src/test/java/com/github/dockerjava/api/command/CommandJSONSamples.java b/docker-java/src/test/java/com/github/dockerjava/api/command/CommandJSONSamples.java index 0cf5141d49..23ef4b7f25 100644 --- a/docker-java/src/test/java/com/github/dockerjava/api/command/CommandJSONSamples.java +++ b/docker-java/src/test/java/com/github/dockerjava/api/command/CommandJSONSamples.java @@ -28,7 +28,9 @@ public enum CommandJSONSamples implements JSONResourceRef { inspectContainerResponse_full_1_21, inspectContainerResponse_full_1_26a, inspectContainerResponse_full_1_26b, - inspectContainerResponse_empty; + inspectContainerResponse_empty, + updateContainerResponse_empty, + updateContainerResponse_warnings; @Override public String getFileName() { diff --git a/docker-java/src/test/java/com/github/dockerjava/api/command/UpdateContainerResponseTest.java b/docker-java/src/test/java/com/github/dockerjava/api/command/UpdateContainerResponseTest.java new file mode 100644 index 0000000000..300a5c324b --- /dev/null +++ b/docker-java/src/test/java/com/github/dockerjava/api/command/UpdateContainerResponseTest.java @@ -0,0 +1,33 @@ +package com.github.dockerjava.api.command; + +import com.github.dockerjava.api.model.UpdateContainerResponse; +import org.junit.Test; + +import java.io.IOException; +import java.util.List; + +import static com.github.dockerjava.test.serdes.JSONTestHelper.testRoundTrip; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +public class UpdateContainerResponseTest { + @Test + public void roundTrip_empty() throws IOException { + UpdateContainerResponse response = testRoundTrip(CommandJSONSamples.updateContainerResponse_empty, UpdateContainerResponse.class); + assertNull(response.getWarnings()); + } + + @Test + public void roundTrip_warnings() throws IOException { + UpdateContainerResponse response = testRoundTrip(CommandJSONSamples.updateContainerResponse_warnings, + UpdateContainerResponse.class); + + List warnings = response.getWarnings(); + assertNotNull(warnings); + assertEquals(1, warnings.size()); + + final String warning = warnings.get(0); + assertEquals("Published ports are discarded when using host network mode", warning); + } +} diff --git a/docker-java/src/test/java/com/github/dockerjava/api/model/CapabilityTest.java b/docker-java/src/test/java/com/github/dockerjava/api/model/CapabilityTest.java index aa6167b8cb..b0652d9455 100644 --- a/docker-java/src/test/java/com/github/dockerjava/api/model/CapabilityTest.java +++ b/docker-java/src/test/java/com/github/dockerjava/api/model/CapabilityTest.java @@ -18,6 +18,9 @@ public void serializeCapability() throws Exception { public void deserializeCapability() throws Exception { Capability capability = JSONTestHelper.getMapper().readValue("\"ALL\"", Capability.class); assertEquals(Capability.ALL, capability); + + Capability compatibleCapability = JSONTestHelper.getMapper().readValue("\"CAP_ALL\"", Capability.class); + assertEquals(Capability.ALL, compatibleCapability); } @Test(expected = JsonMappingException.class) diff --git a/docker-java/src/test/java/com/github/dockerjava/cmd/CreateContainerCmdIT.java b/docker-java/src/test/java/com/github/dockerjava/cmd/CreateContainerCmdIT.java index de9f564e4f..d91791cbcb 100644 --- a/docker-java/src/test/java/com/github/dockerjava/cmd/CreateContainerCmdIT.java +++ b/docker-java/src/test/java/com/github/dockerjava/cmd/CreateContainerCmdIT.java @@ -10,6 +10,8 @@ import com.github.dockerjava.api.command.InspectContainerResponse; import com.github.dockerjava.api.exception.ConflictException; import com.github.dockerjava.api.exception.DockerException; +import com.github.dockerjava.api.DockerClient; +import com.github.dockerjava.core.DefaultDockerClientConfig; import com.github.dockerjava.api.exception.InternalServerErrorException; import com.github.dockerjava.api.exception.NotFoundException; import com.github.dockerjava.api.model.AuthConfig; @@ -34,7 +36,9 @@ import com.github.dockerjava.utils.TestUtils; import net.jcip.annotations.NotThreadSafe; import org.apache.commons.io.FileUtils; +import org.apache.commons.lang3.SystemUtils; import org.junit.ClassRule; +import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -56,6 +60,7 @@ import static com.github.dockerjava.api.model.HostConfig.newHostConfig; import static com.github.dockerjava.core.RemoteApiVersion.VERSION_1_23; import static com.github.dockerjava.core.RemoteApiVersion.VERSION_1_24; +import static com.github.dockerjava.core.RemoteApiVersion.VERSION_1_43; import static com.github.dockerjava.junit.DockerMatchers.isGreaterOrEqual; import static com.github.dockerjava.junit.DockerMatchers.mountedVolumes; import static com.github.dockerjava.core.DockerRule.DEFAULT_IMAGE; @@ -420,6 +425,7 @@ public void createContainerWithLink() throws DockerException { } @Test + @Ignore public void createContainerWithMemorySwappiness() throws DockerException { CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE) .withCmd("sleep", "9999") @@ -959,6 +965,8 @@ public void onNext(Frame item) { @Test public void createContainerWithCgroupParent() throws DockerException { + assumeThat(!SystemUtils.IS_OS_LINUX, is(true)); + CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox") .withHostConfig(newHostConfig() .withCgroupParent("/parent")) @@ -1136,4 +1144,33 @@ public void shouldHandleANetworkAliasWithoutACustomNetworkGracefully() { .withCmd("sleep", "9999") .exec(); } + + @Test + public void createContainerWithAnnotations() throws DockerException { + DefaultDockerClientConfig forcedConfig = DefaultDockerClientConfig.createDefaultConfigBuilder() + .withApiVersion(VERSION_1_43) + .withRegistryUrl("https://index.docker.io/v1/") + .build(); + + DockerClient forcedClient = CmdIT.createDockerClient(forcedConfig); + Map annotations = new HashMap<>(); + annotations.put("com.example.key1", "value1"); + annotations.put("com.example.key2", "value2"); + + CreateContainerResponse container = forcedClient.createContainerCmd(DEFAULT_IMAGE) + .withCmd("sleep", "9999") + .withHostConfig(newHostConfig() + .withAnnotations(annotations)) + .exec(); + + LOG.info("Created container {}", container.toString()); + + assertThat(container.getId(), not(is(emptyString()))); + + InspectContainerResponse inspectContainerResponse = forcedClient.inspectContainerCmd(container.getId()).exec(); + + assertThat(inspectContainerResponse.getHostConfig().getAnnotations(), equalTo(annotations)); + assertThat(inspectContainerResponse.getHostConfig().getAnnotations().get("com.example.key1"), equalTo("value1")); + assertThat(inspectContainerResponse.getHostConfig().getAnnotations().get("com.example.key2"), equalTo("value2")); + } } diff --git a/docker-java/src/test/java/com/github/dockerjava/cmd/ExecStartCmdIT.java b/docker-java/src/test/java/com/github/dockerjava/cmd/ExecStartCmdIT.java index cf096aa26d..fc111f0e27 100644 --- a/docker-java/src/test/java/com/github/dockerjava/cmd/ExecStartCmdIT.java +++ b/docker-java/src/test/java/com/github/dockerjava/cmd/ExecStartCmdIT.java @@ -4,6 +4,7 @@ import com.github.dockerjava.api.command.ExecCreateCmdResponse; import com.github.dockerjava.api.exception.NotFoundException; import com.github.dockerjava.core.command.ExecStartResultCallback; +import org.junit.Ignore; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -77,6 +78,7 @@ public void execStartAttached() throws Exception { assertTrue(responseAsString.length() > 0); } + @Ignore @Test(expected = NotFoundException.class) public void execStartWithNonExistentUser() throws Exception { String containerName = "generated_" + new SecureRandom().nextInt(); diff --git a/docker-java/src/test/java/com/github/dockerjava/cmd/InspectContainerCmdIT.java b/docker-java/src/test/java/com/github/dockerjava/cmd/InspectContainerCmdIT.java index 54d900db8b..cc1468f7ff 100644 --- a/docker-java/src/test/java/com/github/dockerjava/cmd/InspectContainerCmdIT.java +++ b/docker-java/src/test/java/com/github/dockerjava/cmd/InspectContainerCmdIT.java @@ -100,9 +100,9 @@ public void inspectContainerWithSize() throws DockerException { // TODO check swarm if (isNotSwarm(dockerRule.getClient())) { assertNotNull(containerInfo.getSizeRootFs()); - assertTrue(containerInfo.getSizeRootFs().intValue() > 0); + assertTrue(containerInfo.getSizeRootFs() > 0L); assertNotNull(containerInfo.getSizeRw()); - assertTrue(containerInfo.getSizeRw().intValue() == 0); + assertEquals(0L, containerInfo.getSizeRw().longValue()); } } diff --git a/docker-java/src/test/java/com/github/dockerjava/cmd/RestartContainerCmdImplIT.java b/docker-java/src/test/java/com/github/dockerjava/cmd/RestartContainerCmdImplIT.java index ac24152815..bdf309dc21 100644 --- a/docker-java/src/test/java/com/github/dockerjava/cmd/RestartContainerCmdImplIT.java +++ b/docker-java/src/test/java/com/github/dockerjava/cmd/RestartContainerCmdImplIT.java @@ -60,7 +60,7 @@ public void restartContainerWithSignal() throws Exception { .build(); try (DockerClient dockerClient = createDockerClient(dockerClientConfig)) { String expectedUserSignal = "10"; - String initialCommandWithTrap = "trap 'echo \"exit trapped\"' %s; sleep 9999;"; + String initialCommandWithTrap = "trap 'echo \"exit trapped\"' %s; while :; do sleep 1; done"; final String containerId = dockerClient .createContainerCmd(DEFAULT_IMAGE) .withCmd( diff --git a/docker-java/src/test/java/com/github/dockerjava/cmd/UpdateContainerCmdIT.java b/docker-java/src/test/java/com/github/dockerjava/cmd/UpdateContainerCmdIT.java index e5bb554991..e1e637809c 100644 --- a/docker-java/src/test/java/com/github/dockerjava/cmd/UpdateContainerCmdIT.java +++ b/docker-java/src/test/java/com/github/dockerjava/cmd/UpdateContainerCmdIT.java @@ -48,8 +48,8 @@ public void updateContainer() throws DockerException { dockerRule.getClient().updateContainerCmd(containerId) .withBlkioWeight(300) .withCpuShares(512) - .withCpuPeriod(100000) - .withCpuQuota(50000) + .withCpuPeriod(100000L) + .withCpuQuota(50000L) // .withCpusetCpus("0") // depends on env .withCpusetMems("0") // .withMemory(209715200L + 2L) diff --git a/docker-java/src/test/java/com/github/dockerjava/cmd/WaitContainerCmdIT.java b/docker-java/src/test/java/com/github/dockerjava/cmd/WaitContainerCmdIT.java index e2ad2a643e..3a39b3eeab 100644 --- a/docker-java/src/test/java/com/github/dockerjava/cmd/WaitContainerCmdIT.java +++ b/docker-java/src/test/java/com/github/dockerjava/cmd/WaitContainerCmdIT.java @@ -8,18 +8,25 @@ import com.github.dockerjava.api.exception.DockerClientException; import com.github.dockerjava.api.exception.DockerException; import com.github.dockerjava.api.exception.NotFoundException; +import com.github.dockerjava.api.model.WaitContainerCondition; import com.github.dockerjava.api.model.WaitResponse; +import org.junit.Assert; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.concurrent.TimeUnit; +import static com.github.dockerjava.api.model.HostConfig.newHostConfig; +import static com.github.dockerjava.core.RemoteApiVersion.VERSION_1_25; +import static com.github.dockerjava.core.RemoteApiVersion.VERSION_1_30; +import static com.github.dockerjava.junit.DockerMatchers.isGreaterOrEqual; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.emptyString; import static org.hamcrest.Matchers.not; +import static org.junit.Assume.assumeThat; public class WaitContainerCmdIT extends CmdIT { public static final Logger LOG = LoggerFactory.getLogger(BuildImageCmd.class); @@ -102,4 +109,77 @@ public void testWaitContainerTimeout() { LOG.info(e.getMessage()); } } + + @Test + public void testWaitNotStartedContainer() { + assumeThat("API version should be > 1.25", dockerRule, isGreaterOrEqual(VERSION_1_25)); + + CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox") + .withHostConfig(newHostConfig().withAutoRemove(true)) + .exec(); + + LOG.info("Created container: {}", container.toString()); + assertThat(container.getId(), not(is(emptyString()))); + + WaitContainerResultCallback callback = dockerRule.getClient().waitContainerCmd(container.getId()).exec(new WaitContainerResultCallback()); + + Integer statusCode = callback.awaitStatusCode(100, TimeUnit.MILLISECONDS); + Assert.assertEquals(0, statusCode.intValue()); + } + + @Test + public void testWaitContainerWithAutoRemoval() { + assumeThat("API version should be > 1.30", dockerRule, isGreaterOrEqual(VERSION_1_30)); + + CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox") + .withCmd("false") + .withHostConfig(newHostConfig().withAutoRemove(true)) + .exec(); + + LOG.info("Created container: {}", container.toString()); + assertThat(container.getId(), not(is(emptyString()))); + + WaitContainerResultCallback removedCondition = dockerRule.getClient().waitContainerCmd(container.getId()) + .withCondition(WaitContainerCondition.REMOVED) + .exec(new WaitContainerResultCallback()); + + WaitContainerResultCallback nextExitCondition = dockerRule.getClient().waitContainerCmd(container.getId()) + .withCondition(WaitContainerCondition.NEXT_EXIT) + .exec(new WaitContainerResultCallback()); + + dockerRule.getClient().startContainerCmd(container.getId()).exec(); + + Assert.assertEquals(1, removedCondition.awaitStatusCode(100, TimeUnit.MILLISECONDS).intValue()); + Assert.assertEquals(1, nextExitCondition.awaitStatusCode(100, TimeUnit.MILLISECONDS).intValue()); + } + + @Test + public void testWaitRestartedContainer() { + assumeThat("API version should be > 1.30", dockerRule, isGreaterOrEqual(VERSION_1_30)); + + CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox") + .withCmd("sh", "-c", "[ -f \"$HOME/.first_run_marker\" ] && exit 2 || { touch \"$HOME/.first_run_marker\"; exit 1; }") + .exec(); + + LOG.info("Created container: {}", container.toString()); + assertThat(container.getId(), not(is(emptyString()))); + + WaitContainerResultCallback firstExitCallback = dockerRule.getClient().waitContainerCmd(container.getId()) + .withCondition(WaitContainerCondition.NEXT_EXIT) + .exec(new WaitContainerResultCallback()); + + dockerRule.getClient().startContainerCmd(container.getId()).exec(); + + Integer firstStatusCode = firstExitCallback.awaitStatusCode(100, TimeUnit.MILLISECONDS); + Assert.assertEquals(1, firstStatusCode.intValue()); + + WaitContainerResultCallback callback = dockerRule.getClient().waitContainerCmd(container.getId()) + .withCondition(WaitContainerCondition.NEXT_EXIT) + .exec(new WaitContainerResultCallback()); + + dockerRule.getClient().startContainerCmd(container.getId()).exec(); + + Integer statusCode = callback.awaitStatusCode(100, TimeUnit.MILLISECONDS); + Assert.assertEquals(2, statusCode.intValue()); + } } diff --git a/docker-java/src/test/java/com/github/dockerjava/cmd/swarm/SwarmCmdIT.java b/docker-java/src/test/java/com/github/dockerjava/cmd/swarm/SwarmCmdIT.java index 87f35161cc..36bcab8400 100644 --- a/docker-java/src/test/java/com/github/dockerjava/cmd/swarm/SwarmCmdIT.java +++ b/docker-java/src/test/java/com/github/dockerjava/cmd/swarm/SwarmCmdIT.java @@ -20,6 +20,8 @@ import org.junit.experimental.categories.Category; import java.io.IOException; +import java.time.Duration; +import java.util.Arrays; import java.util.HashSet; import java.util.Set; import java.util.concurrent.TimeUnit; @@ -36,7 +38,7 @@ public abstract class SwarmCmdIT extends CmdIT { private static final String DOCKER_IN_DOCKER_IMAGE_REPOSITORY = "docker"; - private static final String DOCKER_IN_DOCKER_IMAGE_TAG = "17.12-dind"; + private static final String DOCKER_IN_DOCKER_IMAGE_TAG = "26.1.3-dind"; private static final String DOCKER_IN_DOCKER_CONTAINER_PREFIX = "docker"; @@ -105,6 +107,8 @@ protected DockerClient startDockerInDocker() throws InterruptedException { ExposedPort exposedPort = ExposedPort.tcp(2375); CreateContainerResponse response = hostDockerClient .createContainerCmd(DOCKER_IN_DOCKER_IMAGE_REPOSITORY + ":" + DOCKER_IN_DOCKER_IMAGE_TAG) + .withEntrypoint("dockerd") + .withCmd(Arrays.asList("--host=tcp://0.0.0.0:2375", "--host=unix:///var/run/docker.sock", "--tls=false")) .withHostConfig(newHostConfig() .withNetworkMode(NETWORK_NAME) .withPortBindings(new PortBinding( @@ -125,7 +129,7 @@ protected DockerClient startDockerInDocker() throws InterruptedException { DockerClient dockerClient = initializeDockerClient(binding); - await().atMost(5, TimeUnit.SECONDS).untilAsserted(() -> { + await().pollDelay(Duration.ofSeconds(5)).atMost(10, TimeUnit.SECONDS).untilAsserted(() -> { dockerClient.pingCmd().exec(); }); diff --git a/docker-java/src/test/resources/com/github/dockerjava/api/command/updateContainerResponse_empty.json b/docker-java/src/test/resources/com/github/dockerjava/api/command/updateContainerResponse_empty.json new file mode 100644 index 0000000000..0967ef424b --- /dev/null +++ b/docker-java/src/test/resources/com/github/dockerjava/api/command/updateContainerResponse_empty.json @@ -0,0 +1 @@ +{} diff --git a/docker-java/src/test/resources/com/github/dockerjava/api/command/updateContainerResponse_warnings.json b/docker-java/src/test/resources/com/github/dockerjava/api/command/updateContainerResponse_warnings.json new file mode 100644 index 0000000000..edeaedc7a8 --- /dev/null +++ b/docker-java/src/test/resources/com/github/dockerjava/api/command/updateContainerResponse_warnings.json @@ -0,0 +1,5 @@ +{ + "Warnings": [ + "Published ports are discarded when using host network mode" + ] +} diff --git a/pom.xml b/pom.xml index f58a3d448a..58fa183e89 100644 --- a/pom.xml +++ b/pom.xml @@ -57,22 +57,21 @@ 1.8 1.8 - 2.30.1 - 2.10.3 - 2.10.3 + 2.47 + 2.19.2 4.5.12 - 1.21 - 2.13.0 - 3.12.0 + 1.28.0 + 2.20.0 + 3.18.0 1.7.30 - 1.76 - 2.6.1 - 19.0 + 1.81 + 2.10.1 + 33.4.8-jre 1.2.3 - 4.1.46.Final + 4.2.4.Final 2.2 1.8 2.3.3 @@ -244,7 +243,7 @@ com.github.siom79.japicmp japicmp-maven-plugin - 0.18.3 + 0.23.1 @@ -286,6 +285,17 @@ + + org.sonatype.central + central-publishing-maven-plugin + 0.8.0 + true + + central + docker-java-transport-tck + com.github.docker-java + + @@ -297,6 +307,9 @@ org.apache.maven.plugins maven-javadoc-plugin + + org.sonatype.central + central-publishing-maven-plugin @@ -308,6 +321,13 @@ org.apache.maven.plugins maven-gpg-plugin + + + + --pinentry-mode + loopback + + sign-artifacts