From d36a8edd07f68490cd4507249a8f5b60023b903b Mon Sep 17 00:00:00 2001 From: Loup-Garou911XD Date: Sat, 18 May 2024 20:17:11 +0530 Subject: [PATCH] done and dusted --- .dockerignore | 4 +- CHANGELOG.md | 1 + CONTRIBUTORS.md | 3 +- do_stuff | 9 ----- Dockerfile => src/assets/docker/Dockerfile | 44 ++++++++++++++-------- tools/batools/build.py | 32 +++++++++------- tools/batools/pcommands.py | 2 - 7 files changed, 54 insertions(+), 41 deletions(-) delete mode 100755 do_stuff rename Dockerfile => src/assets/docker/Dockerfile (59%) diff --git a/.dockerignore b/.dockerignore index 1d1fe94d..249ace41 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1,3 @@ -Dockerfile \ No newline at end of file +.venv/ +tools/pcommand +build/cmake/ \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 03afd83a..4a113974 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index dd21a689..30865a77 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -63,4 +63,5 @@ - Added support for joining using ipv6 address ### Loup Garou -- Added sphinx documentation generation \ No newline at end of file +- Added sphinx documentation generation +- Added docker build \ No newline at end of file diff --git a/do_stuff b/do_stuff deleted file mode 100755 index 1b56c414..00000000 --- a/do_stuff +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -pwd -echo -ls -echo -rm tools/pcommand -rm -rf .venv -make env -make cmake-server-build \ No newline at end of file diff --git a/Dockerfile b/src/assets/docker/Dockerfile similarity index 59% rename from Dockerfile rename to src/assets/docker/Dockerfile index ca5d3d9f..d2804a0d 100644 --- a/Dockerfile +++ b/src/assets/docker/Dockerfile @@ -1,20 +1,24 @@ +# 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 -ENV LANG en_US.utf8 -ENV LANGUAGE=en_US - # 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 DEBIAN_FRONTEND=noninteractive \ - apt-get update -y && \ +RUN apt-get update -y && \ apt-get install -y \ python3.12-dev \ python3.12-venv \ @@ -36,26 +40,30 @@ COPY ./ /home/ubuntu/ballistica WORKDIR /home/ubuntu/ballistica # Compile the application -RUN rm -rf .venv tools/pcommand 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} -# Renew the arg -ARG cmake_build_type - ENV LANG en_US.utf8 ENV LANGUAGE=en_US +ENV DEBIAN_FRONTEND=noninteractive -WORKDIR /home/ubuntu/ballistica +# 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 DEBIAN_FRONTEND=noninteractive \ - apt-get update -y && \ +RUN apt-get update -y && \ apt-get install -y \ python3.12-venv \ python3-pip \ @@ -63,11 +71,17 @@ RUN DEBIAN_FRONTEND=noninteractive \ libvorbisfile3 \ freeglut3-dev \ libopenal1 \ - curl + curl \ + && rm -rf /var/lib/apt/lists/* # Copy the compiled application from the builder stage -COPY --from=builder /home/ubuntu/ballistica/build/cmake/server-debug/staged/ /home/ubuntu/ballistica -COPY --from=builder /home/ubuntu/ballistica/build/cmake/server-debug/ballisticakit_headless /home/ubuntu/ballistica/dist +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 diff --git a/tools/batools/build.py b/tools/batools/build.py index a17d273a..1cae58d3 100644 --- a/tools/batools/build.py +++ b/tools/batools/build.py @@ -645,27 +645,33 @@ def cmake_prep_dir(dirname: str, verbose: bool = False) -> None: if verbose: print(f'{Clr.BLD}{title}:{Clr.RST} Keeping existing build dir.') -def _docker_build(image_name, - dockerfile_dir, - bombsquad_version = None, - project_root = None) -> None: +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 project_root is not None: - # print(project_root) - # build_cmd = build_cmd+['--build-arg', f'PROJ_ROOT={project_root}'] - + 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) -# add option to toggle between prefab and cmake +# todo: add option to toggle between prefab and cmake def docker_build() -> None: + import shutil + shutil.copy("src/assets/docker/Dockerfile",".") + from batools import version + version_num,build_num =version.get_current_version() _docker_build('bsquad', '.', - '1.7.69', - os.getcwd(), - ) \ No newline at end of file + version_num, + build_num, + ) + os.remove("Dockerfile") \ No newline at end of file diff --git a/tools/batools/pcommands.py b/tools/batools/pcommands.py index cad1fa63..f33e1b86 100644 --- a/tools/batools/pcommands.py +++ b/tools/batools/pcommands.py @@ -667,8 +667,6 @@ def prefab_binary_path() -> None: ) def build_docker() -> None: - pass - import subprocess import batools.build batools.build.docker_build()