DigitalPulseSoftware / BurgWar

Burg'war est un jeu de plateforme/combat multijoueur en 2D écrit en C++17/Lua avec mon propre moteur de jeu : Nazara Engine.
MIT License
52 stars 9 forks source link

[FEATURE] Use alpine linux instead of debian for runtime image of Docker image #65

Open Elanis opened 3 years ago

Elanis commented 3 years ago

Instead of using Debian based image for runtime version of BurgWar's server docker image, we should use alpine which is lighter.

I already tried multiple times without really succeeding while doing #64. Here are my tries:

Build image

This image is having issue with 7z build on xmake during RUN /home/burgwar/.local/bin/xmake config --mode=releasedbg -y --build_mapeditor=false.

FROM alpine:latest as build-env

# Update system
RUN apk update
RUN apk upgrade

# Install all we need ...
RUN apk add alpine-sdk curl git unzip bash

# TEMP: Install nazara legacy dependencies
RUN apk add --no-cache openal-soft-dev libsndfile freetype sdl2 xcb-util-cursor-dev xcb-util-wm-dev xcb-util-keysyms libx11 mesa-dev mesa-gl assimp

# Install xmake with root (so it will install dependencies)
RUN curl -fsSL https://xmake.io/shget.text | /bin/bash

# Add user
RUN mkdir -p /home/burgwar
RUN addgroup -S burgwar
RUN adduser \
    --disabled-password \
    --gecos "" \
    --home /home/burgwar \
    --ingroup burgwar \
    burgwar
RUN chown -R burgwar:burgwar /home/burgwar

# That's ugly ... but we need it to install xmake :/
RUN mkdir -p /tmp/
RUN chmod -R 777 /tmp/ 

# Switch to burgwar user
USER burgwar
WORKDIR /home/burgwar

# Install xmake for burgwar user 
RUN curl -fsSL https://xmake.io/shget.text | /bin/bash

# Build server
COPY . /home/burgwar/

RUN /home/burgwar/.local/bin/xmake config --mode=releasedbg -y --build_mapeditor=false
RUN /home/burgwar/.local/bin/xmake -r BurgWarServer

# Compile every default map
RUN /home/burgwar/.local/bin/xmake -r BurgWarMapTool
RUN /home/burgwar/.local/bin/xmake run BurgWarMapTool -c /home/burgwar/maps/*

RUN /home/burgwar/.local/bin/xmake install -v -o build/ BurgWarServer

Runtime

This step (if run after a debian build) generate a segmentation fault during start. After investigations, it looks like it's recieving a command line argument (that is not existing) and making crash the image.

##############################
# Runtime image
##############################
FROM alpine:latest

LABEL org.opencontainers.image.authors="Jerome \"Lynix\" Leclercq;Axel \"Elanis\" Soupe"
EXPOSE 14768/udp
HEALTHCHECK --interval=1m --timeout=3s CMD netstat -nltpu | grep -c 14768

ENV LD_LIBRARY_PATH=/srv/lib:/lib64

# We need some gcc libs
RUN apk update
RUN apk add libgcc libc6-compat net-tools

# TEMP: Install nazara legacy dependencies
RUN apk add --no-cache openal-soft-dev libsndfile freetype sdl2 xcb-util-cursor-dev xcb-util-wm-dev xcb-util-keysyms libx11 mesa-dev mesa-gl assimp

# Add user
RUN mkdir -p /srv
RUN addgroup -S burgwar
RUN adduser \
    --disabled-password \
    --gecos "" \
    --home /srv \
    --ingroup burgwar \
    burgwar
RUN chown -R burgwar:burgwar /srv

USER burgwar
WORKDIR /srv/

COPY --from=build-env /home/burgwar/build/ .

# Copy mods and scripts from bw repo
COPY --from=build-env /home/burgwar/mods/ mods/
COPY --from=build-env /home/burgwar/scripts/ scripts/

# Copy every default map
COPY --from=build-env /home/burgwar/bin/linux_x86_64_debug/*.bmap /srv/

# Set entrypoint
ENTRYPOINT /srv/bin/BurgWarServer
Elanis commented 3 years ago

Other ideas submitted on discord: