Skip to content

Instantly share code, notes, and snippets.

View iocanel's full-sized avatar

Ioannis Canellos iocanel

View GitHub Profile
@iocanel
iocanel / docker-worfklow.groovy
Last active September 4, 2015 15:48
Docker Workflow Example
node('docker') {
docker.image('maven').inside {
git 'https://github.com/fabric8io/example-camel-cdi'
sh 'mvn clean install'
}
}
@iocanel
iocanel / jenkins-setup-credentials.groovy
Created September 1, 2015 09:12
Setup Jenkins Credentials
import jenkins.model.*
import com.cloudbees.plugins.credentials.*
import com.cloudbees.plugins.credentials.common.*
import com.cloudbees.plugins.credentials.domains.*
import com.cloudbees.plugins.credentials.impl.*
import com.cloudbees.jenkins.plugins.sshcredentials.impl.*
import hudson.plugins.sshslaves.*;
domain = Domain.global()
store = Jenkins.instance.getExtensionList('com.cloudbees.plugins.credentials.SystemCredentialsProvider')[0].getStore()
@iocanel
iocanel / jenkins-keygen.sh
Created September 1, 2015 09:05
Jenkins key generation
#Generate master.key and secret
MAGIC="::::MAGIC::::"
mkdir -p /var/jenkins_home/secrets
openssl rand -hex 128 > /var/jenkins_home/secrets/master.key
openssl dgst -sha256 -binary /var/jenkins_home/secrets/master.key > /tmp/master.hashed
HEX_MASTER_KEY=`head -c 16 /tmp/master.hashed | xxd -l 16 -p`
openssl rand 259 > /tmp/base
echo $MAGIC >> /tmp/base
openssl enc -aes-128-ecb -in /tmp/base -K $HEX_MASTER_KEY -out /var/jenkins_home/secrets/hudson.util.Secret
@iocanel
iocanel / volumes-and-mounts.json
Last active August 31, 2015 13:34
Volumes and volume mounts
{
"volumeMounts": [
{
"name": "docker-socket",
"mountPath": "/var/run/docker.sock",
"readOnly": false
}
],
@iocanel
iocanel / get-host.ip.sh
Created August 31, 2015 13:20
Get the docker host ip inside Kubernetes
#!/bin/bash
KUBERNETES=https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_SERVICE_PORT
TOKEN=`cat /var/run/secrets/kubernetes.io/serviceaccount/token`
POD=`hostname`
curl -s -k -H "Authorization: Bearer $TOKEN" $KUBERNETES/api/v1/namespaces/$KUBERNETES_NAMESPACE/pods/$POD | grep -i hostIp | cut -d "\"" -f 4
@iocanel
iocanel / gist:12c0ae1e103fd94bef4c
Created August 31, 2015 10:42
Starting the Swarm client
java -jar /path/to/swarm-client.jar http://jenkins.master:8080
@iocanel
iocanel / OpenshiftClientWithCustomConfig.java
Created August 25, 2015 07:29
Openshift client with custom config
//Openshift client with custom config
OpenshiftConfig config = new OpenshiftConfigBuilder()
.withMasterUrl(url)
.withOpenShiftUrl(openshiftUrl)
.withTrustCerts(true)
.build();
OpenshiftClient client = new DefaultOpenshiftClient(config);
@iocanel
iocanel / KubernetesWithCustomConfig.java
Last active August 29, 2015 14:28
Kubernetes client with custom config
//Client with custom config
Config config = new ConfigBuilder()
.withMasterUrl(url)
.withTrustCerts(true)
.withOauthToken(mytoken)
.build();
KubernetesClient = new DefaultKubernetesClient(config);
@iocanel
iocanel / KubernetesMockClientExample.java
Created August 25, 2015 05:48
Example of the KubernetesMockClient
KubernetesMockClient mock = new KubernetesMockClient();
//Define the behaviour
mock.services().inNamespace(or("default","fabric8")).withName("fabric8-console-service").get().andReturn(
new ServiceBuilder()
.withNewMetadata().withName("fabric8-console-service").endMetadata()
.withNewSpec()
.addNewPort()
.withProtocol("TCP")
.withPort(80)
@iocanel
iocanel / OpenshiftAdaptExample.java
Created August 24, 2015 16:22
Adapt KubernetesClient to OpenShiftClient
KubernetesClient client = new DefaultKubernetesClinet();
OpenShiftClient oc = client.adapt(OpenShiftClient.class);