Skip to content

Commit

Permalink
[JENKINS-55933] Add configuration to test slowdowns in the plugin (#57)
Browse files Browse the repository at this point in the history
* Add configuration to test slowdowns in the plugin

* Cleanup unused files

* Remove unnecessary plugins from plugins.txt

Dependencies are automatically installed in `install-plugins.sh` from
the base jenkins/jenkins image.

* Update LICENSE.md

* Change Docker Image names in Makefile and README.md
  • Loading branch information
AbhyudayaSharma authored and oleg-nenashev committed Feb 11, 2019
1 parent 314e709 commit c1ccef3
Show file tree
Hide file tree
Showing 20 changed files with 839 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/test/performance/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
FROM jenkins/jenkins:2.138.2
MAINTAINER Oleg Nenashev <[email protected]>
LABEL Description="This demo shows how to setup Jenkins Config-as-Code with Docker, Pipeline, and Groovy Hook Scripts" Vendor="Oleg Nenashev" Version="0.2"

ENV JENKINS_UC_EXPERIMENTAL=https://updates.jenkins.io/experimental
COPY plugins.txt /usr/share/jenkins/ref/plugins.txt
RUN /usr/local/bin/install-plugins.sh < /usr/share/jenkins/ref/plugins.txt

COPY init_scripts/src/main/groovy/ /usr/share/jenkins/ref/init.groovy.d/

# TODO: It should be configurable in "docker run"
ARG DEV_HOST=192.168.101.57
ARG CREATE_ADMIN=true
# If false, only few runs can be actually executed on the master
# See JobRestrictions settings
ARG ALLOW_RUNS_ON_MASTER=false
ARG LOCAL_PIPELINE_LIBRARY_PATH=/var/jenkins_home/pipeline-library

ENV CONF_CREATE_ADMIN=$CREATE_ADMIN
ENV CONF_ALLOW_RUNS_ON_MASTER=$ALLOW_RUNS_ON_MASTER

# Directory for Pipeline Library development sample
ENV LOCAL_PIPELINE_LIBRARY_PATH=${LOCAL_PIPELINE_LIBRARY_PATH}
RUN mkdir -p ${LOCAL_PIPELINE_LIBRARY_PATH}

VOLUME /var/jenkins_home/pipeline-library
VOLUME /var/jenkins_home/pipeline-libs
EXPOSE 5005

COPY jenkins2.sh /usr/local/bin/jenkins2.sh
ENV CASC_JENKINS_CONFIG=/var/jenkins_home/jenkins.yaml
COPY jenkins.yaml /var/jenkins_home/jenkins.yaml
ENTRYPOINT ["tini", "--", "/usr/local/bin/jenkins2.sh"]
21 changes: 21 additions & 0 deletions src/test/performance/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017-2019 Oleg Nenashev, Abhyudaya Sharma and other contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
8 changes: 8 additions & 0 deletions src/test/performance/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
build:
docker build -t abhyudaya/jenkins-role-strategy-slowdown-config .

run:
docker run --rm --name ci-jenkins-io-dev -v maven-repo:/root/.m2 -v ${MY_PIPELINE_LIBRARY_DIR}:/var/jenkins_home/pipeline-library -v ${MY_OTHER_PIPELINE_LIBS_DIRS}:/var/jenkins_home/pipeline-libs -e DEV_HOST=${CURRENT_HOST} -p 8080:8080 -p 50000:50000 abhyudaya/jenkins-role-strategy-slowdown-config

debug:
docker run --rm --name ci-jenkins-io-dev -e DEBUG=true -p 5005:5005 -v maven-repo:/root/.m2 -v ${MY_PIPELINE_LIBRARY_DIR}:/var/jenkins_home/pipeline-library -v ${MY_OTHER_PIPELINE_LIBS_DIRS}:/var/jenkins_home/pipeline-libs -e DEV_HOST=${CURRENT_HOST} -p 8080:8080 -p 50000:50000 abhyudaya/jenkins-role-strategy-slowdown-config
34 changes: 34 additions & 0 deletions src/test/performance/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Demo image for Testing the Plugin's performance
===

This configuration is designed to experience the performance slowdowns on a large number
of roles. Based on [oleg-nenashev/demo-jenkins-config-as-code](https://github.com/oleg-nenashev/demo-jenkins-config-as-code).

### Usage

Run image:

```shell
docker run --rm --name ci-jenkins-io-dev -v maven-repo:/root/.m2 -e DEV_HOST=${CURRENT_HOST} -p 8080:8080 -p 50000:50000 abhyudaya/jenkins-role-strategy-slowdown-config
```

Jenkins will need to connect to the Docker host to run agents.
If you use Docker for Mac, use `-Dio.jenkins.dev.host` and additional `socat` image for forwarding.

```shell
docker run -d -v /var/run/docker.sock:/var/run/docker.sock -p 2376:2375 bobrik/socat TCP4-LISTEN:2375,fork,reuseaddr UNIX-CONNECT:/var/run/docker.sock
```

##### Debugging Master

In order to debug the master, use the `-e DEBUG=true -p 5005:5005` when starting the container.
Jenkins will be suspended on the startup in such case.

If you open parent POM as a Maven project in your IDE,
you will be also able to debug initialization Groovy scripts.

### Building image

```shell
docker build -t abhyudaya/jenkins-role-strategy-slowdown-config .
```
153 changes: 153 additions & 0 deletions src/test/performance/init_scripts/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>2.28</version>
</parent>

<groupId>io.jenkins.systemgroovy.demo</groupId>
<artifactId>initscripts</artifactId>
<name>Jenkins Config-as-Code Demo Scripts</name>
<description>Initialization scripts for Jenkins Config-as-Code demo</description>
<version>1.0-SNAPSHOT</version>

<developers>
<developer>
<name>Oleg Nenashev</name>
<organization>Jenkins project</organization>
<organizationUrl>https://jenkins.io</organizationUrl>
</developer>
</developers>

<licenses>
<license>
<name>The MIT License (MIT)</name>
<url>http://opensource.org/licenses/MIT</url>
<distribution>repo</distribution>
</license>
</licenses>

<properties>
<jenkins.version>2.73.3</jenkins.version>
<java.level>8</java.level>
</properties>


<dependencies>
<!-- Jenkins packages just to have code completion & co -->
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>matrix-auth</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>cloudbees-folder</artifactId>
<version>5.12</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-aggregator</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>git</artifactId>
<version>3.3.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.kostyasha.yet-another-docker</groupId>
<artifactId>yet-another-docker-plugin</artifactId>
<version>0.1.0-rc37</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.synopsys.jenkinsci</groupId>
<artifactId>ownership</artifactId>
<version>0.10.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.synopsys.arc.jenkinsci.plugins</groupId>
<artifactId>job-restrictions</artifactId>
<version>0.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>role-strategy</artifactId>
<version>2.5.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>mailer</artifactId>
<version>1.20</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>authorize-project</artifactId>
<version>1.3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jvnet.hudson.plugins</groupId>
<artifactId>locale</artifactId>
<version>1.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>hudson.plugins.filesystem_scm</groupId>
<artifactId>filesystem_scm</artifactId>
<version>1.21-alpha-1</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.5-jenkins-3</version>
<dependencies>
<dependency>
<groupId>org.codehaus.gmaven.runtime</groupId>
<artifactId>gmaven-runtime-1.8</artifactId>
<version>1.5-jenkins-3</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* The MIT License
*
* Copyright (c) 2017 Oleg Nenashev
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

import org.codehaus.groovy.control.CompilerConfiguration
import static java.util.logging.Level.INFO
import static java.util.logging.Level.WARNING;
import java.util.logging.Logger;
import javax.annotation.Nonnull;
import javax.servlet.ServletContext;
import jenkins.model.Jenkins;

/**
* Bootstraps the standard Jenkins initialization logic.
* The bootstrap adds support of Groovy classes and propagates execution failures.
* The started scripts will be debuggable in IDE via Remote Debugger inside a running instance.
*
* @author Oleg Nenashev
*/
class GroovyInitBootstrap {
private final Binding bindings = new Binding()
private final ServletContext servletContext
private final File home
private final GroovyClassLoader groovyClassloader
private final CompilerConfiguration compilerConfiguration = CompilerConfiguration.DEFAULT

private GroovyInitBootstrap(Jenkins j) {
this(j.servletContext, j.rootDir, j.pluginManager.uberClassLoader)
}

GroovyInitBootstrap(@Nonnull ServletContext servletContext, @Nonnull File home, @Nonnull ClassLoader groovyClassloader) {
this.servletContext = servletContext
this.home = home
compilerConfiguration.classpath = new File(home, "init.groovy.d/").absolutePath
this.groovyClassloader = new GroovyClassLoader(groovyClassloader, compilerConfiguration, true)
}

GroovyBootstrap bind(String name, Object o) {
bindings.setProperty(name,o)
return this
}

/**
* Runs the bootstrap and executes all scripts in {@code init.groovy.d/scripts}.
* @throws Error Execution failed, should be considered as fatal.
*/
void run() {
File scriptsDir = new File(home, "init.groovy.d/scripts")
if (scriptsDir.isDirectory()) {
File[] scripts = scriptsDir.listFiles(new FileFilter() {
boolean accept(File f) {
return f.name.endsWith(".groovy")
}
})
if (scripts!=null) {
// sort to run them in an alphabetic order
scripts.sort().each {
execute(it)
}
}
}
}

/**
* Executes the specified Groovy file.
* @param f Groovy file
* @throws Error Execution failed, should be considered as fatal.
*/
protected void execute(@Nonnull File f) {
if (f.exists()) {
LOGGER.log(INFO, "Executing {0}", f)
try {
GroovyCodeSource codeSource = new GroovyCodeSource(f)
new GroovyShell(groovyClassloader, bindings).evaluate(codeSource)
} catch (IOException e) {
LOGGER.log(WARNING, "Failed to execute " + f, e);
throw new Error("Failed to execute " + f, e)
}
}
}

private static final Logger LOGGER = Logger.getLogger(GroovyBootstrap.class.getName());
}

GroovyInitBootstrap bootstrap = new GroovyInitBootstrap(Jenkins.instance)
bootstrap.run()
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Demo jobs
===

This directory contains a set of demo `Jenkinsfile`s.
System Groovy scripts process this directory and create jobs for each job.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
buildPlugin(platforms: ['linux'],
repo: 'https://github.com/jenkinsci/job-restrictions-plugin.git',
findbugs: [archive: true, unstableTotalAll: '0'])
Loading

0 comments on commit c1ccef3

Please sign in to comment.