Skip to content

Commit b310419

Browse files
Merge pull request #895 from kuisathaverat/feat/portable
feat: make demo more portable
2 parents a3ddfca + 4b2052c commit b310419

File tree

13 files changed

+192
-51
lines changed

13 files changed

+192
-51
lines changed

demos/Makefile

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.DEFAULT_GOAL := start
22

33
export OTELCOL_IMG?=otel/opentelemetry-collector-contrib-dev:latest
4-
export ELASTIC_STACK_VERSION?=8.10.1
4+
export ELASTIC_STACK_VERSION?=8.14.2
55

66
.PHONY: build
77
build:
@@ -18,18 +18,3 @@ stop:
1818
.PHONY: clean
1919
clean:
2020
@env docker-compose --file docker-compose.yml down -v
21-
22-
.PHONY: start-all ## Start everything locally
23-
start-all: start start-local-worker
24-
25-
.PHONY: stop-all ## Stop everything locally
26-
stop-all: stop-local-worker stop
27-
28-
.PHONY: start-local-worker
29-
start-local-worker: ## Start the local worker
30-
[ ! -e agent.jar ] && wget --quiet -O agent.jar http://localhost:8080/jnlpJars/agent.jar || true
31-
{ nohup java -jar agent.jar -jnlpUrl http://localhost:8080/computer/local/jenkins-agent.jnlp > local.log 2>&1 & echo $$! > local.pid; }
32-
33-
.PHONY: stop-local-worker
34-
stop-local-worker: ## Stop the local worker
35-
[ -e local.pid ] && ( kill -9 `cat local.pid` ; rm local.pid ) || true

demos/config/ansible.dsl

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,44 @@ executable = /bin/bash
2424
module_lang = en_US.UTF-8
2525
callbacks_enabled = community.general.opentelemetry
2626
'''
27+
installHermit()
2728
}
2829
}
2930
stage('run-ansible') {
3031
steps {
3132
script {
32-
// some magic with -u root:root to bypass the due to: 'getpwuid(): uid not found in ansible
33-
docker.image('geerlingguy/docker-ubuntu2004-ansible').inside('-u root:root --network demos_jenkins') {
34-
// some magic withEnv to bypass Permission denied: b'/.ansible'
35-
withEnv(["HOME=\${env.WORKSPACE}"]) {
36-
sh(label: 'fetch the community.general collection', script: 'ansible-galaxy collection install community.general')
37-
sh(label: 'pip3 install', script: 'pip3 install opentelemetry-api opentelemetry-sdk opentelemetry-exporter-otlp')
38-
sh(label: 'run ansible', script: 'ansible-playbook playbook.yml')
33+
runWithHermit(){
34+
sh(label: 'fetch the community.general collection', script: 'ansible-galaxy collection install community.general')
35+
sh(label: 'pip3 install', script: 'pip3 install opentelemetry-api opentelemetry-sdk opentelemetry-exporter-otlp')
36+
sh(label: 'run ansible', script: 'ansible-playbook playbook.yml')
3937
}
40-
}
4138
}
4239
}
4340
}
4441
}
45-
}"""
42+
}
43+
44+
def runWithHermit(Closure body){
45+
hermitEnvVars = sh(returnStdout: true, script: './hermit/bin/hermit env --raw').trim()
46+
withEnv(hermitEnvVars.split('\\n').toList()) {
47+
body()
48+
}
49+
}
50+
51+
def installHermit() {
52+
sh(label: 'installHermit',
53+
script: 'curl -fsSL https://github.com/cashapp/hermit/releases/download/stable/install.sh | /bin/bash')
54+
sh(label: 'install tools',
55+
script: '''
56+
mkdir -p hermit
57+
cd hermit
58+
~/bin/hermit init
59+
eval \$(./bin/hermit env --raw)
60+
hermit install python3
61+
pip install ansible
62+
''')
63+
}
64+
"""
4665

4766
pipelineJob(NAME) {
4867
definition {

demos/config/gradle.dsl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,18 @@ DSL = """pipeline {
1414
stage('build') {
1515
steps {
1616
script {
17-
docker.image('openjdk:8-jdk-alpine').inside('--network demos_jenkins') {
1817
withEnv(["HOME=\${env.WORKSPACE}"]) {
19-
sh(label: 'gradle build', script: './gradlew clean build')
18+
sh(label: 'gradle build', script: './gradlew clean build')
2019
}
21-
}
2220
}
2321
}
2422
}
2523
stage('test') {
2624
steps {
2725
script {
28-
docker.image('openjdk:8-jdk-alpine').inside('--network demos_jenkins') {
2926
withEnv(["HOME=\${env.WORKSPACE}"]) {
3027
sh(label: 'gradle test', script: './gradlew clean test')
3128
}
32-
}
3329
}
3430
}
3531
}

demos/config/import_dashboard.dsl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
NAME = 'import_dashboard'
2+
DSL = """pipeline {
3+
agent any
4+
stages {
5+
stage('Import Dashboard') {
6+
steps {
7+
sh(label: 'Download dashboard', script: 'curl -sSfL -o dashboard.ndjson https://raw.githubusercontent.com/jenkinsci/opentelemetry-plugin/main/src/main/kibana/jenkins-kibana-dashboards.ndjson')
8+
sh(label: 'Import Dashboard', script: 'curl -X POST -u "admin:changeme" http://kibana:5601/api/saved_objects/_import -H "kbn-xsrf: true" --form [email protected]')
9+
}
10+
}
11+
}
12+
}
13+
"""
14+
15+
pipelineJob(NAME) {
16+
definition {
17+
cps {
18+
script(DSL.stripIndent())
19+
}
20+
}
21+
}

demos/config/jenkins.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ credentials:
3434
scope: GLOBAL
3535
username: "jenkins_logs_user"
3636
unclassified:
37+
location:
38+
url: "http://jenkins:8080/"
3739
openTelemetry:
3840
authentication: "noAuthentication"
3941
endpoint: "http://otel-collector:4317"
@@ -53,3 +55,5 @@ jobs:
5355
- file: "/var/jenkins_home/config/maven.dsl"
5456
- file: "/var/jenkins_home/config/otel-cli.dsl"
5557
- file: "/var/jenkins_home/config/otel-cli-make.dsl"
58+
- file: "/var/jenkins_home/config/import_dashboard.dsl"
59+
- file: "/var/jenkins_home/config/pytest-otel.dsl"

demos/config/maven.dsl

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,25 @@ DSL = '''pipeline {
1414
stage('prepare') {
1515
steps {
1616
sh (label: 'fetch opentelemetry-maven-extension',
17-
script: 'curl -s https://repo.maven.apache.org/maven2/io/opentelemetry/contrib/opentelemetry-maven-extension/${OTEL_VERSION}/opentelemetry-maven-extension-${OTEL_VERSION}.jar > otel.jar')
17+
script: 'curl -s https://repo.maven.apache.org/maven2/io/opentelemetry/contrib/opentelemetry-maven-extension/\${OTEL_VERSION}/opentelemetry-maven-extension-\${OTEL_VERSION}.jar > otel.jar')
1818
}
1919
}
2020
stage('compile') {
2121
steps {
2222
script {
23-
docker.image('openjdk:8-jdk-alpine').inside('--network demos_jenkins') {
24-
withEnv(["HOME=${env.WORKSPACE}"]) {
25-
sh(label: 'mvn compile', script: './mvnw -B ${MAVEN_OPTS} clean compile')
23+
withEnv(["HOME=\${env.WORKSPACE}"]) {
24+
sh(label: 'mvn compile', script: './mvnw -B \${MAVEN_OPTS} clean compile')
2625
}
27-
}
2826
}
2927

3028
}
3129
}
3230
stage('test') {
3331
steps {
3432
script {
35-
docker.image('openjdk:8-jdk-alpine').inside('--network demos_jenkins') {
36-
withEnv(["HOME=${env.WORKSPACE}"]) {
37-
sh(label: 'mvn test', script: './mvnw -B ${MAVEN_OPTS} test')
33+
withEnv(["HOME=\${env.WORKSPACE}"]) {
34+
sh(label: 'mvn test', script: './mvnw -B \${MAVEN_OPTS} test')
3835
}
39-
}
4036
}
4137
}
4238
post {

demos/config/otel-cli-make.dsl

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,35 +31,60 @@ test:
3131
stage('prepare') {
3232
steps {
3333
installOtelCli()
34+
installHermit()
3435
}
3536
}
3637
stage('make build') {
3738
steps {
3839
withEnv(["PATH+OTEL=\${OTEL_LOCATION}"]) {
39-
sh(label: 'make build', script: "OTEL_EXPORTER_OTLP_ENDPOINT=\${env.OTEL_EXPORTER_OTLP_ENDPOINT.replaceAll('http://', '')} make build")
40+
runWithHermit(){
41+
sh(label: 'make build', script: "OTEL_EXPORTER_OTLP_ENDPOINT=\${env.OTEL_EXPORTER_OTLP_ENDPOINT.replaceAll('http://', '')} make build")
42+
}
4043
}
4144
}
4245
}
4346
stage('make test') {
4447
steps {
4548
withEnv(["PATH+OTEL=\${OTEL_LOCATION}"]) {
46-
sh(label: 'make test', script: "OTEL_EXPORTER_OTLP_ENDPOINT=\${env.OTEL_EXPORTER_OTLP_ENDPOINT.replaceAll('http://', '')} make test")
49+
runWithHermit(){
50+
sh(label: 'make test', script: "OTEL_EXPORTER_OTLP_ENDPOINT=\${env.OTEL_EXPORTER_OTLP_ENDPOINT.replaceAll('http://', '')} make test")
51+
}
4752
}
4853
}
4954
}
5055
}
5156
}
5257

58+
def runWithHermit(Closure body){
59+
hermitEnvVars = sh(returnStdout: true, script: './hermit/bin/hermit env --raw').trim()
60+
withEnv(hermitEnvVars.split('\\n').toList()) {
61+
body()
62+
}
63+
}
64+
5365
def installOtelCli() {
5466
def os = 'Linux'
5567
if (sh(script: 'uname -a | grep -i Darwin', returnStatus: true) == 0) {
5668
os = 'Darwin'
5769
}
5870
dir("\${OTEL_LOCATION}") {
5971
sh(label: 'fetch otel-cli',
60-
script: "wget -q 'https://github.com/equinix-labs/otel-cli/releases/download/v0.0.18/otel-cli-0.0.18-\${os}-x86_64.tar.gz' -O otel-cli.tar.gz && tar -xf otel-cli.tar.gz")
72+
script: "curl -sSfL -o otel-cli.tar.gz 'https://github.com/equinix-labs/otel-cli/releases/download/v0.0.18/otel-cli-0.0.18-\${os}-x86_64.tar.gz' && tar -xf otel-cli.tar.gz")
6173
}
6274
}
75+
76+
def installHermit() {
77+
sh(label: 'installHermit',
78+
script: 'curl -fsSL https://github.com/cashapp/hermit/releases/download/stable/install.sh | /bin/bash')
79+
sh(label: 'install tools',
80+
script: '''
81+
mkdir -p hermit
82+
cd hermit
83+
~/bin/hermit init
84+
eval \$(./bin/hermit env --raw)
85+
hermit install make
86+
''')
87+
}
6388
"""
6489

6590
pipelineJob(NAME) {

demos/config/otel-cli.dsl

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ test:
2121
stage('prepare') {
2222
steps {
2323
installOtelCli()
24+
installHermit()
2425
}
2526
}
2627
stage('make build') {
@@ -38,21 +39,43 @@ test:
3839

3940
def runWithOtelCli(def args=[:]) {
4041
withEnv(["PATH+OTEL=\${OTEL_LOCATION}"]) {
41-
sh 'env | sort'
42-
sh(label: args.label, script: "OTEL_EXPORTER_OTLP_ENDPOINT=\${env.OTEL_EXPORTER_OTLP_ENDPOINT.replaceAll('http://', '')} otel-cli exec --name '\${args.label}'--tp-print \${args.script}")
42+
runWithHermit{
43+
sh 'env | sort'
44+
sh(label: args.label, script: "OTEL_EXPORTER_OTLP_ENDPOINT=\${env.OTEL_EXPORTER_OTLP_ENDPOINT.replaceAll('http://', '')} otel-cli exec --name '\${args.label}'--tp-print \${args.script}")
45+
}
4346
}
4447
}
4548

49+
def runWithHermit(Closure body){
50+
hermitEnvVars = sh(returnStdout: true, script: './hermit/bin/hermit env --raw').trim()
51+
withEnv(hermitEnvVars.split('\\n').toList()) {
52+
body()
53+
}
54+
}
55+
4656
def installOtelCli() {
4757
def os = 'Linux'
4858
if (sh(script: 'uname -a | grep -i Darwin', returnStatus: true) == 0) {
4959
os = 'Darwin'
5060
}
5161
dir("\${OTEL_LOCATION}") {
5262
sh(label: 'fetch otel-cli',
53-
script: "wget 'https://github.com/equinix-labs/otel-cli/releases/download/v0.0.18/otel-cli-0.0.18-\${os}-x86_64.tar.gz' -O otel-cli.tar.gz && tar -xf otel-cli.tar.gz")
63+
script: "curl -sSfL -o otel-cli.tar.gz 'https://github.com/equinix-labs/otel-cli/releases/download/v0.0.18/otel-cli-0.0.18-\${os}-x86_64.tar.gz' && tar -xf otel-cli.tar.gz")
5464
}
5565
}
66+
67+
def installHermit() {
68+
sh(label: 'installHermit',
69+
script: 'curl -fsSL https://github.com/cashapp/hermit/releases/download/stable/install.sh | /bin/bash')
70+
sh(label: 'install tools',
71+
script: '''
72+
mkdir -p hermit
73+
cd hermit
74+
~/bin/hermit init
75+
eval \$(./bin/hermit env --raw)
76+
hermit install make
77+
''')
78+
}
5679
"""
5780

5881
pipelineJob(NAME) {

demos/config/otel-collector-config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ receivers:
22
otlp:
33
protocols:
44
grpc:
5+
endpoint: 0.0.0.0:4317
6+
http:
7+
endpoint: 0.0.0.0:4318
58

69
exporters:
710
prometheus:
@@ -61,4 +64,5 @@ service:
6164
exporters: [debug, prometheus, otlp/elastic]
6265
logs:
6366
receivers: [otlp]
67+
processors: [batch]
6468
exporters: [debug, otlp/elastic]

demos/config/plugins.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ git
66
filesystem_scm
77
jdk-tool
88
job-dsl
9-
opentelemetry
9+
opentelemetry::https://repo.jenkins-ci.org/incrementals/io/jenkins/plugins/opentelemetry/3.1309.vb_ea_11a_392465/opentelemetry-3.1309.vb_ea_11a_392465.hpi
1010
pipeline-model-definition
1111
swarm
1212
workflow-aggregator

0 commit comments

Comments
 (0)