From 0f69f11b78ccf6eb094c6aefb72ebf661df92e05 Mon Sep 17 00:00:00 2001 From: Thulio Ferraz Assis <3149049+f0rmiga@users.noreply.github.com> Date: Thu, 26 Sep 2019 18:23:08 -0700 Subject: [PATCH] Improved Docker support --- .dockerignore | 2 ++ Dockerfile | 74 ++++++++++++++++++++++++++++++++------------------- README.md | 25 +++++++++++++---- build.sh | 3 --- run.sh | 19 ------------- 5 files changed, 69 insertions(+), 54 deletions(-) create mode 100644 .dockerignore delete mode 100755 build.sh delete mode 100755 run.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..2f1255d2 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +/build/ +Dockerfile diff --git a/Dockerfile b/Dockerfile index e1ba3f5f..f4e4df4b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,31 +1,51 @@ -from ubuntu:latest +FROM ubuntu@sha256:b88f8848e9a1a4e4558ba7cfc4acc5879e1d0e7ac06401409062ad2627e6fb58 AS builder -WORKDIR /app +RUN apt-get update; \ + apt-get install -y \ + build-essential \ + cmake \ + git-core \ + libboost-atomic1.65-dev \ + libboost-chrono1.65-dev \ + libboost-date-time1.65-dev \ + libboost-filesystem1.65-dev \ + libboost-system1.65-dev \ + libboost-thread1.65-dev \ + libglew-dev \ + liblua5.1-0-dev \ + libncurses5-dev \ + libopenal-dev \ + libssl-dev \ + libvorbis-dev \ + mercurial \ + zlib1g-dev; \ + apt-get clean && apt-get autoclean -RUN apt-get update; apt-get install -y \ - build-essential \ - cmake \ - git-core \ - libboost-all-dev \ - libglew-dev \ - liblua5.1-0-dev \ - libopenal-dev \ - libphysfs-dev \ - libssl-dev \ - libvorbis-dev \ - zlib1g-dev +WORKDIR / +RUN hg clone -r stable-2.0 http://hg.icculus.org/icculus/physfs/ +WORKDIR /physfs/build/ +RUN cmake .. +RUN make -j$(grep -c ^process /proc/cpuinfo) +RUN make install +RUN mv /usr/local/lib/libphysfs.a /usr/lib/x86_64-linux-gnu/. -RUN apt-get install -y \ - libncurses5-dev \ - mercurial; \ - hg clone -r stable-2.0 http://hg.icculus.org/icculus/physfs/; \ - cd physfs; \ - mkdir build && cd build && cmake .. && make && make install; \ - mv /usr/local/lib/libphysfs.a /usr/lib/x86_64-linux-gnu/. +COPY ./src/ /otclient/src/. +COPY CMakeLists.txt /otclient/. +WORKDIR /otclient/build/ +RUN cmake -DCMAKE_CXX_LINK_FLAGS=-no-pie .. +RUN make -j$(grep -c ^process /proc/cpuinfo) +RUN strip --strip-unneeded otclient -ADD . /app - -# Build application -RUN mkdir -p build && cd build && cmake .. && make -j$(grep -c ^process /proc/cpuinfo); - -CMD cd build; ./otclient +FROM ubuntu@sha256:b88f8848e9a1a4e4558ba7cfc4acc5879e1d0e7ac06401409062ad2627e6fb58 +RUN apt-get update; \ + apt-get install -y \ + libglew2.0 \ + libopenal1; \ + apt-get clean && apt-get autoclean +COPY --from=builder /otclient/build/otclient /otclient/bin/otclient +COPY ./data/ /otclient/data/. +COPY ./mods/ /otclient/mods/. +COPY ./modules/ /otclient/modules/. +COPY ./init.lua /otclient/. +WORKDIR /otclient +CMD ["./bin/otclient"] diff --git a/README.md b/README.md index d36dcf65..99b8a1e3 100644 --- a/README.md +++ b/README.md @@ -38,13 +38,28 @@ In short, if you need to compile OTClient, follow these tutorials: ### Build and run with Docker -To build and run the client: -``` -./build.sh -./run.sh +To build the image: + +```sh +docker build -t edubart/otclient . ``` -The build step should be run just when something on implementation changes. +To run the built image: + +```sh +# Disable access control for the X server. +xhost + + +# Run the container image with the required bindings to the host devices and volumes. +docker run -it --rm \ + --env DISPLAY \ + --volume /tmp/.X11-unix:/tmp/.X11-unix \ + --device /dev/dri \ + --device /dev/snd edubart/otclient /bin/bash + +# Enable access control for the X server. +xhost - +``` ### Need help? diff --git a/build.sh b/build.sh deleted file mode 100755 index 35ce50fd..00000000 --- a/build.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash - -docker build -t edubart/otclient . diff --git a/run.sh b/run.sh deleted file mode 100755 index 288c22bd..00000000 --- a/run.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bash - -SE_enforcing=`getenforce` || true - -sudo setenforce Permissive || true - -# Enable any host to connect on X Org -xhost + - -docker run -ti --rm \ - -e DISPLAY \ - -v /tmp/.X11-unix:/tmp/.X11-unix \ - --device /dev/dri \ - edubart/otclient - -# Enable any host to connect on X Org -xhost - - -sudo setenforce $SE_enforcing || true