Skip to content

Commit fae85a8

Browse files
authored
Working on package (#1)
* Major work, most of the things for JSMH2 Deployment is working but untested * Added basic jsm example script * Added repo for JirInstanceManagerRest * Updated POM to generate sources
1 parent f77e194 commit fae85a8

13 files changed

Lines changed: 478 additions & 19 deletions

File tree

.github/publish-maven-package.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created
2+
# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#apache-maven-with-a-settings-path
3+
4+
name: Publish Maven Package
5+
6+
on:
7+
workflow_dispatch:
8+
push:
9+
branches:
10+
- master
11+
12+
jobs:
13+
build:
14+
15+
runs-on: ubuntu-latest
16+
permissions:
17+
contents: read
18+
packages: write
19+
20+
steps:
21+
- uses: actions/checkout@v3
22+
- name: Set up JDK 11
23+
uses: actions/setup-java@v3
24+
with:
25+
java-version: '11'
26+
distribution: 'temurin'
27+
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
28+
settings-path: ${{ github.workspace }} # location for the settings.xml file
29+
30+
- name: Compile Groovy code
31+
run: mvn gplus:compile
32+
33+
- name: Publish Package to Github Maven Repo
34+
run: mvn deploy -s $GITHUB_WORKSPACE/settings.xml
35+
env:
36+
GITHUB_TOKEN: ${{ github.token }}

.idea/jarRepositories.xml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/Basic JSM Setup.groovy

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import com.eficode.devstack.deployment.impl.JsmH2Deployment
2+
3+
String jiraBaseUrl = "http://localhost:8080"
4+
JsmH2Deployment jsmDep = new JsmH2Deployment(jiraBaseUrl)
5+
File projectRoot = new File(".")
6+
jsmDep.setJiraLicense(new File(projectRoot.path + "/resources/jira/licenses/jsm.license"))
7+
jsmDep.setupDeployment()

pom.xml

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@
77
<groupId>com.eficode</groupId>
88
<artifactId>devstack</artifactId>
99
<version>1.0-SNAPSHOT</version>
10+
<description>A series of scripts for setting up common developer application suites</description>
11+
12+
<distributionManagement>
13+
<repository>
14+
<id>github</id>
15+
<name>Eficode Devstack</name>
16+
<url>https://maven.pkg.github.com/eficode/devStack</url>
17+
</repository>
18+
</distributionManagement>
1019

1120
<dependencies>
1221
<!-- https://mvnrepository.com/artifact/org.codehaus.groovy/groovy-all -->
@@ -49,12 +58,38 @@
4958
<version>3.13.6</version>
5059
<classifier>standalone</classifier>
5160
</dependency>
61+
<dependency>
62+
<groupId>com.eficode.atlassian</groupId>
63+
<artifactId>jirainstancemanger</artifactId>
64+
<version>1.0.1-SNAPSHOT</version>
65+
</dependency>
5266

5367

5468
</dependencies>
5569

70+
<repositories>
71+
<repository>
72+
<id>eficode-github-jiraManagerRest</id>
73+
<url>https://github.com/eficode/JiraInstanceMangerRest/raw/pre_v1_tweaks/repository/</url>
74+
</repository>
75+
</repositories>
5676
<build>
77+
<sourceDirectory>${basedir}/src/main/groovy</sourceDirectory>
5778
<plugins>
79+
<plugin>
80+
<groupId>org.apache.maven.plugins</groupId>
81+
<artifactId>maven-source-plugin</artifactId>
82+
<version>3.2.0</version>
83+
<executions>
84+
<execution>
85+
<id>attach-sources</id>
86+
<phase>generate-sources</phase>
87+
<goals>
88+
<goal>jar-no-fork</goal>
89+
</goals>
90+
</execution>
91+
</executions>
92+
</plugin>
5893
<plugin>
5994
<groupId>org.codehaus.gmavenplus</groupId>
6095
<artifactId>gmavenplus-plugin</artifactId>
@@ -74,11 +109,7 @@
74109
<scope>runtime</scope>
75110
</dependency>
76111
</dependencies>
77-
<configuration>
78-
<scripts>
79-
<script>src/main/groovy/Main.groovy</script>
80-
</scripts>
81-
</configuration>
112+
82113
</plugin>
83114
</plugins>
84115
</build>

src/main/groovy/com/eficode/devstack/container/ContainerManager.groovy renamed to src/main/groovy/com/eficode/devstack/container/Container.groovy

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ import java.nio.file.Files
2121
import java.nio.file.Path
2222
import java.time.Duration
2323

24-
trait ContainerManager {
24+
trait Container {
2525

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

4747
DockerClientConfig dockerConfig = new DockerClientConfig(host)
4848
DockerEnv dockerEnv = new DockerEnv(host)
4949
dockerEnv.setCertPath(certPath)
5050
dockerEnv.setTlsVerify("1")
5151
dockerConfig.apply(dockerEnv)
52-
53-
return new DockerClientImpl(dockerConfig)
52+
dockerClient = new DockerClientImpl(dockerConfig)
53+
return ping()
5454

5555
}
5656

5757

5858
boolean ping() {
59-
return dockerClient.ping().content as String == "OK"
59+
try {
60+
return dockerClient.ping().content as String == "OK"
61+
}catch(SocketException ex) {
62+
log.warn("Failed to ping Docker engine:" + ex.message)
63+
return false
64+
}
65+
66+
}
67+
68+
69+
70+
71+
boolean isCreated(){
72+
73+
ArrayList<Map> content = dockerClient.ps().content
74+
ArrayList<String> containerNames = content.collect {it.Names}.flatten()
75+
return containerNames.find{ it == "/" + getContainerName()} != null
76+
77+
}
78+
79+
String getId() {
80+
return containerId
6081
}
82+
6183
String getContainerId() {
6284

6385
if (containerId) {
@@ -101,6 +123,18 @@ trait ContainerManager {
101123

102124
}
103125

126+
boolean stopContainer() {
127+
log.info("Stopping container:" + containerId)
128+
dockerClient.stop(containerId, 240000)
129+
if (dockerClient.inspectContainer(containerId).content.state.running) {
130+
log.warn("\tFailed to stop container" + containerId)
131+
return false
132+
}else {
133+
log.info("\tContainer stopped")
134+
return true
135+
}
136+
}
137+
104138

105139

106140

src/main/groovy/com/eficode/devstack/container/impl/JsmContainer.groovy

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
package com.eficode.devstack.container.impl
22

3-
import com.eficode.devstack.container.ContainerManager
3+
import com.eficode.devstack.container.Container
44
import de.gesellix.docker.client.EngineResponseContent
55
import de.gesellix.docker.remote.api.ContainerCreateRequest
66
import de.gesellix.docker.remote.api.HostConfig
77
import de.gesellix.docker.remote.api.PortBinding
88

9-
class JsmContainer implements ContainerManager{
9+
class JsmContainer implements Container{
1010

11-
String containerName = "JSM-H2"
11+
String containerName = "JSM"
1212
String containerMainPort = "8080"
13+
String containerImage = "atlassian/jira-servicemanagement"
14+
String containerImageTag = "latest"
1315
long jvmMaxRam = 6000
1416

1517
JsmContainer() {}
@@ -20,7 +22,7 @@ class JsmContainer implements ContainerManager{
2022
* @param dockerCertPath ex: src/test/resources/dockerCert
2123
*/
2224
JsmContainer(String dockerHost, String dockerCertPath) {
23-
dockerClient = setupSecureRemoteConnection(dockerHost, dockerCertPath)
25+
assert setupSecureRemoteConnection(dockerHost, dockerCertPath) : "Error setting up secure remote docker connection"
2426
}
2527

2628

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

3234
}
3335

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

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

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.eficode.devstack.deployment
2+
3+
import com.eficode.devstack.container.Container
4+
import org.slf4j.Logger
5+
import org.slf4j.LoggerFactory
6+
7+
trait Deployment {
8+
9+
static Logger log = LoggerFactory.getLogger(Deployment.class)
10+
abstract ArrayList<Container> containers
11+
abstract String friendlyName
12+
13+
14+
abstract boolean setupDeployment()
15+
16+
void setupSecureDockerConnection(String host, String certPath) {
17+
18+
log.info("Setting up secure connection to docker engine")
19+
assert getContainers() != null && !getContainers().empty : "Deployment has no containers defined"
20+
//assert getContainers().any{! it.ping()} : "Connection has already been established."
21+
//assert getContainers().created.each {!it} : "Cant setup secure connection when containers have already been created in docker engine"
22+
23+
24+
getContainers().each {
25+
assert it.setupSecureRemoteConnection(host, certPath) : "Error setting up secure connection to docker engine"
26+
log.info("\tSecure connection setup for container:" + getFriendlyName())
27+
}
28+
log.info("\tSuccessfully setup secure connections to docker engine")
29+
}
30+
31+
32+
boolean startDeployment() {
33+
log.info("Starting deployment:" + friendlyName)
34+
35+
containers.each {container ->
36+
log.debug("\tStarting:" + container.containerName)
37+
assert container.startContainer() : "Error starting container:" + container.containerId
38+
}
39+
40+
log.info("\tFinished starting deployment")
41+
return true
42+
43+
}
44+
45+
boolean stopDeployment() {
46+
log.info("Stopping deployment:" + friendlyName)
47+
48+
containers.each {container ->
49+
log.debug("\tStopping:" + container.containerName)
50+
assert container.stopContainer() : "Error stopping container:" + container.containerId
51+
}
52+
53+
log.info("\tFinished stopping deployment")
54+
return true
55+
56+
}
57+
}

0 commit comments

Comments
 (0)