Skip to content

Commit

Permalink
JIM 2.1, Imrpoved Tests, JSM Deploy imrpovments (#34)
Browse files Browse the repository at this point in the history
* Container.groovy
 * Now waits for engine to report created

JsmH2Deployment.groovy
 * Now waits for Jira to become responsive

DockerClientDS.groovy
 * New method for deleting images

Improved reliability of several tests

Updated JIM to 2.1.1
Updated docker client to 2023-12-01T19-40-00
Udpated gmavenplus-plugin to 3.0.2

* Tweaking
  • Loading branch information
farthinder authored Jan 22, 2024
1 parent 626f4a6 commit 46bc95b
Show file tree
Hide file tree
Showing 18 changed files with 188 additions and 160 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/publish-maven-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ jobs:
mkdir -p repository/com/eficode/devstack-standalone
echo Building and installing "normal" version
mvn install -f pom.xml -DcreateChecksum=true
mvn install -f pom.xml -DcreateChecksum=true -DskipTests
echo Creating pom for standalone version and installing
mvn gplus:execute@execute
mvn install -f pom-standalone.xml -DcreateChecksum=true
mvn install -f pom-standalone.xml -DcreateChecksum=true -DskipTests


- name: Copying JAR files
run: |
Expand Down
52 changes: 23 additions & 29 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.eficode</groupId>
<artifactId>devstack</artifactId>
<version>2.3.12-SNAPSHOT</version>
<version>2.3.13</version>
<packaging>jar</packaging>

<name>DevStack</name>
Expand Down Expand Up @@ -102,31 +102,18 @@
<dependency>
<groupId>com.eficode.atlassian</groupId>
<artifactId>jirainstancemanager</artifactId>
<version>2.0.3-SNAPSHOT</version>
<version>2.1.1</version>
</dependency>


<!-- https://mvnrepository.com/artifact/de.gesellix/docker-client -->
<dependency>
<groupId>de.gesellix</groupId>
<artifactId>docker-client</artifactId>
<version>2023-08-16T08-25-00</version>
<version>2023-12-01T19-40-00</version>
</dependency>


<!--dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.9.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.9.0</version>
<scope>test</scope>
</dependency-->

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand Down Expand Up @@ -179,10 +166,29 @@
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
<configuration>
<useFile>false</useFile>
<includes>
<include>**/*Test</include>
<include>**/*Spec</include>
</includes>
<statelessTestsetReporter implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5Xml30StatelessReporter">
<disable>false</disable>
<version>3.0</version>
<usePhrasedFileName>false</usePhrasedFileName>
<usePhrasedTestSuiteClassName>true</usePhrasedTestSuiteClassName>
<usePhrasedTestCaseClassName>true</usePhrasedTestCaseClassName>
<usePhrasedTestCaseMethodName>true</usePhrasedTestCaseMethodName>
</statelessTestsetReporter>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>2.0.0</version>
<version>3.0.2</version>
<executions>
<execution>
<goals>
Expand Down Expand Up @@ -213,18 +219,6 @@
</scripts>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M7</version>
<configuration>
<includes>
<include>**/*Spec.class</include>
<include>**/*Test.java</include>
</includes>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
11 changes: 11 additions & 0 deletions src/main/groovy/com/eficode/devstack/container/Container.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,17 @@ trait Container {
assert setContainerNetworks(networks): "Error setting container networks to:" + containerDefaultNetworks

containerId = response.content.id

long createTimeoutMs = 10000
long createWaitStart = System.currentTimeMillis()

while (!created && (createWaitStart + createTimeoutMs ) > System.currentTimeMillis()) {
sleep(1000)
}
if (!created) {
log.warn("Timed out waiting for container to be created: " + containerId)
}

return containerId

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class JsmAndBitbucketH2Deployment implements Deployment {
bitbucketH2Deployment.setBitbucketLicence(bitbucketLicense)

jsmH2Deployment.deploymentNetworkName = this.containerNetworkName

bitbucketH2Deployment.deploymentNetworkName = this.containerNetworkName
jsmContainer.createBridgeNetwork(this.containerNetworkName)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class JsmH2Deployment implements Deployment{
this.containers = [new JsmContainer(dockerHost, dockerCertPath)]
jsmContainer.containerMainPort = jsmContainer.extractPortFromUrl(jiraBaseUrl)
jsmContainer.containerName = jsmContainer.extractDomainFromUrl(jiraBaseUrl)

}

JsmContainer getJsmContainer() {
Expand Down Expand Up @@ -138,7 +139,7 @@ class JsmH2Deployment implements Deployment{

jsmContainer.containerDefaultNetworks = [deploymentNetworkName]
jsmContainer.createContainer()
log.info("\tCreated jsm container:" + jsmContainer.id)
log.info("*\tCreated jsm container:" + jsmContainer.id)

assert jsmContainer.startContainer() : "Error starting JSM container:" + jsmContainer.id
log.info("\tStarted JSM container")
Expand All @@ -147,6 +148,8 @@ class JsmH2Deployment implements Deployment{
String cmdJiraConfigProperties = "echo \"jira.websudo.is.disabled=true\" >> jira-config.properties; chown jira:jira jira-config.properties && echo status: \$?"
assert jsmContainer.runBashCommandInContainer(cmdJiraConfigProperties).find {it == "status: 0"} : "Error creating jira-config.properties file"

log.info("\tWaiting for JIRA to startup")
jiraRest.waitForJiraToBeResponsive()
log.info("\tSetting up local H2 database")
assert jiraRest.setupH2Database() : "Error setting up H2 database for JSM"
log.info("\t\tDatabase setup successfully")
Expand Down
26 changes: 21 additions & 5 deletions src/main/groovy/com/eficode/devstack/util/DockerClientDS.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import de.gesellix.docker.remote.api.ContainerSummary
import de.gesellix.docker.remote.api.ExecConfig
import de.gesellix.docker.remote.api.ExecStartConfig
import de.gesellix.docker.remote.api.IdResponse
import de.gesellix.docker.remote.api.ImageDeleteResponseItem
import de.gesellix.docker.remote.api.SystemInfo
import de.gesellix.docker.remote.api.Volume
import de.gesellix.docker.remote.api.VolumeCreateOptions
Expand Down Expand Up @@ -121,11 +122,11 @@ class DockerClientDS extends DockerClientImpl {
* @return true on success
*/
boolean overwriteVolume(String srcVolumeName, String destinationVolumeName) {
ArrayList<Volume>srcVolumes = getVolumesWithName(srcVolumeName)
assert srcVolumes.size() == 1 : "Error identifying src volume with name:" + srcVolumeName
ArrayList<Volume> srcVolumes = getVolumesWithName(srcVolumeName)
assert srcVolumes.size() == 1: "Error identifying src volume with name:" + srcVolumeName

ArrayList<Volume>destVolumes = getVolumesWithName(destinationVolumeName)
assert destVolumes.size() == 1 : "Error identifying destination volume with name:" + destinationVolumeName
ArrayList<Volume> destVolumes = getVolumesWithName(destinationVolumeName)
assert destVolumes.size() == 1: "Error identifying destination volume with name:" + destinationVolumeName


return overwriteVolume(srcVolumes.first(), destVolumes.first())
Expand Down Expand Up @@ -242,11 +243,26 @@ class DockerClientDS extends DockerClientImpl {
String execId = execCreateResult.content.id
ExecStartConfig execStartConfig = new ExecStartConfig(
(execConfig.detachKeys ?: false) as Boolean,
execConfig.tty
execConfig.tty,
execConfig.consoleSize
)


startExec(execId, execStartConfig, callback, timeout)
return execCreateResult

}


EngineResponseContent<List<ImageDeleteResponseItem>> deleteImage(String imageName, String imageTag) {

String preExistingImage = manageImage.findImageId(imageName, imageTag)
if (preExistingImage && preExistingImage.startsWith("sha256")) {
return manageImage.rmi(preExistingImage)
}

return null

}

}
4 changes: 2 additions & 2 deletions src/main/groovy/com/eficode/devstack/util/ImageBuilder.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ class ImageBuilder extends DoodContainer {
String artifactName = "atlassian-servicedesk"
String archType = dockerClient.engineArch
String imageTag = "$imageName:$jsmVersion-$archType"
containerName = imageTag.replaceAll(/[^a-zA-Z0-9_.-]/, "-").take(128-"-imageBuilder".length())
containerName += "-imageBuilder"
containerName = "jsm-builder-$jsmVersion-$archType".replaceAll(/[^a-zA-Z0-9_.-]/, "-")


//Check first if an image with the expected tag already exists
if (!force) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class ContainerTest extends DevStackSpec {
def setupSpec() {


dockerRemoteHost = "https://docker.domain.se:2376"
dockerCertPath = "~/.docker/"
//dockerRemoteHost = "https://docker.domain.se:2376"
//dockerCertPath = "~/.docker/"


log = LoggerFactory.getLogger(ContainerTest.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class BitbucketContainerTest extends DevStackSpec {


def setupSpec() {
dockerRemoteHost = "https://docker.domain.se:2376"
dockerCertPath = "~/.docker/"
//dockerRemoteHost = "https://docker.domain.se:2376"
//dockerCertPath = "~/.docker/"


log = LoggerFactory.getLogger(BitbucketContainerTest.class)
Expand Down Expand Up @@ -46,20 +46,19 @@ class BitbucketContainerTest extends DevStackSpec {
assert containerInspect.name == "/" + bbc.containerName: "BB was not given the expected name"
assert containerInspect.state.status == ContainerState.Status.Created: "BB Container status is of unexpected value"
assert containerInspect.state.running == false: "BB Container was started even though it should only have been created"
assert dockerClient.inspectImage(containerInspect.image).content.repoTags.find { it == "atlassian/bitbucket:latest" }: "BB container was created with incorrect Docker image"
assert dockerClient.inspectImage(containerInspect.image).content.repoTags.find { it == "atlassian/bitbucket:latest" || it.contains("atlassian/bitbucket:${BitbucketContainer.getLatestBbVersion()}") }: "BB container was created with incorrect Docker image"
assert containerInspect.hostConfig.portBindings.containsKey("7990/tcp"): "BB Container port binding was not setup correctly"
log.info("\tBB Container was setup correctly")

expect:
bbc.startContainer()
bbr.setApplicationProperties(new File("resources/bitbucket/licenses/bitbucketLicense").text)
bbr.setApplicationProperties(new File(System.getProperty("user.home") + "/.licenses/bitbucket/bitbucket.license").text)
bbr.status == "RUNNING"


where:
dockerHost | certPath | baseUrl
"" | "" | "http://localhost:7990"
dockerRemoteHost | dockerCertPath | "http://bitbucket.domain.se:7990"


}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ class DoodContainerTest extends DevStackSpec {

def setupSpec() {

dockerRemoteHost = "https://docker.domain.se:2376"
dockerCertPath = "~/.docker/"
//dockerRemoteHost = "https://docker.domain.se:2376"
//dockerCertPath = "~/.docker/"


DevStackSpec.log = LoggerFactory.getLogger(DoodContainerTest.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ class JenkinsContainerTest extends DevStackSpec{

def setupSpec() {

dockerRemoteHost = "https://docker.domain.se:2376"
dockerCertPath = "~/.docker/"
dockerRemoteHost = ""
dockerCertPath = ""

DevStackSpec.log = LoggerFactory.getLogger(JenkinsContainerTest.class)



cleanupContainerNames = ["jenkins.domain.se", "jenkins-agent.domain.se", "localhost"]
cleanupContainerPorts = [8080, 50000]

Expand Down Expand Up @@ -95,7 +96,7 @@ class JenkinsContainerTest extends DevStackSpec{
where:
dockerHost | certPath | baseUrl
"" | "" | "http://localhost:8080"
dockerRemoteHost | dockerCertPath | "http://jenkins.domain.se:8080"




Expand Down
Loading

0 comments on commit 46bc95b

Please sign in to comment.