Skip to content

Commit

Permalink
Merge pull request #45 from eficode/2.3.24
Browse files Browse the repository at this point in the history
2.3.24
  • Loading branch information
farthinder authored May 23, 2024
2 parents 9690768 + 3fa7c05 commit 2813837
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 35 deletions.
5 changes: 5 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 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.23</version>
<version>2.3.24</version>
<packaging>jar</packaging>

<name>DevStack</name>
Expand All @@ -23,7 +23,7 @@
<spock-core.version>2.3-groovy-${groovy.major.version}</spock-core.version>
<jiraShortcuts.version>2.0.3-SNAPSHOT-groovy-3.0</jiraShortcuts.version>
<bitbucketinstancemanager.version>0.0.3-SNAPSHOT-groovy-3.0</bitbucketinstancemanager.version>
<jirainstancemanager.version>2.1.9</jirainstancemanager.version>
<jirainstancemanager.version>2.1.10</jirainstancemanager.version>
</properties>


Expand Down Expand Up @@ -135,6 +135,10 @@
<id>eficode-github-jiraManagerRest</id>
<url>https://github.com/eficode/JiraInstanceManagerRest/raw/packages/repository/</url>
</repository>
<repository>
<id>eficode-github-remoteSpock</id>
<url>https://github.com/eficode/remoteSpock/raw/packages/repository/</url>
</repository>
<repository>
<id>eficode-github-BitbucketInstanceManagerRest</id>
<url>https://github.com/eficode/BitbucketInstanceManagerRest/raw/packages/repository/</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class JsmDevDeployment implements Deployment {
Volume allureReportVolume
DirectorySyncer reportSyncer

private Builder builder

DockerClientDS dockerClient

//Used when naming various Docker components
Expand All @@ -35,36 +37,23 @@ class JsmDevDeployment implements Deployment {
JsmDevDeployment(String jiraBaseUrl, String dockerHost, String dockerCertPath, ArrayList<String> srcCodePaths) {

componentsPrefix = AllureContainer.extractDomainFromUrl(jiraBaseUrl)
subDeployments.add(new JsmH2Deployment(jiraBaseUrl, dockerHost, dockerCertPath))


allureContainer = new AllureContainer(dockerHost, dockerCertPath)
allureContainer.containerName = componentsPrefix + "-reporter"
dockerClient = allureContainer.dockerClient


allureReportVolume = dockerClient.getOrCreateVolume(componentsPrefix + "-allureReports")
jiraReportVolume = dockerClient.getOrCreateVolume(componentsPrefix + "-jiraReports")
allureContainer.prepareCustomEnvVar(["CHECK_RESULTS_EVERY_SECONDS=3", "KEEP_HISTORY=1", "KEEP_HISTORY_LATEST=30"])
allureContainer.setResultsVolume(allureReportVolume.name)


srcCodeVolume = dockerClient.getOrCreateVolume(componentsPrefix + "-code")
srcSyncer = DirectorySyncer.getDuplicateContainer(dockerClient, "SrcSyncer")
this.srcCodePaths = srcCodePaths
reportSyncer = DirectorySyncer.getDuplicateContainer(dockerClient, "ReportSyncer")

if (srcSyncer?.created) {
log.warn("Old SrcSyncer container exists, removing it before proceeding")
srcSyncer.stopAndRemoveContainer()
srcSyncer = null
}


subDeployments.add(new JsmH2Deployment(jiraBaseUrl, dockerHost, dockerCertPath))
jsmDeployment.jsmContainer.prepareVolumeMount(srcCodeVolume.name, "/var/atlassian/application-data/jira/scripts/", false)
jsmDeployment.jsmContainer.prepareVolumeMount(jiraReportVolume.name, "/var/atlassian/application-data/jira/allure-results/", false)

this.srcCodePaths = srcCodePaths

}


JsmH2Deployment getJsmDeployment() {
return subDeployments.find { it instanceof JsmH2Deployment } as JsmH2Deployment
}
Expand All @@ -91,7 +80,8 @@ class JsmDevDeployment implements Deployment {

try {
jsmSnapshotVolume = jsmContainer.getSnapshotVolume()
}catch (ignored){}
} catch (ignored) {
}


Boolean success = Deployment.super.stopAndRemoveDeployment()
Expand All @@ -118,22 +108,35 @@ class JsmDevDeployment implements Deployment {
boolean setupDeployment() {


srcSyncer = DirectorySyncer.createSyncToVolume(srcCodePaths, srcCodeVolume.name, "SrcSyncer", "-avh --chown=2001:2001")

srcCodeVolume = dockerClient.getOrCreateVolume(componentsPrefix + "-code")
allureReportVolume = dockerClient.getOrCreateVolume(componentsPrefix + "-allureReports")
jiraReportVolume = dockerClient.getOrCreateVolume(componentsPrefix + "-jiraReports")


srcSyncer = DirectorySyncer.createSyncToVolume(srcCodePaths, srcCodeVolume.name, "SrcSyncer", "-avh --chown=2001:2001")
reportSyncer = DirectorySyncer.syncBetweenVolumesAndUsers(jiraReportVolume.name, allureReportVolume.name, "1000:1000", "ReportSyncer")


allureContainer.prepareCustomEnvVar(["CHECK_RESULTS_EVERY_SECONDS=3", "KEEP_HISTORY=1", "KEEP_HISTORY_LATEST=30"])
allureContainer.setResultsVolume(allureReportVolume.name)


allureContainer.created ?: allureContainer.createContainer()
allureContainer.startContainer()

if (!jsmDeployment.jsmContainer.created) {
jsmDeployment.jsmContainer.prepareVolumeMount(srcCodeVolume.name, "/var/atlassian/application-data/jira/scripts/", false)
jsmDeployment.jsmContainer.prepareVolumeMount(jiraReportVolume.name, "/var/atlassian/application-data/jira/allure-results/", false)

jsmDeployment.setupDeployment(true, true)
}

jsmDeployment.setupDeployment(builder.useSnapshotIfAvailable, builder.snapshotAfterCreation)
//Change owner of the mounted volume
jsmContainer.runBashCommandInContainer("chown -R jira:jira /var/atlassian/application-data/jira/allure-results", 10, "root")

if (jsmDeployment.jiraRest.scriptRunnerIsInstalled()) {
jsmDeployment.jiraRest.deploySpockEndpoint(['com.riadalabs.jira.plugins.insight' ])
jsmDeployment.jiraRest.deploySpockEndpoint(['com.riadalabs.jira.plugins.insight'])
}

}
Expand All @@ -145,6 +148,8 @@ class JsmDevDeployment implements Deployment {
private String jsmVersion = "latest"
private String jsmJvmDebugPort = "5005"
private Boolean enableJsmDooD = false
private Boolean useSnapshotIfAvailable = false
private Boolean snapshotAfterCreation = false

private Map<String, String> appsToInstall = [:]

Expand Down Expand Up @@ -194,6 +199,16 @@ class JsmDevDeployment implements Deployment {
return this
}

Builder useSnapshotIfAvailable() {
this.useSnapshotIfAvailable = true
return this
}

Builder snapshotAfterCreation() {
this.snapshotAfterCreation = true
return this
}


JsmDevDeployment build() {

Expand All @@ -207,7 +222,7 @@ class JsmDevDeployment implements Deployment {
devDeployment.jsmDeployment.jsmContainer.prepareBindMount("/var/run/docker.sock", "/var/run/docker.sock", false)
}
devDeployment.jsmDeployment.appsToInstall = this.appsToInstall

devDeployment.builder = this

return devDeployment

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,30 +85,45 @@ class JsmDevDeploymentSpec extends DevStackSpec {
JiraInstanceManagerRest jim = new JiraInstanceManagerRest(baseUrl)


when:
when: "When seting up the builder and running stopAndRemove"
JsmDevDeployment jsmDevDep = new JsmDevDeployment.Builder(baseUrl, jsmLicenseFile.text, [localSrcDir.canonicalPath])
.setJsmJvmDebugPort("5005")
.setJsmVersion("latest")
.enableJsmDood()
.addAppToInstall(MarketplaceApp.getScriptRunnerVersion().downloadUrl, srLicenseFile.text)
.snapshotAfterCreation()
.useSnapshotIfAvailable()
.build()


jsmDevDep.stopAndRemoveDeployment()

then: "None of the parts should exist"
!jsmDevDep.jsmContainer?.created
!jsmDevDep.allureContainer?.created
!jsmDevDep.reportSyncer?.created
!jsmDevDep.srcSyncer?.created
!jsmDevDep.allureReportVolume?.usageData?.propertySize
!jsmDevDep.srcCodeVolume?.usageData?.propertySize


when:
Long initialSetupDuration = System.currentTimeMillis()
jsmDevDep.setupDeployment()
initialSetupDuration = System.currentTimeMillis() - initialSetupDuration
ArrayList<ContainerSummary> containersAfter = getContainers()


then:
containersAfter.find {it.names.toString().contains("spockdev.localhost")}
containersAfter.find {it.names.toString().contains("spockdev.localhost-reporter")}
containersAfter.find {it.names.toString().contains("ReportSyncer")}
containersAfter.find {it.names.toString().contains("SrcSyncer")}
containersAfter.find { it.names.toString().contains("spockdev.localhost") }
containersAfter.find { it.names.toString().contains("spockdev.localhost-reporter") }
containersAfter.find { it.names.toString().contains("ReportSyncer") }
containersAfter.find { it.names.toString().contains("SrcSyncer") }


when: "Creating a file in the local synced dir"

File localTestFile = new File(localSrcDir, "com/eficode/atlassian/jira/jiraLocalScripts/JiraLocalSpockTest.groovy")
File localTestFile = new File(localSrcDir, "com/eficode/atlassian/jira/jiraLocalScripts/JiraLocalSpockTest.groovy")
localTestFile.createParentDirectories()
localTestFile.text = getSuccessfulSpockBody()
sleep(2000)
Expand All @@ -119,22 +134,35 @@ class JsmDevDeploymentSpec extends DevStackSpec {
expect:
jsmDevDep.jsmContainer.appAppUploadEnabled
jsmDevDep.jsmContainer.enableJvmDebug() == null
assert jim.isSpockEndpointDeployed(true) : "Spock endpoint was not deployed"
assert jim.isSpockEndpointDeployed(true): "Spock endpoint was not deployed"

when:"Running spocktest"
when: "Running spocktest"
jim.runSpockTest("com.eficode.atlassian.jira.jiraLocalScripts.JiraLocalSpockTest", "", SpockOutputType.AllureReport, "allure-results/")
sleep(2000)
then:
jsmDevDep.allureContainer.runBashCommandInContainer("ls -l /app/allure-results/")
assert jsmDevDep.jsmContainer.runBashCommandInContainer("ls allure-results").first().split("\n").every { reportName ->
jsmDevDep.allureContainer.runBashCommandInContainer("ls /app/allure-results/$reportName && echo Status: \$?").toString().contains("Status: 0")
} : "All Reports in JIRA container haven't been synced to Allure container"
}: "All Reports in JIRA container haven't been synced to Allure container"


when:"When triggering another setup of the same deployment"
String jsmCreatedTimestamp = jsmDevDep.jsmContainer.inspectContainer().created
String reportSyncerCreatedTimestamp = jsmDevDep.reportSyncer.inspectContainer().created
String srcSyncerCreatedTimestamp = jsmDevDep.srcSyncer.inspectContainer().created
Long snapshotSetupDuration = System.currentTimeMillis()
jsmDevDep.setupDeployment()
snapshotSetupDuration = System.currentTimeMillis() - snapshotSetupDuration

then: "Snapshot should be restored and containers remain the same"
jsmCreatedTimestamp == jsmDevDep.jsmContainer.inspectContainer().created
reportSyncerCreatedTimestamp == jsmDevDep.reportSyncer.inspectContainer().created
srcSyncerCreatedTimestamp == jsmDevDep.srcSyncer.inspectContainer().created
(snapshotSetupDuration * 2) < initialSetupDuration

cleanup:
jsmDevDep.stopAndRemoveDeployment()



}
}

0 comments on commit 2813837

Please sign in to comment.