Skip to content

Instantly share code, notes, and snippets.

@aslakknutsen
Last active August 29, 2015 14:07
Show Gist options
  • Save aslakknutsen/68c52e9b3a9ddb3d9ada to your computer and use it in GitHub Desktop.
Save aslakknutsen/68c52e9b3a9ddb3d9ada to your computer and use it in GitHub Desktop.
<arquillian>
<container qualifier="wildfly">
<configuration>
<property name="managementPort">9990</property>
</configuration>
</container>
<extension qualifier="docker">
<property name="suiteContainers">database/postgres</property>
<property name="controlledByDocker">wildfly:jboss/wildfly,mail/server</property>
</extension>
</arquillian>
public class DockerObserver {
@Inject
private Instance<ArquillianDescriptor> desc;
@Inject
private Instance<ContainerRegistry> reg;
public void startDockerImage(@Observess(precedence = 0) BeforeSuite event) {
String[] dockerImageIds = getImageId();
if(dockerImageIds != null) {
for(Stirng dockerImageId : dockerImageIds) {
docker.startAndWaitForPort(dockerImageId);
}
}
}
public void stopDockerImage(@Observers AfterSuite event) {
String[] dockerImageIds = getImageId();
if(dockerImageIds != null) {
for(String dockerImageId : dockerImageIds) {
docker.stopAndWait(dockerImageId);
}
}
}
public void startDockerImage(@Observers BeforeStart event) {
String[] dockerImageIds = getImageIdForContainer(event.getContainer());
if(dockerImageIds != null) {
for(Stirng dockerImageId : dockerImageIds) {
String port = desc.get().getContainer().getProperty("managementPort") // figure out which port the container attempts to connect to
docker.startAndWaitForPort(dockerImageId, port);
}
}
}
public void stopDockerImage(@Observers AfterStop event) {
String[] dockerImageIds = getImageIdForContainer(event.getContainer());
if(dockerImageIds != null) {
for(String dockerImageId : dockerImageIds) {
docker.stopAndWait(dockerImageId);
}
}
}
public String[] getImageIdForContainer(Container c) {
return desc.get().getExtension().getProperty("controlledByDocker").contains(c.name()) // locate extension with name docker
}
public String[] getImageIds() {
return desc.get().getExtension().getProperty("suiteContainers").contains(c.name()) // locate extension with name docker
}
}
@lordofthejars
Copy link

Hi Aslak I have seen that this method event.getContainer() does not exist in BeforeStart event. The bad news is that at that point I need the Container to get configuration parameters to start a ping to given host and port until container is started inside Docker. Do I have any way to get it?

@aslakknutsen
Copy link
Author

@Inject
private Instance<ContainerRegistry> registryInst;

public void overrideContainerHostProperty(@Observes BeforeSetup event) {
  Container currentContainer = locateCurrentContainer(event.getDeployableContainer())   
  if(currentContainer == null) {
    throw new RuntimeException("No Container found in registry.. ?");
  }
  currentContainer.getContainerConfiguration().overrideProperty("name", docker2bootIP)
}

private Container locateCurrentContainer(DeployableContainer<?> deployable) {
  for(Container container : registryInst.get().getContainers()) {
    if(container.getDeployableContainer() == deployable) {
      return container;
    }
  }
  return null;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment