-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a rootless Docker strategy (#2985)
- Loading branch information
Showing
13 changed files
with
167 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: CI-Docker-Rootless | ||
|
||
on: | ||
pull_request: {} | ||
push: { branches: [ master ] } | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-18.04 | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: debug | ||
run: id -u; whoami | ||
- name: uninstall rootful Docker | ||
run: sudo apt-get -q -y --purge remove moby-engine moby-buildx && sudo rm -rf /var/run/docker.sock | ||
- name: install rootless Docker | ||
run: curl -fsSL https://get.docker.com/rootless | sh | ||
- name: start rootless Docker | ||
run: PATH=$HOME/bin:$PATH XDG_RUNTIME_DIR=/tmp/docker-$(id -u) dockerd-rootless.sh --experimental --storage-driver vfs & | ||
- name: Build with Gradle | ||
run: XDG_RUNTIME_DIR=/tmp/docker-$(id -u) ./gradlew --no-daemon --scan testcontainers:test | ||
- name: aggregate test reports with ciMate | ||
if: always() | ||
continue-on-error: true | ||
env: | ||
CIMATE_PROJECT_ID: 2348n4vl | ||
CIMATE_CI_KEY: "CI / rootless Docker" | ||
run: | | ||
wget -q https://get.cimate.io/release/linux/cimate | ||
chmod +x cimate | ||
./cimate "**/TEST-*.xml" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
core/src/main/java/org/testcontainers/dockerclient/RootlessDockerClientProviderStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package org.testcontainers.dockerclient; | ||
|
||
import com.sun.jna.Library; | ||
import com.sun.jna.Native; | ||
import org.apache.commons.lang.SystemUtils; | ||
|
||
import java.net.URI; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
/** | ||
* | ||
* @deprecated this class is used by the SPI and should not be used directly | ||
*/ | ||
@Deprecated | ||
public final class RootlessDockerClientProviderStrategy extends DockerClientProviderStrategy { | ||
|
||
public static final int PRIORITY = UnixSocketClientProviderStrategy.PRIORITY + 1; | ||
|
||
private Path getSocketPath() { | ||
String xdgRuntimeDir = System.getenv("XDG_RUNTIME_DIR"); | ||
if (xdgRuntimeDir == null) { | ||
xdgRuntimeDir = "/run/user/" + LibC.INSTANCE.getuid(); | ||
} | ||
return Paths.get(xdgRuntimeDir).resolve("docker.sock"); | ||
} | ||
|
||
@Override | ||
public TransportConfig getTransportConfig() throws InvalidConfigurationException { | ||
return TransportConfig.builder() | ||
.dockerHost(URI.create("unix://" + getSocketPath().toString())) | ||
.build(); | ||
} | ||
|
||
@Override | ||
protected boolean isApplicable() { | ||
return SystemUtils.IS_OS_LINUX && Files.exists(getSocketPath()); | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Rootless Docker accessed via Unix socket (" + getSocketPath() + ")"; | ||
} | ||
|
||
@Override | ||
protected int getPriority() { | ||
return PRIORITY; | ||
} | ||
|
||
private interface LibC extends Library { | ||
|
||
LibC INSTANCE = Native.loadLibrary("c", LibC.class); | ||
|
||
int getuid(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters