Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/publish-maven-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created
# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#apache-maven-with-a-settings-path

name: Publish Maven Package

on:
workflow_dispatch:
push:
branches:
- master

jobs:
build:

runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file

- name: Compile Groovy code
run: mvn gplus:compile

- name: Publish Package to Github Maven Repo
run: mvn deploy -s $GITHUB_WORKSPACE/settings.xml
env:
GITHUB_TOKEN: ${{ github.token }}
10 changes: 10 additions & 0 deletions .idea/jarRepositories.xml

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

7 changes: 7 additions & 0 deletions examples/Basic JSM Setup.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import com.eficode.devstack.deployment.impl.JsmH2Deployment

String jiraBaseUrl = "http://localhost:8080"
JsmH2Deployment jsmDep = new JsmH2Deployment(jiraBaseUrl)
File projectRoot = new File(".")
jsmDep.setJiraLicense(new File(projectRoot.path + "/resources/jira/licenses/jsm.license"))
jsmDep.setupDeployment()
41 changes: 36 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
<groupId>com.eficode</groupId>
<artifactId>devstack</artifactId>
<version>1.0-SNAPSHOT</version>
<description>A series of scripts for setting up common developer application suites</description>

<distributionManagement>
<repository>
<id>github</id>
<name>Eficode Devstack</name>
<url>https://maven.pkg.github.com/eficode/devStack</url>
</repository>
</distributionManagement>

<dependencies>
<!-- https://mvnrepository.com/artifact/org.codehaus.groovy/groovy-all -->
Expand Down Expand Up @@ -49,12 +58,38 @@
<version>3.13.6</version>
<classifier>standalone</classifier>
</dependency>
<dependency>
<groupId>com.eficode.atlassian</groupId>
<artifactId>jirainstancemanger</artifactId>
<version>1.0.1-SNAPSHOT</version>
</dependency>


</dependencies>

<repositories>
<repository>
<id>eficode-github-jiraManagerRest</id>
<url>https://github.com/eficode/JiraInstanceMangerRest/raw/pre_v1_tweaks/repository/</url>
</repository>
</repositories>
<build>
<sourceDirectory>${basedir}/src/main/groovy</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>attach-sources</id>
<phase>generate-sources</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
Expand All @@ -74,11 +109,7 @@
<scope>runtime</scope>
</dependency>
</dependencies>
<configuration>
<scripts>
<script>src/main/groovy/Main.groovy</script>
</scripts>
</configuration>

</plugin>
</plugins>
</build>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import java.nio.file.Files
import java.nio.file.Path
import java.time.Duration

trait ContainerManager {
trait Container {

static Logger log = LoggerFactory.getLogger(ContainerManager.class)
static Logger log = LoggerFactory.getLogger(Container.class)
static DockerClientImpl dockerClient = new DockerClientImpl()
abstract String containerName
abstract String containerMainPort
Expand All @@ -42,22 +42,44 @@ trait ContainerManager {
* @param host ex: "https://docker.domain.se:2376"
* @param certPath folder containing ca.pem, cert.pem, key.pem
*/
static DockerClientImpl setupSecureRemoteConnection(String host, String certPath) {
boolean setupSecureRemoteConnection(String host, String certPath) {

DockerClientConfig dockerConfig = new DockerClientConfig(host)
DockerEnv dockerEnv = new DockerEnv(host)
dockerEnv.setCertPath(certPath)
dockerEnv.setTlsVerify("1")
dockerConfig.apply(dockerEnv)

return new DockerClientImpl(dockerConfig)
dockerClient = new DockerClientImpl(dockerConfig)
return ping()

}


boolean ping() {
return dockerClient.ping().content as String == "OK"
try {
return dockerClient.ping().content as String == "OK"
}catch(SocketException ex) {
log.warn("Failed to ping Docker engine:" + ex.message)
return false
}

}




boolean isCreated(){

ArrayList<Map> content = dockerClient.ps().content
ArrayList<String> containerNames = content.collect {it.Names}.flatten()
return containerNames.find{ it == "/" + getContainerName()} != null

}

String getId() {
return containerId
}

String getContainerId() {

if (containerId) {
Expand Down Expand Up @@ -101,6 +123,18 @@ trait ContainerManager {

}

boolean stopContainer() {
log.info("Stopping container:" + containerId)
dockerClient.stop(containerId, 240000)
if (dockerClient.inspectContainer(containerId).content.state.running) {
log.warn("\tFailed to stop container" + containerId)
return false
}else {
log.info("\tContainer stopped")
return true
}
}




Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package com.eficode.devstack.container.impl

import com.eficode.devstack.container.ContainerManager
import com.eficode.devstack.container.Container
import de.gesellix.docker.client.EngineResponseContent
import de.gesellix.docker.remote.api.ContainerCreateRequest
import de.gesellix.docker.remote.api.HostConfig
import de.gesellix.docker.remote.api.PortBinding

class JsmContainer implements ContainerManager{
class JsmContainer implements Container{

String containerName = "JSM-H2"
String containerName = "JSM"
String containerMainPort = "8080"
String containerImage = "atlassian/jira-servicemanagement"
String containerImageTag = "latest"
long jvmMaxRam = 6000

JsmContainer() {}
Expand All @@ -20,7 +22,7 @@ class JsmContainer implements ContainerManager{
* @param dockerCertPath ex: src/test/resources/dockerCert
*/
JsmContainer(String dockerHost, String dockerCertPath) {
dockerClient = setupSecureRemoteConnection(dockerHost, dockerCertPath)
assert setupSecureRemoteConnection(dockerHost, dockerCertPath) : "Error setting up secure remote docker connection"
}


Expand All @@ -31,7 +33,7 @@ class JsmContainer implements ContainerManager{

}

String createJsmContainer(String jsmContainerName = containerName, String imageName = "atlassian/jira-servicemanagement", String imageTag = "latest", long jsmMaxRamMB = jvmMaxRam, String jsmPort = containerMainPort) {
String createJsmContainer(String jsmContainerName = containerName, String imageName = containerImage, String imageTag = containerImageTag, long jsmMaxRamMB = jvmMaxRam, String jsmPort = containerMainPort) {

assert dockerClient.ping().content as String == "OK", "Error Connecting to docker service"

Expand Down
57 changes: 57 additions & 0 deletions src/main/groovy/com/eficode/devstack/deployment/Deployment.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.eficode.devstack.deployment

import com.eficode.devstack.container.Container
import org.slf4j.Logger
import org.slf4j.LoggerFactory

trait Deployment {

static Logger log = LoggerFactory.getLogger(Deployment.class)
abstract ArrayList<Container> containers
abstract String friendlyName


abstract boolean setupDeployment()

void setupSecureDockerConnection(String host, String certPath) {

log.info("Setting up secure connection to docker engine")
assert getContainers() != null && !getContainers().empty : "Deployment has no containers defined"
//assert getContainers().any{! it.ping()} : "Connection has already been established."
//assert getContainers().created.each {!it} : "Cant setup secure connection when containers have already been created in docker engine"


getContainers().each {
assert it.setupSecureRemoteConnection(host, certPath) : "Error setting up secure connection to docker engine"
log.info("\tSecure connection setup for container:" + getFriendlyName())
}
log.info("\tSuccessfully setup secure connections to docker engine")
}


boolean startDeployment() {
log.info("Starting deployment:" + friendlyName)

containers.each {container ->
log.debug("\tStarting:" + container.containerName)
assert container.startContainer() : "Error starting container:" + container.containerId
}

log.info("\tFinished starting deployment")
return true

}

boolean stopDeployment() {
log.info("Stopping deployment:" + friendlyName)

containers.each {container ->
log.debug("\tStopping:" + container.containerName)
assert container.stopContainer() : "Error stopping container:" + container.containerId
}

log.info("\tFinished stopping deployment")
return true

}
}
Loading