Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes required for Configuration As Code (and plugin install) #136

Closed
wants to merge 37 commits into from
Closed
Changes from 3 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
a4e6e3f
I like my desktop notifications
Jul 2, 2018
09a9687
Additional state checking
Jul 2, 2018
2becb1c
Merge branch 'patch-3' into mymerge
Jul 13, 2018
1005c8a
New componenets
Aug 3, 2018
b2a5967
Changes.
Aug 3, 2018
54f4ac7
Next
Aug 3, 2018
7f4a30f
Which test for aws added... Tests for awscli.
Aug 24, 2018
5313c77
Lets try this.
Aug 24, 2018
a1d04ba
Deploys okay
Aug 24, 2018
3dd0f5d
Insertation fix
Aug 26, 2018
c454026
Better delete handle logic
Aug 27, 2018
72d3e20
Stack deleted
Aug 27, 2018
aac8633
Watch_notify now takes into account deleting too
Aug 27, 2018
708e7f8
Manual revert
Aug 27, 2018
ad9cc6c
Break not exit 0
Aug 27, 2018
bb308c6
Break not exit 0
Aug 27, 2018
ab4f5ab
Added 'a'
Aug 27, 2018
7e8ce5d
Path change
Aug 27, 2018
f225f49
Overlay
Aug 27, 2018
3efbc4a
Overlay url fix
Aug 27, 2018
f6c860c
URL fix, better doesn't mess with overlay
Aug 27, 2018
b915ef4
Better mesage
Aug 27, 2018
85e5f2b
My mistake
Aug 27, 2018
dc46d03
I have to remove this, as Configuration As Code can load in plugins, …
Sep 7, 2018
7d7f49c
Configuration as code refresh to configuration-as-code-support-1.0-rc…
Sep 11, 2018
62cf332
1.0RC1
Sep 12, 2018
5ba7b8c
Plugin generation. CAC now in repo no need to bundle into ciinabox-ecs.
Sep 21, 2018
4e76eb9
Fixed var init
Sep 21, 2018
8f5974f
Suppress whitespaces
Sep 21, 2018
9b84155
Generation script
Sep 26, 2018
3d839b3
Indent
Sep 26, 2018
e8bccc3
Should be break
Sep 26, 2018
18366a7
Corrected file names x2
Sep 26, 2018
765757e
Don't require a restart
Sep 26, 2018
16bc195
get correct IP address
Sep 26, 2018
63c6d16
One liner mode
Sep 26, 2018
562f8f0
Removal of a couple of unnecessary output
Oct 4, 2018
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
jenkins:
plugins:
required:
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import jenkins.*
import hudson.*
import com.cloudbees.plugins.credentials.*
import com.cloudbees.plugins.credentials.common.*
import com.cloudbees.plugins.credentials.domains.*
import com.cloudbees.plugins.credentials.impl.*
import hudson.plugins.sshslaves.*;
import jenkins.model.*
import hudson.model.*
import hudson.security.*
import hudson.slaves.*
import hudson.plugins.sshslaves.verifiers.*

def instance = Jenkins.getInstance()
instance.setNumExecutors(0)

def bootstrap = new File("/var/jenkins_home/bootstrap").exists()

user = hudson.model.User.get('ciinabox', false)

if (user == null && !bootstrap) {
println("no ciinabox user found...creating it")
user = hudson.model.User.get('ciinabox')
user.setFullName('ciinabox')
email = new hudson.tasks.Mailer.UserProperty('[email protected]')
user.addProperty(email)
password = hudson.security.HudsonPrivateSecurityRealm.Details.fromPlainPassword('ciinabox')
user.addProperty(password)
user.save()

def realm = new HudsonPrivateSecurityRealm(false)
instance.setSecurityRealm(realm)
def strategy = new hudson.security.ProjectMatrixAuthorizationStrategy()
strategy.add(Jenkins.ADMINISTER, "ciinabox")
instance.setAuthorizationStrategy(strategy)
instance.save()
} else {
println("ciinabox user and default security already setup")
}


def creds = com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials(
com.cloudbees.plugins.credentials.common.StandardUsernameCredentials.class,
Jenkins.instance,
null,
null
);

def jenkinsCreds = null
for (c in creds) {
if (c.username == 'jenkins') {
jenkinsCreds = c
break
}
}

if (jenkinsCreds == null) {
global_domain = Domain.global()
credentials_store =
Jenkins.instance.getExtensionList(
'com.cloudbees.plugins.credentials.SystemCredentialsProvider'
)[0].getStore()
jenkinsCreds = new UsernamePasswordCredentialsImpl(
CredentialsScope.GLOBAL,
null,
"jenkins",
"jenkins",
"jenkins")
credentials_store.addCredentials(global_domain, jenkinsCreds)
} else {
println("jenkins creds already exists")
}

def envVars = [
new EnvironmentVariablesNodeProperty.Entry('LANGUAGE', 'C.UTF-8'),
new EnvironmentVariablesNodeProperty.Entry('LC_ALL', 'C.UTF-8')
]
envProps = new EnvironmentVariablesNodeProperty(envVars)

//add dind / dood slaves if they exist
int sshPort = 22

def createSlave = { String type ->
String slaveName = "jenkins-docker-${type}-slave"
try {
//try to make connection on port 22
Socket ssh = new Socket()
//connect with timeout of 10s
ssh.connect(new InetSocketAddress(slaveName, sshPort), 10000)
boolean slaveExists = false
for (jenkinsSlave in hudson.model.Hudson.instance.slaves) {
if (jenkinsSlave.name.equals(slaveName)) {
slaveExists = true
}
}

println "Connection can be made to sshd on ${slaveName} host"

if (slaveExists) {
println "Jenkins ${slaveName} is already present on system"
} else {
println "Creating ${slaveName} ..."
Jenkins.instance.addNode(new DumbSlave(slaveName,
"Jenkins Docker ${type} Slave ",
type.equals('dood') ? '/data/jenkins-dood' : "/home/jenkins",
"8",
Node.Mode.NORMAL,
"docker docker-${type}",
new SSHLauncher(
slaveName, //host
22, //port
jenkinsCreds, //credentials
type.equals('dood') ? '-Djava.io.tmpdir=/data/jenkins-dood/tmp' : null, //jvm opptions
null, //java path
null, //jdk installer
null, //prefix start cmd
null, //prefix end cmd
null, //launchTimeoutSeconds
null, //maxNumRetries
null, //retryWaitTime
new NonVerifyingKeyVerificationStrategy()
//verification strategy, running slave and host within same docker engine no need for verification
// ,
), new RetentionStrategy.Always(), [ envProps ]))
}
} catch (IOException ignored) {
println "Connection can't be made to ${slaveName} host"
}
}

createSlave('dind')
createSlave('dood')


if (!bootstrap) {
println("touch /var/jenkins_home/bootstrap".execute().text)
} else {
println("Bootstrap file present, this is not first execution of this file")
}

println "\nCIINABOX - Jenkins initialization complete at ${new java.util.Date()}\n"
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import hudson.model.*
import hudson.remoting.Future
import jenkins.model.*
import net.sf.json.JSONArray
import net.sf.json.JSONObject
import org.apache.commons.lang.StringUtils

import java.util.concurrent.TimeUnit
import java.util.jar.JarFile
import java.util.jar.Manifest

import static java.util.logging.Level.WARNING

{ String msg = getClass().protectionDomain.codeSource.location.path ->
println "--> ${msg}"

Jenkins.instance.getPluginManager().getPlugins()
Jenkins.instance.getUpdateCenter().updateAllSites()

def updates = 0;
/* plugins */ [
'/var/jenkins_home/plugins_to_install/configuration-as-code.hpi',
].each { pluginFilename ->
try {
println("Reading: " + pluginFilename);
def baseName = "";
JSONArray dependencies = new JSONArray();
try {
JarFile j = new JarFile(pluginFilename);
Manifest m = j.getManifest();
String deps = m.getMainAttributes().getValue("Plugin-Dependencies");
baseName = m.getMainAttributes().getValue("Short-Name");

if (StringUtils.isNotBlank(deps)) {
String[] plugins = deps.split(",");
for (String p : plugins) {
String[] attrs = p.split("[:;]");
dependencies.add(new JSONObject()
.element("name", attrs[0])
.element("version", attrs[1])
.element("optional", p.contains("resolution:=optional")));
}
}
} catch(IOException e) {
LOGGER.log(WARNING, "Unable to setup dependency list for plugin upload", e);
}

def plugin = Jenkins.getInstance().getPluginManager().getPlugin(baseName);
println(baseName);
if (plugin == null) {
println("Need to update or install plugin");

JSONObject cfg = new JSONObject().
element("name", baseName).
element("version", "0"). // unused but mandatory
element("url", "file://" + pluginFilename).
element("dependencies", dependencies);
def us = new UpdateSite(UpdateCenter.ID_UPLOAD, null);
def p = new UpdateSite.Plugin(us, UpdateCenter.ID_UPLOAD, cfg);
def f = p.deploy(false);
println("Blocking until successfully downloaded");
f.get();
updates++;
}
} catch (Exception x) {
x.printStackTrace()
}
}

println "--> ${msg} ... done"
} ()
Binary file not shown.