diff --git a/demo/Dockerfile b/demo/Dockerfile index 13f31012..12949743 100644 --- a/demo/Dockerfile +++ b/demo/Dockerfile @@ -1,31 +1,30 @@ -FROM jenkins/jenkins:2.319.3 +FROM jenkins/jenkins:2.375.2 USER root -ENV MAVEN_VERSION=3.8.4 +ENV MAVEN_VERSION=3.8.7 RUN curl -s https://archive.apache.org/dist/maven/maven-3/$MAVEN_VERSION/binaries/apache-maven-$MAVEN_VERSION-bin.tar.gz | tar xvfCz - /opt && \ ln -sv /opt/apache-maven-$MAVEN_VERSION/bin/mvn /usr/local/bin/mvn -ADD repo /tmp/repo -COPY gen.sh /tmp/ ADD lib /tmp/lib -COPY plugins /usr/share/jenkins/ref/plugins -RUN chown -R jenkins.jenkins /tmp/repo /tmp/lib /usr/share/jenkins/ref/plugins +RUN mkdir -p /m2repo + +RUN chown -R jenkins.jenkins /tmp/lib /m2repo USER jenkins -RUN cd /tmp/repo && \ - bash ../gen.sh && \ - git init && \ - git add . && \ - git -c user.email=demo@jenkins-ci.org -c user.name="Parallel Test Executor Demo" commit -m 'demo' && \ - cd /tmp/lib && \ +COPY target/test-classes/test-dependencies/*.hpi /usr/share/jenkins/ref/plugins/ + +RUN cd /tmp/lib && \ git init && \ git add . && \ git -c user.email=demo@jenkins-ci.org -c user.name="Parallel Test Executor Demo" commit -m 'demo' # TODO without this JENKINS-24752 workaround, it takes too long to provision. # (Do not add hudson.model.LoadStatistics.decay=0.1; in that case we overprovision slaves which never get used, and OnceRetentionStrategy.check disconnects them after an idle timeout.) -ENV JAVA_OPTS -Dhudson.model.LoadStatistics.clock=1000 -Dhudson.Main.development=true +ENV JAVA_OPTS -Dhudson.model.LoadStatistics.clock=1000 -Dhudson.Main.development=true -Dhudson.plugins.git.GitSCM.ALLOW_LOCAL_CHECKOUT=true ADD JENKINS_HOME /usr/share/jenkins/ref + +HEALTHCHECK --interval=5m --timeout=3s \ + CMD curl -f http://localhost:8080/ || exit 1 diff --git a/demo/JENKINS_HOME/credentials.xml b/demo/JENKINS_HOME/credentials.xml new file mode 100644 index 00000000..70dabfa6 --- /dev/null +++ b/demo/JENKINS_HOME/credentials.xml @@ -0,0 +1,20 @@ + + + + + + + + + + GLOBAL + gitea + + jenkins + SECRET + false + + + + + diff --git a/demo/JENKINS_HOME/jobs/pipeline/config.xml b/demo/JENKINS_HOME/jobs/pipeline/config.xml index 99bb7ace..f203315a 100644 --- a/demo/JENKINS_HOME/jobs/pipeline/config.xml +++ b/demo/JENKINS_HOME/jobs/pipeline/config.xml @@ -3,13 +3,25 @@ - - - /tmp/repo - - * - - false + + + 6126b51e-8b62-413c-9e82-333d0cf58bdb + http://gitea:3000 + jenkins + demo + gitea + + + 1 + + + 1 + + + 1 + + + diff --git a/demo/JENKINS_HOME/org.jenkinsci.plugin.gitea.servers.GiteaServers.xml b/demo/JENKINS_HOME/org.jenkinsci.plugin.gitea.servers.GiteaServers.xml new file mode 100644 index 00000000..8a3da6c5 --- /dev/null +++ b/demo/JENKINS_HOME/org.jenkinsci.plugin.gitea.servers.GiteaServers.xml @@ -0,0 +1,11 @@ + + + + + gitea + http://gitea:3000 + false + gitea + + + diff --git a/demo/Makefile b/demo/Makefile index 2498fd1e..28dc8cfc 100644 --- a/demo/Makefile +++ b/demo/Makefile @@ -1,27 +1,22 @@ -IMAGE=parallel-test-executor-demo -DOCKER_RUN=docker run --rm -p 127.0.0.1:8080:8080 -v m2repo:/m2repo --group-add=$(shell stat -c %g /var/run/docker.sock) -ti - +PHONY: validate validate: mvn -Dtest=InjectedTest clean test +PHONY: copy-plugins copy-plugins: - if [ \! -f ../target/parallel-test-executor.hpi ]; then mvn -f .. -DskipTests install; fi + if [ \! -f ../target/parallel-test-executor.hpi ]; then mvn -f .. -Pquick-build install; fi if [ \! -f target/test-classes/test-dependencies/index -o \ pom.xml -nt target/test-classes/test-dependencies/index -o \ ../target/parallel-test-executor.hpi -nt target/test-classes/test-dependencies/parallel-test-executor.hpi ]; then \ mvn clean validate hpi:resolve-test-dependencies; fi @# TODO would be more efficient to move Dockerfile and all it references into a subdirectory, or use .dockerignore - rm -rf plugins - mkdir plugins - cp -v target/test-classes/test-dependencies/*.hpi plugins - -build: copy-plugins - docker build -t $(IMAGE) . -# http://stackoverflow.com/q/23544282/12916 unclear how best to ensure that the jenkins user can write to this volume -volume: - docker volume create --name=m2repo - docker run --rm -v m2repo:/m2repo ubuntu chmod -v a+rw /m2repo +PHONY: clean +clean: + rm -rf target + docker-compose down -v + docker image rm demo-jenkins || true -run: build volume - $(DOCKER_RUN) $(IMAGE) +PHONY: run +run: copy-plugins + ./run.sh diff --git a/demo/create-pr.sh b/demo/create-pr.sh new file mode 100755 index 00000000..9dec8d18 --- /dev/null +++ b/demo/create-pr.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +set -euxo pipefail +export TOKEN=$(cat target/gitea_token.txt) +pushd target/repo > /dev/null + export BRANCH_NAME=experiment-$(openssl rand -hex 6) + export TARGET_BRANCH=main + git checkout -b "$BRANCH_NAME" + git -c user.email=demo@jenkins-ci.org -c user.name="Parallel Test Executor Demo" commit --allow-empty -m "Empty commit" + git push + curl -X 'POST' \ + 'http://localhost:3000/api/v1/repos/jenkins/demo/pulls' \ + -H "Authorization: token $TOKEN" \ + -H 'accept: application/json' \ + -H 'Content-Type: application/json' \ + -d "{ + \"base\": \"$TARGET_BRANCH\", + \"title\": \"A pull request from $BRANCH_NAME\", + \"body\": \"Some description\", + \"head\": \"$BRANCH_NAME\" + }" +popd > /dev/null diff --git a/demo/credentials.xml b/demo/credentials.xml new file mode 100644 index 00000000..5b69110c --- /dev/null +++ b/demo/credentials.xml @@ -0,0 +1,8 @@ + + GLOBAL + gitea + + jenkins + SECRET + false + diff --git a/demo/docker-compose.yml b/demo/docker-compose.yml new file mode 100644 index 00000000..2527fa24 --- /dev/null +++ b/demo/docker-compose.yml @@ -0,0 +1,45 @@ +version: "3.9" +networks: + demo: + external: false +volumes: + m2repo: + gitea: +services: + gitea: + image: gitea/gitea:1.18.0 + container_name: gitea + environment: + - USER_UID=1000 + - USER_GID=1000 + - GITEA__server__HTTP_PORT=3000 + - GITEA__server__SSH_PORT=22 + - GITEA__server__ROOT_URL=http://localhost:3000/ + - GITEA__server__DOMAIN=localhost + - GITEA__database__DB_TYPE=sqlite3 + - GITEA__security__INSTALL_LOCK=true + restart: always + networks: + - demo + volumes: + - gitea:/data + - /etc/timezone:/etc/timezone:ro + - /etc/localtime:/etc/localtime:ro + ports: + - "3000:3000" + - "222:22" + jenkins: + container_name: jenkins + networks: + - demo + build: + context: . + ports: + - "8080:8080" + volumes: + - m2repo:/m2repo:rw + healthcheck: + test: [ "CMD", "curl", "-f", "http://localhost:8080" ] + interval: 5s + timeout: 3s + diff --git a/demo/pom.xml b/demo/pom.xml index 186bc644..8349dea4 100644 --- a/demo/pom.xml +++ b/demo/pom.xml @@ -5,15 +5,14 @@ org.jenkins-ci.plugins plugin - 4.34 + 4.53 parallel-test-executor-demo 1.0-SNAPSHOT hpi - 2.319.3 - 8 + 2.361.4 Parallel Test Executor Demo @@ -32,7 +31,7 @@ org.jenkins-ci.plugins parallel-test-executor - 1.13 + 999999-SNAPSHOT test @@ -111,32 +110,22 @@ 82.vc2a_3f0f7a_291 test + + org.jenkins-ci.plugins + gitea + 1.4.5 + test + io.jenkins.tools.bom - bom-2.319.x - 1148.v7261f385f859 + bom-2.361.x + 1775.vf0577a_a_01778 import pom - - org.jenkins-ci.plugins - parameterized-trigger - 2.43 - - - org.jenkins-ci - symbol-annotation - - - - - org.jenkins-ci.main - maven-plugin - 3.16 - diff --git a/demo/run.sh b/demo/run.sh new file mode 100755 index 00000000..679337b8 --- /dev/null +++ b/demo/run.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash +set -euo pipefail + +docker compose up -d --wait +mkdir -p target +docker-compose exec -u 1000:1000 gitea gitea admin user create --admin --username jenkins --random-password --email demo@jenkins.io > target/gitea_output.txt || true +docker-compose exec -u 1000:1000 gitea gitea admin user generate-access-token --username jenkins --raw > target/gitea_token.txt +export TOKEN=$(cat target/gitea_token.txt) +wget -O target/jenkins-cli.jar -o /dev/null http://localhost:8080/jnlpJars/jenkins-cli.jar +sed -e "s/SECRET/$TOKEN/" credentials.xml | java -jar target/jenkins-cli.jar -s http://localhost:8080/ update-credentials-by-xml "SystemCredentialsProvider::SystemContextResolver::jenkins" "(global)" gitea + +curl -X 'POST' \ + 'http://localhost:3000/api/v1/user/repos' \ + -H "Authorization: token $TOKEN" \ + -H 'accept: application/json' \ + -H 'Content-Type: application/json' \ + -d '{ + "auto_init": true, + "default_branch": "main", + "name": "demo" +}' + +git clone http://jenkins:$TOKEN@localhost:3000/jenkins/demo.git target/repo +cp -R repo target/ +pushd target/repo + bash ../../gen.sh + git add . + git -c user.email=demo@jenkins-ci.org -c user.name="Parallel Test Executor Demo" commit -m "Initial commit" + git push origin -u +popd + +GITEA_USERNAME=$(grep "New user" < target/gitea_output.txt | cut -f 2 -d "'") +GITEA_PASSWORD=$(grep password < target/gitea_output.txt | cut -f 2 -d "'") + +echo "Demo initialized" +echo "Gitea is available on http://localhost:3000 using $GITEA_USERNAME $GITEA_PASSWORD" +echo "Jenkins is available on http://localhost:8080" +echo "The demo git repo is available in target/repo and can be accessed at http://localhost:3000/jenkins/demo" +open http://localhost:8080/