Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Elanis opened this issue Nov 11, 2021 · 1 comment
Assignees
Labels
english Written in english enhancement New feature or request

Comments

@Elanis
Copy link
Contributor

Elanis commented Nov 11, 2021

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 Elanis added english Written in english enhancement New feature or request labels Nov 11, 2021
@Elanis
Copy link
Contributor Author

Elanis commented Nov 13, 2021

Other ideas submitted on discord:

  • static linking libstdc++ ( maybe LDFLAGS="-static-libstdc++" xmake )
  • using musl as build environment then scratch as runtime environment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
english Written in english enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants