Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jlahtinen committed Nov 21, 2023
1 parent 626f4a6 commit 3895d98
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 20 deletions.
4 changes: 2 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.12-SNAPSHOT</version>
<version>2.3.13-SNAPSHOT</version>
<packaging>jar</packaging>

<name>DevStack</name>
Expand Down Expand Up @@ -228,4 +228,4 @@
</plugins>
</build>

</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -974,4 +974,4 @@ trait Container {
return callBack.output
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,25 @@ class JsmContainer implements Container {

@Override
ContainerCreateRequest setupContainerCreateRequest() {

String image = containerImage + ":" + containerImageTag

log.debug("Setting up container create request for JSM container")
if (dockerClient.engineArch != "x86_64") {
log.debug("\tDocker engine is not x86, building custom JSM docker image")

ImageBuilder imageBuilder = new ImageBuilder(dockerClient.host, dockerClient.certPath)
String jsmVersion = containerImageTag
if (jsmVersion == "latest") {
log.debug("\tCurrent image tag is set to \"latest\", need to resolve latest version number from Atlassian Marketplace in order to build custom image")
jsmVersion = getLatestJsmVersion()
}
log.debug("\tStarting building of Docker Image for JSM verion $jsmVersion")
ImageSummary newImage = imageBuilder.buildJsm(jsmVersion)
log.debug("\tFinished building custom image:" + newImage.repoTags.join(","))

image = newImage.repoTags.first()
new ImageBuilder(dockerClient.host, dockerClient.certPath)
String jsmVersion = containerImageTag
if (jsmVersion == "latest") {
log.debug("\tCurrent image tag is set to \"latest\", need to resolve latest version number from Atlassian Marketplace in order to build custom image")
jsmVersion = getLatestJsmVersion()
}
log.debug("\tStarting building of Docker Image for JSM verion $jsmVersion")
ImageSummary jsmImage = new ImageBuilder(dockerClient.host, dockerClient.certPath).buildJsm(jsmVersion)
log.debug("\tFinished building custom image:" + jsmImage.repoTags.join(","))

sleep(120 * 1000)

log.debug("\tStarting building of Docker Image for faketime JSM verion $jsmVersion")
ImageSummary faketimeJsmImage = new ImageBuilder(dockerClient.host, dockerClient.certPath).buildFaketimeJsm(jsmVersion)
log.debug("\tFinished building custom image:" + faketimeJsmImage.repoTags.join(","))

String image = faketimeJsmImage.repoTags.first()

ContainerCreateRequest containerCreateRequest = new ContainerCreateRequest().tap { c ->

Expand Down
43 changes: 42 additions & 1 deletion src/main/groovy/com/eficode/devstack/util/ImageBuilder.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class ImageBuilder extends DoodContainer {
* @return
*/
ImageSummary buildJsm(String jsmVersion, boolean force = false){

String imageName = "atlassian/jira-servicemanagement"
String artifactName = "atlassian-servicedesk"
String archType = dockerClient.engineArch
Expand Down Expand Up @@ -76,7 +75,49 @@ class ImageBuilder extends DoodContainer {
ImageSummary newImage = images.find {it.repoTags == [imageTag]}
log.debug("\tFinished building image:" + imageTag + ", ID:" + newImage.id[7..17])
return newImage
}

ImageSummary buildFaketimeJsm(String jsmVersion, boolean force = false){
String imageName = "atlassian/jira-servicemanagement"
String artifactName = "atlassian-servicedesk"
String archType = dockerClient.engineArch
String imageTag = "$imageName:$jsmVersion-$archType"
String faketimeDockerFilePath = "/faketimebuild/Dockerfile"
String faketimeImageTag = "$imageName-faketime:$jsmVersion-$archType"
containerName = faketimeImageTag.replaceAll(/[^a-zA-Z0-9_.-]/, "-").take(128-"-imageBuilder".length())
containerName += "-imageBuilder"

log.info("my name is now $containerName")

//Check first if an image with the expected tag already exists
if (!force) {
ArrayList<ImageSummary> existingImages = dockerClient.images().content
ImageSummary existingImage = existingImages.find {it.repoTags == [faketimeImageTag]}
if (existingImage) {
return existingImage
}
}

String faketimeDockerFile = """
FROM $imageTag
WORKDIR /
RUN apt-get update && apt-get install -y wget g++ make
RUN wget https://github.com/odnoklassniki/jvmti-tools/raw/master/faketime/faketime.cpp
RUN g++ -O2 -fPIC -shared -I \$JAVA_HOME/include -I \$JAVA_HOME/include/linux -olibfaketime.so faketime.cpp
ENV JVM_SUPPORT_RECOMMENDED_ARGS="-agentpath:/libfaketime.so=+2592000000"
"""

putBuilderCommand("mkdir -p /faketimebuild", "status:0")
putBuilderCommand("cat > $faketimeDockerFilePath <<- 'EOF'\n" + faketimeDockerFile + "\nEOF", "") // TODO: 2nd argument?
putBuilderCommand("cd /faketimebuild && docker build --tag $faketimeImageTag --build-arg JIRA_VERSION=$jsmVersion --build-arg ARTEFACT_NAME=$artifactName . && echo status:\$?", "status:0")
putBuilderCommand("pkill tail", "")

assert build() : "Error building the image."

ArrayList<ImageSummary> images = dockerClient.images().content
ImageSummary newImage = images.find {it.repoTags == [faketimeImageTag]}
return newImage
}


Expand Down

0 comments on commit 3895d98

Please sign in to comment.