Compare commits

...

7 Commits

5 changed files with 129 additions and 87 deletions

View File

@@ -1,26 +1,23 @@
FROM eclipse-temurin:17-jdk FROM eclipse-temurin:21-jdk
ARG RUNNABLE_SERVER_JAR ARG RUNNABLE_SERVER_JAR
# create directories
WORKDIR /data WORKDIR /data
RUN mkdir jar bundle workdir RUN mkdir bin bundle workdir
ADD $RUNNABLE_SERVER_JAR jar/paper.jar # add executable files
ADD $RUNNABLE_SERVER_JAR bin/paper.jar
ADD run.sh bin/run.sh
RUN java -DbundlerRepoDir=/data/bundle -Dpaperclip.patchonly=true -jar /data/jar/paper.jar # download paper libraries and apply patches
RUN java -DbundlerRepoDir=/data/bundle -Dpaperclip.patchonly=true -jar /data/bin/paper.jar
# configure max heap size
ENV MAXMEM=1024M ENV MAXMEM=1024M
EXPOSE 25565 EXPOSE 25565
VOLUME /data/workdir VOLUME /data/workdir
WORKDIR /data/workdir WORKDIR /data/workdir
CMD java -Xmx$MAXMEM -XX:+UseG1GC -XX:+ParallelRefProcEnabled \ CMD ["sh", "/data/bin/run.sh"]
-XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions \
-XX:G1ReservePercent=15 -XX:G1NewSizePercent=20 -XX:G1MaxNewSizePercent=30 \
-XX:G1HeapRegionSize=8M -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 \
-XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 \
-XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem -XX:MaxTenuringThreshold=1 \
-XX:MaxHeapFreeRatio=30 -XX:MinHeapFreeRatio=5 \
-DbundlerRepoDir=/data/bundle \
-jar /data/jar/paper.jar nogui

88
Jenkinsfile vendored Normal file
View File

@@ -0,0 +1,88 @@
/*
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()
sh "docker image rm ${docker_tag} ${docker_tag_version}"
}
}
}

View File

@@ -1,10 +1,28 @@
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"
services: services:
paper: paper:
image: "pandacubefr/paper:(version)" image: "cr.pandacube.fr/paper:(version)"
container_name: (server name) container_name: (server name)
stdin_open: true # docker run -i stdin_open: true # docker run -i
tty: true # docker run -t tty: true # docker run -t

View File

@@ -1,72 +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: Cant 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
#java -version
# run it to generate final jar, but not launching the actual server (-v option)
#echo "Running Paperclip..."
#mkdir bundle
#java -DbundlerRepoDir=bundle -Dpaperclip.patchonly=true -jar $RUNNABLE_SERVER_JAR
# important that versions/ comes first. It will be extracted first,
# and following extraction will not override any file
#find bundle/versions/ bundle/libraries/ -type f -name '*.jar' > jars.txt
DOCKER_TAG="pandacubefr/paper:"$MC_VERSION"-"$PAPER_BUILD
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_IMAGE_FILE="Paper-docker-image-"$MC_VERSION"-"$PAPER_BUILD".tar.gz"
echo "Saving docker image to "$DOCKER_IMAGE_FILE
docker save -o $DOCKER_IMAGE_FILE $DOCKER_TAG
#mkdir uberjar
#for jar in `cat jars.txt`; do
# unzip -d uberjar -nq $jar
#done
#(
# cd uberjar
# # exclude some stuff, especially about jar signature and stuff
# rm -f META-INF/*.SF META-INF/*.DSA META-INF/*.RSA
# # create the uber jar
# zip -r '../'$UBER_SERVER_JAR *
#)
#mvn install:install-file -Dfile=$UBER_SERVER_JAR -DgroupId=io.papermc.paper -DartifactId=paper -Dversion=$MC_VERSION-$PAPER_BUILD-SNAPSHOT -Dpackaging=jar

11
run.sh Normal file
View File

@@ -0,0 +1,11 @@
#!/bin/sh
exec java -Xmx$MAXMEM -XX:+UseG1GC -XX:+ParallelRefProcEnabled \
-XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions \
-XX:G1ReservePercent=15 -XX:G1NewSizePercent=20 -XX:G1MaxNewSizePercent=30 \
-XX:G1HeapRegionSize=8M -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 \
-XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 \
-XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem -XX:MaxTenuringThreshold=1 \
-XX:MaxHeapFreeRatio=30 -XX:MinHeapFreeRatio=5 \
-DbundlerRepoDir=/data/bundle \
-jar /data/bin/paper.jar nogui