Kirsle.net logo Kirsle.net

Dockerfiles to build Doodle

The general steps to build my Doodle game on Linux are:

  • Install the Go language itself to compile Go software
  • Install C libraries my game uses: SDL2 and SDL2_TTF
  • Put my source code in the right $GOPATH environment for Go
  • Install my Go dependencies and,
  • Build my program to a binary for your current operating system

These Dockerfiles run through exactly these steps from base images of Ubuntu, Debian and Fedora.

The docker build steps set up the Docker images with all the dependencies and tools installed and ready to go. Then you docker run to actually build the app and output a zip and tar files like "doodle-0.0.1-alpha.zip"

Fedora.dockerfile

FROM fedora:latest
MAINTAINER Noah Petherbridge <root@kirsle.net>
ENV GOPATH /home/builder/go

# Update all the software and then install Go, git, SDL2 and other dependencies
RUN dnf -y update && \
	dnf -y install git zip golang SDL2-devel SDL2_ttf-devel make && \
	dnf clean all

# Create a user to build the packages.
RUN useradd builder -u 1000 -m -G users

# Add the project to the GOPATH
ADD . /home/builder/go/src/git.kirsle.net/apps/doodle
WORKDIR /home/builder/go/src/git.kirsle.net/apps/doodle
RUN chown -R builder:builder /home/builder/go

# Build the app as the `builder` user
USER builder

# The `make setup` command runs my "go get ./..." to fetch my Go dependencies
RUN make setup

# This command is what actually runs when I do `docker run`
# The `make __docker.dist` command runs a shell script that builds and zips
# up the game.
CMD ["make", "__docker.dist"]

Ubuntu.dockerfile

Debian's is basically the same except FROM debian:latest

FROM ubuntu:latest
MAINTAINER Noah Petherbridge <root@kirsle.net>
ENV GOPATH /home/builder/go

# Update all the software and then install Go, git, SDL2 and other dependencies
RUN apt update && \
	apt -y upgrade && \
	apt -y install git zip golang libsdl2-dev libsdl2-ttf-dev make && \
	apt clean

# Create a user to build the packages.
RUN useradd builder -u 1000 -m -G users

# Add the project to the GOPATH
ADD . /home/builder/go/src/git.kirsle.net/apps/doodle
WORKDIR /home/builder/go/src/git.kirsle.net/apps/doodle
RUN chown -R builder:builder /home/builder/go

# Build the app as the `builder` user
USER builder
RUN make setup
CMD ["make", "__docker.dist"]