mirror of
https://github.com/RYDE-WORK/ballistica.git
synced 2026-01-25 08:23:35 +08:00
Merge pull request #698 from Loup-Garou911XD/master
ballistica in docker :o
This commit is contained in:
commit
cfdab7419f
3
.dockerignore
Normal file
3
.dockerignore
Normal file
@ -0,0 +1,3 @@
|
||||
.venv/
|
||||
tools/pcommand
|
||||
build/cmake/
|
||||
@ -58,6 +58,7 @@
|
||||
multiple `SockAddr`s; it will attempt to contact the host on all of them and
|
||||
use whichever responds first. This allows us to pass both ipv4 and ipv6
|
||||
addresses when available and transparently use whichever is more performant.
|
||||
- Added `docker-build` and `docker-run` targets to Makefile
|
||||
|
||||
|
||||
### 1.7.34 (build 21823, api 8, 2024-04-26)
|
||||
|
||||
@ -63,4 +63,5 @@
|
||||
- Added support for joining using ipv6 address
|
||||
|
||||
### Loup Garou
|
||||
- Added sphinx documentation generation
|
||||
- Added sphinx documentation generation
|
||||
- Added docker build
|
||||
6
Makefile
6
Makefile
@ -222,6 +222,12 @@ pcommandbatch_speed_test: env
|
||||
|
||||
# Prebuilt binaries for various platforms.
|
||||
|
||||
docker-build:
|
||||
$(PCOMMAND) build_docker
|
||||
|
||||
docker-run:
|
||||
docker run -it bombsquad_server
|
||||
|
||||
# WSL is Linux but running under Windows, so it can target either. By default
|
||||
# we want these top level targets (prefab-gui-debug, etc.) to yield native
|
||||
# Windows builds from WSL, but this env var can be set to override that.
|
||||
|
||||
91
config/docker/Dockerfile
Normal file
91
config/docker/Dockerfile
Normal file
@ -0,0 +1,91 @@
|
||||
# if provided it will make debug build
|
||||
ARG cmake_build_type=Release
|
||||
|
||||
# system to start with the build with
|
||||
# currently will break for non ubuntu system
|
||||
ARG base_image=ubuntu:24.04
|
||||
|
||||
#-------------------------------BUILDER--------------------------------
|
||||
# Start with the base image
|
||||
FROM ${base_image} AS builder
|
||||
|
||||
# Renew the arg
|
||||
ARG cmake_build_type
|
||||
|
||||
ENV LANG en_US.utf8
|
||||
ENV LANGUAGE=en_US
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
ENV CMAKE_BUILD_TYPE=${cmake_build_type}
|
||||
|
||||
# Install build dependencies
|
||||
RUN apt-get update -y && \
|
||||
apt-get install -y \
|
||||
python3.12-dev \
|
||||
python3.12-venv \
|
||||
python3-pip \
|
||||
libsdl2-dev \
|
||||
libvorbisfile3 \
|
||||
freeglut3-dev \
|
||||
libopenal-dev \
|
||||
make \
|
||||
curl \
|
||||
rsync \
|
||||
clang-format \
|
||||
cmake \
|
||||
libvorbis-dev
|
||||
|
||||
# Copy source code
|
||||
COPY ./ /home/ubuntu/ballistica
|
||||
|
||||
WORKDIR /home/ubuntu/ballistica
|
||||
|
||||
# Compile the application
|
||||
RUN make cmake-server-build
|
||||
RUN mkdir ./../ballistica_cmake_server
|
||||
RUN mv build/cmake/* ./../ballistica_cmake_server
|
||||
|
||||
#-------------------------------RUNNER--------------------------------
|
||||
# Create a new stage for the runtime environment
|
||||
FROM ${base_image}
|
||||
|
||||
ENV LANG en_US.utf8
|
||||
ENV LANGUAGE=en_US
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
# Renew the arg
|
||||
ARG cmake_build_type
|
||||
LABEL BUILD_TYPE=${cmake_build_type}
|
||||
|
||||
ARG bombsquad_build=N/A
|
||||
LABEL BOMBSQUAD_BUILD=${bombsquad_build}
|
||||
|
||||
ARG bombsquad_version=N/A
|
||||
LABEL BOMBSQUAD_VERSION=${bombsquad_version}
|
||||
|
||||
# Install runtime dependencies
|
||||
RUN apt-get update -y && \
|
||||
apt-get install -y \
|
||||
python3.12-venv \
|
||||
python3-pip \
|
||||
libsdl2-dev \
|
||||
libvorbisfile3 \
|
||||
freeglut3-dev \
|
||||
libopenal1 \
|
||||
curl \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Copy the compiled application from the builder stage
|
||||
COPY --from=builder /home/ubuntu/ballistica_cmake_server/*/staged \
|
||||
/home/ubuntu/ballistica
|
||||
# ballisticakit_headless in staged is a symlink
|
||||
COPY --from=builder /home/ubuntu/ballistica_cmake_server/*/ballisticakit_headless \
|
||||
/home/ubuntu/ballistica/dist
|
||||
|
||||
WORKDIR /home/ubuntu/ballistica
|
||||
|
||||
# Expose the necessary port
|
||||
EXPOSE 43210/udp
|
||||
EXPOSE 43210/tcp
|
||||
|
||||
# Set the default command to run the application
|
||||
CMD [ "./ballisticakit_server" ]
|
||||
@ -169,6 +169,7 @@ ctx.no_filter_dirs = {
|
||||
ctx.filter_file_names = {
|
||||
'Makefile',
|
||||
'.gitignore',
|
||||
'.dockerignore',
|
||||
'.gitattributes',
|
||||
'README',
|
||||
'README.md',
|
||||
|
||||
@ -644,3 +644,55 @@ def cmake_prep_dir(dirname: str, verbose: bool = False) -> None:
|
||||
else:
|
||||
if verbose:
|
||||
print(f'{Clr.BLD}{title}:{Clr.RST} Keeping existing build dir.')
|
||||
|
||||
|
||||
def _docker_build(
|
||||
image_name: str,
|
||||
dockerfile_dir: str,
|
||||
bombsquad_version: str | None = None,
|
||||
bombsquad_build: str | int | None = None,
|
||||
cmake_build_type: str | None = None,
|
||||
) -> None:
|
||||
|
||||
build_cmd = [
|
||||
'docker',
|
||||
'image',
|
||||
'build',
|
||||
'-t',
|
||||
image_name,
|
||||
dockerfile_dir,
|
||||
]
|
||||
if bombsquad_version is not None:
|
||||
build_cmd = build_cmd + [
|
||||
'--build-arg',
|
||||
f'bombsquad_version={bombsquad_version}',
|
||||
]
|
||||
if bombsquad_build is not None:
|
||||
build_cmd = build_cmd + [
|
||||
'--build-arg',
|
||||
f'bombsquad_build={str(bombsquad_build)}',
|
||||
]
|
||||
if cmake_build_type is not None:
|
||||
build_cmd = build_cmd + [
|
||||
'--build-arg',
|
||||
f'cmake_build_type={cmake_build_type}',
|
||||
]
|
||||
subprocess.run(build_cmd, check=True)
|
||||
|
||||
|
||||
def docker_build() -> None:
|
||||
"""Build docker image."""
|
||||
import shutil
|
||||
|
||||
# todo: add option to toggle between prefab and cmake
|
||||
shutil.copy('config/docker/Dockerfile', '.')
|
||||
from batools import version
|
||||
|
||||
version_num, build_num = version.get_current_version()
|
||||
_docker_build(
|
||||
'bombsquad_server',
|
||||
'.',
|
||||
version_num,
|
||||
build_num,
|
||||
)
|
||||
os.remove('Dockerfile')
|
||||
|
||||
@ -104,6 +104,7 @@ from batools.pcommands import (
|
||||
ensure_prefab_platform,
|
||||
prefab_run_var,
|
||||
prefab_binary_path,
|
||||
build_docker,
|
||||
make_prefab,
|
||||
lazybuild,
|
||||
efro_gradle,
|
||||
|
||||
@ -667,6 +667,13 @@ def prefab_binary_path() -> None:
|
||||
)
|
||||
|
||||
|
||||
def build_docker() -> None:
|
||||
"""Build the docker image with bombsquad cmake server."""
|
||||
import batools.build
|
||||
|
||||
batools.build.docker_build()
|
||||
|
||||
|
||||
def make_prefab() -> None:
|
||||
"""Run prefab builds for the current platform."""
|
||||
import subprocess
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user