Skip to content

Commit

Permalink
Added Docker support.
Browse files Browse the repository at this point in the history
The only change required to the core code was a modification to the root detection routine, to exempt Docker containers from the --asroot requirement.

To build the container:
$ docker build -t ckan .

To use the container to update all mods:
$ docker run --rm -v ${KSPDIR}:/kspdir ckan

To use the container to install MechJeb:
$ docker run --rm -v ${KSPDIR}:/kspdir ckan install MechJeb

Both of the last two lines require that the ${KSPDIR} value be set.

There is a docker-compose.yml supplied which will automatically do this for Linux users.

To use the YAML file to build the container:
$ docker-compose build ckan

To use the YAML file to update all mods:
$ docker-compose run --rm ckan

To use the YAML file to install MechJeb
$ docker-compose run --rm ckan install MechJeb
  • Loading branch information
mathuin authored and pjf committed Jun 19, 2016
1 parent 87beeaa commit f489599
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Cmdline/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -79,7 +80,10 @@ public static int Main(string[] args)
user = new ConsoleUser(options.Headless);
CheckMonoVersion(user, 3, 1, 0);

if ((Platform.IsUnix || Platform.IsMac) && CmdLineUtil.GetUID() == 0)
// Processes in Docker containers normally run as root.
// If we are running in a Docker container, do not require --asroot.
// Docker creates a .dockerenv file in the root of each container.
if ((Platform.IsUnix || Platform.IsMac) && CmdLineUtil.GetUID() == 0 && !File.Exists("/.dockerenv"))
{
if (!options.AsRoot)
{
Expand Down
30 changes: 30 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM mono
RUN echo '#!/bin/bash\n\
chown --reference=/kspdir/GameData -R /kspdir\n\
' >> /root/cleanup.sh
RUN chmod +x /root/cleanup.sh
RUN echo 'trap /root/cleanup.sh EXIT\n\
ckan()\n\
{\n\
mono /build/CmdLine.exe "$@" --kspdir /kspdir --headless\n\
}\n\
ckan update\n\
' >> /root/.bashrc
RUN echo '#!/bin/bash\n\
source /root/.bashrc\n\
ckan scan\n\
if [ "$#" -ne 0 ]; then\n\
ckan $@\n\
else\n\
ckan upgrade --all\n\
fi\n\
' >> /root/entrypoint.sh
RUN chmod +x /root/entrypoint.sh
RUN apt-get -y update && apt-get -y install libcurl4-openssl-dev
RUN mkdir /kspdir
VOLUME ["/kspdir"]
COPY . /source
WORKDIR /source
RUN nuget restore -NonInteractive
RUN xbuild /property:Configuration=Release /property:OutDir=/build/
ENTRYPOINT ["/root/entrypoint.sh"]
6 changes: 6 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: "2"
services:
ckan:
build: .
volumes:
- ~/.steam/steam/steamapps/common/Kerbal Space Program/:/kspdir

0 comments on commit f489599

Please sign in to comment.