Convert to Jenkins Pipeline
This commit is contained in:
parent
88d14916af
commit
6899a79ce5
87
Jenkinsfile
vendored
Normal file
87
Jenkinsfile
vendored
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
/*
|
||||||
|
Required plugins in Jenkins:
|
||||||
|
- Pipeline Utility Steps
|
||||||
|
- Docker Pipeline
|
||||||
|
*/
|
||||||
|
|
||||||
|
def app_version
|
||||||
|
def app_build
|
||||||
|
def url_download
|
||||||
|
def app_filename
|
||||||
|
def docker_tag
|
||||||
|
def docker_tag_latest
|
||||||
|
|
||||||
|
pipeline {
|
||||||
|
agent any
|
||||||
|
|
||||||
|
parameters {
|
||||||
|
string(name: 'MC_VERSION', description: 'The Minecraft version to build.')
|
||||||
|
}
|
||||||
|
|
||||||
|
environment {
|
||||||
|
URL_BASE = 'https://api.papermc.io/v2/projects/paper'
|
||||||
|
URL_VERSION_INFOS = "${URL_BASE}/versions/${params.MC_VERSION}"
|
||||||
|
|
||||||
|
DOCKER_TAG_BASE = 'cr.pandacube.fr/paper'
|
||||||
|
DOCKER_REGISTRY_URL = 'https://cr.pandacube.fr'
|
||||||
|
DOCKER_REGISTRY_CREDENTIALS = 'cr-pandacube-credentials'
|
||||||
|
}
|
||||||
|
|
||||||
|
stages {
|
||||||
|
|
||||||
|
stage('Get build data') {
|
||||||
|
steps {
|
||||||
|
sh "curl -L -s '$URL_VERSION_INFOS' -o version_infos.json"
|
||||||
|
script {
|
||||||
|
def version_infos = readJSON file: 'version_infos.json'
|
||||||
|
|
||||||
|
app_version = params.MC_VERSION
|
||||||
|
app_build = version_infos.builds[-1]
|
||||||
|
url_download = "${URL_VERSION_INFOS}/builds/${app_build}/downloads/paper-${app_version}-${app_build}.jar"
|
||||||
|
app_filename = "Paper-${MC_VERSION}-${app_build}.jar"
|
||||||
|
|
||||||
|
docker_tag = "${DOCKER_TAG_BASE}:${app_version}-${app_build}"
|
||||||
|
docker_tag_version = "${DOCKER_TAG_BASE}:${app_version}"
|
||||||
|
}
|
||||||
|
echo "Paper version ${app_version} build #${app_build}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Download jar') {
|
||||||
|
steps {
|
||||||
|
sh "curl -L -o '$app_filename' '$url_download'"
|
||||||
|
}
|
||||||
|
post {
|
||||||
|
success {
|
||||||
|
archiveArtifacts artifacts: 'Paper-*.jar', fingerprint: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Build Docker image') {
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
docker.build(docker_tag, "--build-arg RUNNABLE_SERVER_JAR=$app_filename .")
|
||||||
|
}
|
||||||
|
sh "docker tag ${docker_tag} ${docker_tag_version}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Push Docker image') {
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
docker.withRegistry(DOCKER_REGISTRY_URL, DOCKER_REGISTRY_CREDENTIALS) {
|
||||||
|
docker.image(docker_tag).push()
|
||||||
|
docker.image(docker_tag_version).push()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
post {
|
||||||
|
cleanup {
|
||||||
|
cleanWs()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
20
Readme.md
20
Readme.md
@ -1,4 +1,22 @@
|
|||||||
Docker Compose Example
|
# PaperDockerBuilder
|
||||||
|
|
||||||
|
Jenkins pipeline to build a Docker image of Paper.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
Dockerfile # used to build the Docker image
|
||||||
|
Jenkinsfile # the pipeline file
|
||||||
|
Readme.md # you are reading this file
|
||||||
|
run.sh # entrypoint of the Docker image
|
||||||
|
```
|
||||||
|
|
||||||
|
## Pipeline process
|
||||||
|
|
||||||
|
1. Fetches the information about the latest build of Paper for the provided MC version, from the [PaperMC API](https://api.papermc.io/v2/projects/paper)
|
||||||
|
2. Downloads the Paper jar file.
|
||||||
|
3. Builds the docker image with the downloaded jar and the entrypoint script, ensuring libraries are downloaded and Paper patch is applied.
|
||||||
|
4. Pushes the image to the container registry with the tags `$mc_version` (e.g. `1.20.1`) and `$mc_version-$paper_build` (e.g. `1.20.1-196`)
|
||||||
|
|
||||||
|
## Docker Compose Example
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
version: "3"
|
version: "3"
|
||||||
|
47
build.sh
47
build.sh
@ -1,47 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
URL_PROJECT='https://api.papermc.io/v2/projects/paper'
|
|
||||||
|
|
||||||
echo "Getting Paper last build id for MC "$MC_VERSION"..."
|
|
||||||
|
|
||||||
URL_VERSION=$URL_PROJECT'/versions/'$MC_VERSION
|
|
||||||
|
|
||||||
# get paper build version
|
|
||||||
if ! curl -s $URL_VERSION -o version_infos.json; then
|
|
||||||
echo -e "Error: Can't join API"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
if ! jq -r '.builds[-1]' -e < version_infos.json > build_number.txt; then
|
|
||||||
echo -e "API returned an error (probably MC_VERSION is not valid)"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
PAPER_BUILD=`cat build_number.txt`
|
|
||||||
URL_BUILD=$URL_VERSION'/builds/'$PAPER_BUILD
|
|
||||||
|
|
||||||
|
|
||||||
DOWNLOAD_REOBF=$URL_BUILD'/downloads/paper-'$MC_VERSION'-'$PAPER_BUILD'.jar'
|
|
||||||
|
|
||||||
# the runnable jar is actually paperclip
|
|
||||||
RUNNABLE_SERVER_JAR='Paper-'$MC_VERSION'-'$PAPER_BUILD'.jar'
|
|
||||||
#UBER_SERVER_JAR='Paper-uberjar-'$MC_VERSION'-'$PAPER_BUILD'.jar'
|
|
||||||
|
|
||||||
echo "Downloadling Paperclip for Paper-"$MC_VERSION"-"$PAPER_BUILD"..."
|
|
||||||
echo "From "$DOWNLOAD_REOBF
|
|
||||||
echo "To "$RUNNABLE_SERVER_JAR
|
|
||||||
curl -o $RUNNABLE_SERVER_JAR $DOWNLOAD_REOBF
|
|
||||||
|
|
||||||
|
|
||||||
DOCKER_TAG="cr.pandacube.fr/paper:"$MC_VERSION"-"$PAPER_BUILD
|
|
||||||
DOCKER_TAG_VERSION="cr.pandacube.fr/paper:"$MC_VERSION
|
|
||||||
echo "Building docker image with pre-downloaded and pre-patched files, with tag "$DOCKER_TAG
|
|
||||||
docker build --build-arg RUNNABLE_SERVER_JAR=$RUNNABLE_SERVER_JAR -t $DOCKER_TAG .
|
|
||||||
docker tag $DOCKER_TAG $DOCKER_TAG_VERSION
|
|
||||||
|
|
||||||
|
|
||||||
echo "Pushing image to Pandacube's container registry"
|
|
||||||
docker push $DOCKER_TAG
|
|
||||||
docker push $DOCKER_TAG_VERSION
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user