From cd94a6112ca0779b9323d8f041c7f6527c9fe679 Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Tue, 16 Jan 2024 16:51:00 +0100 Subject: [PATCH] Jenkins pipeline --- Jenkinsfile | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++ Readme.md | 25 +++++++++++++++--- 2 files changed, 95 insertions(+), 3 deletions(-) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..36260dd --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,73 @@ +/* +Required plugins in Jenkins: +- Pipeline Utility Steps +- Docker Pipeline +*/ + +def geyser_version +def geyser_build +def runnable_jar +def docker_tag +def docker_tag_latest + +pipeline { + agent any + environment { + URL_BUILD = 'https://download.geysermc.org/v2/projects/geyser/versions/latest/builds/latest' + URL_DOWNLOAD = URL_BUILD + '/downloads/standalone' + DOCKER_TAG_BASE = 'cr.pandacube.fr/geyser' + DOCKER_CR_PANDACUBE_CREDENTIALS = 'cr-pandacube-credentials' + } + + stages { + + stage('Get build data') { + steps { + sh 'curl -L -s $URL_BUILD -o build_infos.json' + script { + def build_infos = readJSON file: 'build_infos.json' + geyser_version = build_infos.version + geyser_build = build_infos.build + runnable_jar = "Geyser-${geyser_version}-${geyser_build}.jar" + docker_tag = "${DOCKER_TAG_BASE}:${GEYSER_VERSION}-${GEYSER_BUILD}" + docker_tag_latest = "${DOCKER_TAG_BASE}:latest" + } + echo "Geyser version ${geyser_version} build #${geyser_build}" + } + } + + stage('Download jar') { + steps { + echo "From $URL_DOWNLOAD" + echo "To $runnable_jar" + sh "curl -L -o '$runnable_jar' '$URL_DOWNLOAD'" + } + } + + stage('Build Docker image') { + steps { + script { + docker.build(docker_tag, "--build-arg RUNNABLE_JAR=$runnable_jar .") + } + sh "docker tag ${docker_tag} ${docker_tag_latest}" + } + } + + stage('Push Docker image') { + steps { + script { + docker.withRegistry('cr.pandacube.fr', DOCKER_CR_PANDACUBE_CREDENTIALS) { + docker.image(docker_tag).push() + docker.image(docker_tag_latest).push() + } + } + } + } + } + + post { + always { + cleanWs() + } + } +} \ No newline at end of file diff --git a/Readme.md b/Readme.md index 6ef7791..1b1811b 100644 --- a/Readme.md +++ b/Readme.md @@ -1,10 +1,29 @@ -Docker Compose Example +# GeyserDockerBuilder + +Jenkins pipeline to build a Docker image of Geyser Standalone. + +```bash +build.sh # the old pipeline script, not used anymore +Dockerfile # used to build the image +Jenkinsfile # the new pipeline script +Readme.md # you are reading this file +run.sh # entrypoint of the docker image +``` + +## Pipeline process + +- Fetches the information about the latest build of Geyser (version, build number), from the [GeyserMC API](https://download.geysermc.org/v2/projects) +- Downloads the Geyser Standalone jar file. +- Builds the docker image with the downloaded jar and the entrypoint script. +- Pushes the image to the container registry with the tags `latest` and `$geyser_version-$geyser_build` (e.g. `2.2.0-408`) + +## Docker Compose Example ```yml version: "3" services: - (server-name): - image: "cr.pandacube.fr/geyser:(version)" + geyser: + image: "cr.pandacube.fr/geyser:latest" stdin_open: true # docker run -i tty: true # docker run -t user: "1000:1000" # uid and gid of owner of working dir