Building #SpigotMC in a Windows #Container using #Docker (#WindowsContainer)Published on 24 Jun 2016
When I started working on a Windows container for my Minecraft server, I realized that my installation was also in dire need of an update to the latest version of SpigotMC. This does not come as a source release so it needs to be compiled manually. Therefore, I investigated how the build process can be banished into a container. Here is how it is done!
SpigotMC offers a very detailed guide how to build the SpigotMC Minecraft server from source. The developers have automated this process and provide it in a JAR called BuildTools.jar which must be downlaoded from the website. These build tools require a Java Runtime Environment and a Git installation.
I have created an image with all the prerequisites which is created using the following Dockerfile and my java docker image:
FROM nicholasdille/javaruntime:8u91 MAINTAINER firstname.lastname@example.org ADD https://github.com/git-for-windows/git/releases/download/v2.9.0.windows.1/Git-2.9.0-64-bit.exe c:\Git-2.9.0-64-bit.exe RUN c:\Git-2.9.0-64-bit.exe /SILENT RUN del c:\Git-2.9.0-64-bit.exe RUN md c:\build ADD RunBuildTools.ps1 c:\build ADD https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar /build/BuildTools.jar CMD powershell -command c:\build\RunBuildTools.ps1
As soon as a container is launched based on this image, the build tools are launched automatically by the PowerShell script called RunBuildTools.ps1:
$Env:JAVA_HOME = "$Env:ProgramFiles\Java\jre1.8.0u91" $Env:Path = "$Env:Path;$Env:ProgramFiles\Git\bin;$JAVA_HOME\bin" Set-Location -Path c:\build java.exe -jar BuildTools.jar
Note that the build succeeds although it is not launched from git-bash. Apparently PowerShell comes with the necessary aliases to resemble bash closely enough.
For my as well as your convenience, I have created a wrapper script for launching the container (
docker run) and waiting for the build to complete (
docker wait). After displaying the last five lines the script extracts the name of the resulting JAR file and copies it to the current directory (
@Echo Off docker run -d --name build nicholasdille/spigotmc-build docker wait build docker logs --tail=5 build for /f "usebackq tokens=4" %%i in (`docker logs --tail=1 build`) do docker cp build:c:\build\%%i .
I have also published all the source shown above in my GitHub repository for docker as well as published the resulting image in Docker Hub as nicholasdille/spigotmc-build.