-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update demo to include gitea for multibranch support
- Loading branch information
Showing
10 changed files
with
197 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 [email protected] -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 [email protected] -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version='1.1' encoding='UTF-8'?> | ||
<com.cloudbees.plugins.credentials.SystemCredentialsProvider plugin="[email protected]"> | ||
<domainCredentialsMap class="hudson.util.CopyOnWriteMap$Hash"> | ||
<entry> | ||
<com.cloudbees.plugins.credentials.domains.Domain> | ||
<specifications/> | ||
</com.cloudbees.plugins.credentials.domains.Domain> | ||
<java.util.concurrent.CopyOnWriteArrayList> | ||
<com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl plugin="[email protected]"> | ||
<scope>GLOBAL</scope> | ||
<id>gitea</id> | ||
<description/> | ||
<username>jenkins</username> | ||
<password>SECRET</password> | ||
<usernameSecret>false</usernameSecret> | ||
</com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl> | ||
</java.util.concurrent.CopyOnWriteArrayList> | ||
</entry> | ||
</domainCredentialsMap> | ||
</com.cloudbees.plugins.credentials.SystemCredentialsProvider> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,13 +3,25 @@ | |
<actions/> | ||
<description></description> | ||
<sources> | ||
<jenkins.branch.BranchSource> | ||
<source class="jenkins.plugins.git.GitSCMSource"> | ||
<remote>/tmp/repo</remote> | ||
<credentialsId></credentialsId> | ||
<includes>*</includes> | ||
<excludes></excludes> | ||
<ignoreOnPushNotifications>false</ignoreOnPushNotifications> | ||
<jenkins.branch.BranchSource plugin="[email protected]_f6cc"> | ||
<source class="org.jenkinsci.plugin.gitea.GiteaSCMSource" plugin="[email protected]"> | ||
<id>6126b51e-8b62-413c-9e82-333d0cf58bdb</id> | ||
<serverUrl>http://gitea:3000</serverUrl> | ||
<repoOwner>jenkins</repoOwner> | ||
<repository>demo</repository> | ||
<credentialsId>gitea</credentialsId> | ||
<traits> | ||
<org.jenkinsci.plugin.gitea.BranchDiscoveryTrait> | ||
<strategyId>1</strategyId> | ||
</org.jenkinsci.plugin.gitea.BranchDiscoveryTrait> | ||
<org.jenkinsci.plugin.gitea.OriginPullRequestDiscoveryTrait> | ||
<strategyId>1</strategyId> | ||
</org.jenkinsci.plugin.gitea.OriginPullRequestDiscoveryTrait> | ||
<org.jenkinsci.plugin.gitea.ForkPullRequestDiscoveryTrait> | ||
<strategyId>1</strategyId> | ||
<trust class="org.jenkinsci.plugin.gitea.ForkPullRequestDiscoveryTrait$TrustContributors"/> | ||
</org.jenkinsci.plugin.gitea.ForkPullRequestDiscoveryTrait> | ||
</traits> | ||
</source> | ||
<strategy class="jenkins.branch.DefaultBranchPropertyStrategy"> | ||
<properties class="empty-list"/> | ||
|
11 changes: 11 additions & 0 deletions
11
demo/JENKINS_HOME/org.jenkinsci.plugin.gitea.servers.GiteaServers.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version='1.1' encoding='UTF-8'?> | ||
<org.jenkinsci.plugin.gitea.servers.GiteaServers plugin="[email protected]"> | ||
<servers> | ||
<org.jenkinsci.plugin.gitea.servers.GiteaServer> | ||
<displayName>gitea</displayName> | ||
<serverUrl>http://gitea:3000</serverUrl> | ||
<manageHooks>false</manageHooks> | ||
<credentialsId>gitea</credentialsId> | ||
</org.jenkinsci.plugin.gitea.servers.GiteaServer> | ||
</servers> | ||
</org.jenkinsci.plugin.gitea.servers.GiteaServers> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 [email protected] -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl plugin="[email protected]"> | ||
<scope>GLOBAL</scope> | ||
<id>gitea</id> | ||
<description/> | ||
<username>jenkins</username> | ||
<password>SECRET</password> | ||
<usernameSecret>false</usernameSecret> | ||
</com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 [email protected] > 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 [email protected] -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/ |