This repository has been archived by the owner on Jun 27, 2024. It is now read-only.
generated from homecentr/docker-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(bug): Connector process not executed as passed PUID/PGID (#67)
- Loading branch information
Showing
9 changed files
with
86 additions
and
105 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
#!/usr/bin/with-contenv sh | ||
|
||
s6-setuidgid "$PUID:$PGID" | ||
|
||
exec /swarm-local-network-connector | ||
exec runas /swarm-local-network-connector |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,114 +1,103 @@ | ||
import PullPolicies.NeverPullImagePolicy; | ||
import helpers.DockerImageTagResolver; | ||
import io.homecentr.testcontainers.containers.GenericContainerEx; | ||
import io.homecentr.testcontainers.images.NeverPullImagePolicy; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.containers.output.Slf4jLogConsumer; | ||
import org.testcontainers.containers.wait.strategy.Wait; | ||
|
||
import java.time.Duration; | ||
import java.util.concurrent.TimeoutException; | ||
|
||
import static io.homecentr.testcontainers.WaitLoop.waitFor; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
public class ConnectorContainerShould extends ContainerTestBase { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(ContainerTestBase.class); | ||
|
||
@Test | ||
public void connectContainersCreatedBeforeStartOfConnector() throws InterruptedException, TimeoutException { | ||
|
||
GenericContainer targetContainer = new GenericContainer<>("nginx") | ||
.withLabel("io.homecentr.local-networks", "[{ \"Network\": \""+ getNetworkName() +"\" }]"); | ||
private GenericContainer _connectorContainer; | ||
private GenericContainer _targetContainer; | ||
|
||
GenericContainer connectorContainer = createConnectorContainer(); | ||
|
||
try { | ||
targetContainer.start(); | ||
@Before | ||
public void before() { | ||
_connectorContainer = new GenericContainerEx<>(new DockerImageTagResolver()) | ||
.withFileSystemBind("//var/run/docker.sock", "/var/run/docker.sock") | ||
.withImagePullPolicy(new NeverPullImagePolicy()) | ||
.withEnv("LOG_LEVEL", "debug") | ||
.withEnv("PUID", "0") | ||
.withEnv("PGID", "0") | ||
.waitingFor(Wait.forLogMessage(".*Started, waiting for signal.*", 1)); | ||
} | ||
|
||
connectorContainer.start(); | ||
connectorContainer.followOutput(new Slf4jLogConsumer(logger)); | ||
@After | ||
public void after() { | ||
_connectorContainer.close(); | ||
|
||
waitUntilContainerConnectedToNetwork(targetContainer, 5000); | ||
} | ||
finally { | ||
targetContainer.close(); | ||
connectorContainer.close(); | ||
if(_targetContainer != null) { | ||
_targetContainer.close(); | ||
} | ||
} | ||
|
||
@Test | ||
public void connectContainerCreatedAfterStartOfConnector() throws InterruptedException, TimeoutException { | ||
GenericContainer targetContainer = new GenericContainer<>("nginx") | ||
public void connectContainersCreatedBeforeStartOfConnector() throws Exception { | ||
_targetContainer = new GenericContainer<>("nginx") | ||
.withLabel("io.homecentr.local-networks", "[{ \"Network\": \""+ getNetworkName() +"\" }]"); | ||
|
||
GenericContainer connectorContainer = createConnectorContainer(); | ||
_targetContainer.start(); | ||
|
||
try { | ||
connectorContainer.start(); | ||
targetContainer.start(); | ||
_connectorContainer.start(); | ||
_connectorContainer.followOutput(new Slf4jLogConsumer(logger)); | ||
|
||
connectorContainer.followOutput(new Slf4jLogConsumer(logger)); | ||
waitFor(Duration.ofSeconds(5), () -> isConnectedToNetwork(_targetContainer)); | ||
} | ||
|
||
waitUntilContainerConnectedToNetwork(targetContainer, 5000); | ||
} | ||
finally { | ||
targetContainer.close(); | ||
connectorContainer.close(); | ||
} | ||
@Test | ||
public void connectContainerCreatedAfterStartOfConnector() throws Exception { | ||
_targetContainer = new GenericContainer<>("nginx") | ||
.withLabel("io.homecentr.local-networks", "[{ \"Network\": \""+ getNetworkName() +"\" }]"); | ||
|
||
_connectorContainer.start(); | ||
_connectorContainer.followOutput(new Slf4jLogConsumer(logger)); | ||
|
||
_targetContainer.start(); | ||
|
||
waitFor(Duration.ofSeconds(5), () -> isConnectedToNetwork(_targetContainer)); | ||
} | ||
|
||
@Test | ||
public void connectContainerWithExplicitConfig() throws Exception { | ||
GenericContainer targetContainer = new GenericContainer<>("nginx") | ||
_targetContainer = new GenericContainer<>("nginx") | ||
.withLabel("io.homecentr.local-networks", "[{ \"Network\": \""+ getNetworkName() +"\", \"Config\": { \"IPAMConfig\": { \"IPV4Address\": \"192.168.99.100\" } } }]"); | ||
|
||
GenericContainer connectorContainer = createConnectorContainer(); | ||
|
||
try { | ||
connectorContainer.start(); | ||
targetContainer.start(); | ||
_connectorContainer.start(); | ||
_connectorContainer.followOutput(new Slf4jLogConsumer(logger)); | ||
|
||
connectorContainer.followOutput(new Slf4jLogConsumer(logger)); | ||
_targetContainer.start(); | ||
|
||
waitUntilContainerConnectedToNetwork(targetContainer, 5000); | ||
waitFor(Duration.ofSeconds(5), () -> isConnectedToNetwork(_targetContainer)); | ||
|
||
assertEquals("192.168.99.100", getContainerIpAddress(targetContainer)); | ||
} | ||
finally { | ||
targetContainer.close(); | ||
connectorContainer.close(); | ||
} | ||
assertEquals("192.168.99.100", getContainerIpAddress(_targetContainer)); | ||
} | ||
|
||
@Test | ||
public void ignoreContainerWithInvalidLabel() throws Exception { | ||
GenericContainer targetContainer = new GenericContainer<>("nginx") | ||
_targetContainer = new GenericContainer<>("nginx") | ||
.withLabel("io.homecentr.local-networks", "[{ \"Network\": \""+ getNetworkName() +"\" }]"); | ||
|
||
GenericContainer connectorContainer = createConnectorContainer(); | ||
|
||
try { | ||
connectorContainer.start(); | ||
targetContainer.start(); | ||
_connectorContainer.start(); | ||
_connectorContainer.followOutput(new Slf4jLogConsumer(logger)); | ||
|
||
connectorContainer.followOutput(new Slf4jLogConsumer(logger)); | ||
_targetContainer.start(); | ||
|
||
try { | ||
waitUntilContainerConnectedToNetwork(targetContainer, 5000); | ||
} | ||
catch (TimeoutException ex) { } | ||
} | ||
finally { | ||
targetContainer.close(); | ||
connectorContainer.close(); | ||
try { | ||
// Wait to make sure the container is not connected to the network | ||
waitFor(Duration.ofSeconds(5), () -> isConnectedToNetwork(_targetContainer)); | ||
} | ||
} | ||
|
||
private GenericContainer createConnectorContainer() { | ||
return new GenericContainer<>(getConnectorImageTag()) | ||
.withFileSystemBind("//var/run/docker.sock", "/var/run/docker.sock") | ||
.withImagePullPolicy(new NeverPullImagePolicy()) | ||
.withEnv("LOG_LEVEL", "debug") | ||
.waitingFor(Wait.forLogMessage(".*Started, waiting for signal.*", 1)); | ||
catch (TimeoutException ex) { } | ||
} | ||
} |
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
11 changes: 0 additions & 11 deletions
11
tests/src/test/java/PullPolicies/NeverPullImagePolicy.java
This file was deleted.
Oops, something went wrong.
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,10 @@ | ||
package helpers; | ||
|
||
import io.homecentr.testcontainers.images.EnvironmentImageTagResolver; | ||
import io.homecentr.testcontainers.images.SystemWrapperImpl; | ||
|
||
public class DockerImageTagResolver extends EnvironmentImageTagResolver { | ||
public DockerImageTagResolver() { | ||
super(new SystemWrapperImpl(), "homecentr/swarm-local-network-connector:local"); | ||
} | ||
} |