From f41362beb4668211f5f3b3caf2728a5710b0cf1a Mon Sep 17 00:00:00 2001 From: Alex Dolzhenkov Date: Sun, 14 Jan 2024 21:28:12 +1300 Subject: [PATCH] #108 Add docker container support --- Dockerfile | 47 +++++++++++++++++++++++++++++++++++++++++++++++ README.md | 26 +++++++++++++++++++++++++- 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..3785e02c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,47 @@ +# Build docker container: docker build -t voxel-engine . +# Build project: docker run --rm -it -v$(pwd):/project voxel-engine bash -c "cmake -DCMAKE_BUILD_TYPE=Release -Bbuild && cmake --build build" +# Run project in docker: docker run --rm -it -v$(pwd):/project -v/tmp/.X11-unix:/tmp/.X11-unix -v${XAUTHORITY}:/home/user/.Xauthority:ro -eDISPLAY --network=host voxel-engine ./build/VoxelEngine + +FROM debian:bullseye-slim +LABEL Description="Docker container for building VoxelEngine for Linux" + +# Install dependencies +RUN apt-get update && apt-get install --no-install-recommends -y \ + git \ + g++ \ + make \ + cmake \ + xauth \ + gdb \ + gdbserver \ + libglfw3-dev \ + libglfw3 \ + libglew-dev \ + libglm-dev \ + libpng-dev \ + libopenal-dev \ + libluajit-5.1-dev \ + ca-certificates \ + && rm -rf /var/lib/apt/lists/* + +# CMake missing LUA_INCLUDE_DIR and LUA_LIBRARIES fix: +RUN ln -s /usr/lib/x86_64-linux-gnu/libluajit-5.1.a /usr/lib/x86_64-linux-gnu/liblua5.1.a \ + && ln -s /usr/include/luajit-2.1 /usr/include/lua + +# Install LuaJIT: +RUN git clone https://luajit.org/git/luajit.git \ + && cd luajit \ + && make && make install INSTALL_INC=/usr/include/lua \ + && cd .. && rm -rf luajit + +# Create default user, due to: +# - Build and test artifacts have user permissions and not root permissions +# - Don't give root privileges from host to containers (security) +ARG USER=user +ARG UID=1000 +ARG GID=1000 +RUN useradd -m ${USER} --uid=${UID} +USER ${UID}:${GID} + +# Project workspace +WORKDIR /project diff --git a/README.md b/README.md index f51329ed..097c7526 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ - **Tab** - open inventory - **W** **A** **S** **D** - movement - **Space** - jump -- **LMB** - remove block +- **LMB** - remove block - **RMB** - place block - **F** - toggle flight mode - **N** - noclip mode @@ -74,3 +74,27 @@ brew install glfw3 glew glm libpng lua luajit openal-soft ``` If homebrew for some reason could not install the necessary packages: ```lua luajit openal-soft```, then download, install and compile them manually (Lua, LuaJIT and OpenAL). + +## Build using Docker + +### Step 0. Install docker on your system + +See https://docs.docker.com/engine/install + +### Step 1. Build docker container + +``` +docker build -t voxel-engine . +``` + +### Step 2. Build project using the docker container + +``` +docker run --rm -it -v$(pwd):/project voxel-engine bash -c "cmake -DCMAKE_BUILD_TYPE=Release -Bbuild && cmake --build build" +``` + +### Step 3. Run project using the docker container + +``` +docker run --rm -it -v$(pwd):/project -v/tmp/.X11-unix:/tmp/.X11-unix -v${XAUTHORITY}:/home/user/.Xauthority:ro -eDISPLAY --network=host voxel-engine ./build/VoxelEngine +```