Skip to content
This repository has been archived by the owner on Feb 16, 2023. It is now read-only.

feat: Root support, only binary copied from original image, dependencies installed manually #6

Merged
merged 3 commits into from
Apr 27, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Tests expected to fail
  • Loading branch information
lholota committed Apr 27, 2020
commit 682cdb3dc59025d50b13bf2f779610b7ef69ec41
4 changes: 3 additions & 1 deletion fs/etc/services.d/cadvisor/run
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/with-contenv sh

exec s6-setuidgid "$PUID:$PGID" /usr/bin/cadvisor $CADVISOR_ARGS
s6-setuidgid nonroot

exec /usr/bin/cadvisor $CADVISOR_ARGS
31 changes: 25 additions & 6 deletions tests/src/test/java/CadvisorContainerShould.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,31 @@

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

import org.junit.Test;

public class CadvisorContainerShould extends ContainerTestBase {

@Test
public void listenOnWebUiPort() throws IOException {
URL root = new URL(String.format("http:https://%s:%d",
getContainer().getContainerIpAddress(),
getContainer().getMappedPort(8080)));
startContainer();

HttpURLConnection connection = (HttpURLConnection)root.openConnection();
connection.connect();
checkContainerListensOnWebUiPort();
}

assertEquals(200, connection.getResponseCode());
@Test
public void listenOnWebUiPortWhenRunningAsRoot() throws IOException {
startContainer("0", "0");

checkContainerListensOnWebUiPort();
}

@Test
public void returnMetrics() throws IOException {
startContainer();

URL root = new URL(String.format("http:https://%s:%d/metrics",
getContainer().getContainerIpAddress(),
getContainer().getMappedPort(8080)));
Expand All @@ -33,6 +39,8 @@ public void returnMetrics() throws IOException {

@Test
public void returnSuccessOnHealthCheckEndpoint() throws IOException {
startContainer();

URL root = new URL(String.format("http:https://%s:%d/healthz",
getContainer().getContainerIpAddress(),
getContainer().getMappedPort(8080)));
Expand All @@ -42,4 +50,15 @@ public void returnSuccessOnHealthCheckEndpoint() throws IOException {

assertEquals(200, connection.getResponseCode());
}

private void checkContainerListensOnWebUiPort() throws IOException {
URL root = new URL(String.format("http:https://%s:%d",
getContainer().getContainerIpAddress(),
getContainer().getMappedPort(8080)));

HttpURLConnection connection = (HttpURLConnection)root.openConnection();
connection.connect();

assertEquals(200, connection.getResponseCode());
}
}
24 changes: 16 additions & 8 deletions tests/src/test/java/ContainerTestBase.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import org.junit.After;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.slf4j.Logger;
Expand All @@ -11,23 +12,30 @@ public abstract class ContainerTestBase {

private static GenericContainer _container;

@BeforeClass
public static void setUp() {
String dockerImageTag = System.getProperty("image_tag", "homecentr/cadvisor");
protected void startContainer() {
startContainer("", "");
}

protected void startContainer(String uid, String gid) {
String dockerImageTag = System.getProperty("image_tag");

logger.info("Tested Docker image tag: {}", dockerImageTag);

_container = new GenericContainer<>(System.getProperty("image_tag", dockerImageTag))
_container = new GenericContainer<>(dockerImageTag)
.withEnv("PUID", uid)
.withEnv("PGID", gid)
.waitingFor(Wait.forHealthcheck());

_container.start();
_container.followOutput(new Slf4jLogConsumer(logger));
}

@AfterClass
public static void cleanUp() {
_container.stop();
_container.close();
@After
public void cleanUp() {
if(_container != null) {
_container.stop();
_container.close();
}
}

protected GenericContainer getContainer() {
Expand Down