Author Topic: Docker  (Read 2402 times)

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4955
Docker
« on: April 26, 2018, 03:38:32 PM »
I started on some Docker experiments that might help with compiling, testing, and packaging binaries for Linux distribution, which could be easily run from Windows.

This work comes from me finding ways to adjust to the GitHub migration, and experimenting with adding NAS2D as a git submodule. I did the obvious default thing, where the nas2d-core folder was hanging off the root of the OPHD project. This required a few minor Makefile changes, mostly concerning paths, to get things to compile. Or at least that was the plan. In practice however, I ran into some vagaries of my particular system setup, where I have a mix of system package manager installed parts of SDL, and other more up-to-date source install components. As such, the compile wasn't working so smoothly, and so I was not entirely happy with my Makefile changes. It seemed a little too brittle and dependent on the environment.

To address the environment issues, I turned to Docker. By creating a Dockerfile, I could write the instructions to build a standard environment, that would contain everything necessary to compile and run the code, and that description could be added to version control. It was based on the Ubuntu 18.04 beta image, the new version of Ubuntu due out this month. This version of Ubuntu has updated packages, and so it was possible to simply install dependencies using the system package manager. No complicated source install scripts required.

The Ubuntu base image can be downloaded automatically by Docker from the standard image registry. There is a Windows version of Docker, which basically runs the Linux image in a virtual machine, so it'd be an easy way to compile or test code in a Linux environment, even if you were developing on Windows.

Here's the Dockerfile I was using:
Code: [Select]
FROM ubuntu:devel

RUN apt-get update && apt-get install -y \
    libglew-dev \
    libphysfs-dev \
    libsdl2-dev \
    libsdl2-image-dev \
    libsdl2-mixer-dev \
    libsdl2-ttf-dev \
  && rm -rf /var/lib/apt/lists/*

RUN useradd -m -s /bin/bash user
USER user

VOLUME /code
WORKDIR /code

CMD cd nas2d-core && make && cd .. && make

The "ubuntu:devel" base image points to the most recent development version of Ubuntu, which is currently the 18.04 beta image. The GLEW, Physfs, and SDL packages are installed. A non-root "user" is added. A "/code" folder is created and set as the current working directory. The default command when the Docker image is run is then set, which will compile nas2d-core, and then OutpostHD.

I'm thinking the default command should probably be tweaked a bit, and the Dockerfile be included as part of NAS2D rather than OutpostHD.

An example Docker command to run the image is:
Code: [Select]
docker run --rm -t -v `pwd`:/code docker_outposthd-build

The --rm removes the container instance after it has finished running. The -t allocates a pseudo-tty (enables coloring of terminal error messages during compile). The -v is to mount a volume, mapping the current working directory (returned by the command "pwd") to the "/code" folder within the Docker image. This is how the image gets access to the code to compile, and also how it produces compiled results accessible to the host. Finally, the name of the Docker image to run is given.


I also experimented with a docker-compose.yml file to auto build and run the Docker image, as well as another Dockerfile based on the older Ubuntu 16.04 image, which does a source install of needed packages. That's about where I stopped. I'm not certain if it makes sense to build Dockerfiles to test with different system environments, or just stick with a single ... canonical environment.  ;)

Offline leeor_net

  • Administrator
  • Hero Member
  • *****
  • Posts: 2352
  • OPHD Lead Developer
    • LairWorks Entertainment
Re: Docker
« Reply #1 on: April 27, 2018, 10:02:19 AM »
I very much look forward to seeing how this progresses. I still really want to see OutpostHD running on the Big Three (Windows, macOS X, Linux).