From 7a16f374c44a2f498be8094464a569153a32e0f0 Mon Sep 17 00:00:00 2001 From: Robert Lech Date: Mon, 22 Dec 2025 20:49:08 -0500 Subject: [PATCH 1/4] feat: adds building with docker --- .dockerignore | 3 +++ CMakeLists.txt | 1 + Dockerfile | 32 ++++++++++++++++++++++++++++++++ README.md | 16 +++++++++++++++- docker-compose.yaml | 12 ++++++++++++ 5 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yaml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..0056fb5 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +build/ +.git +.vscode diff --git a/CMakeLists.txt b/CMakeLists.txt index 8dfd1d1..0254f10 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,6 +37,7 @@ include(FetchContent) FetchContent_Declare( googletest URL https://github.com/google/googletest/archive/refs/tags/v1.17.0.zip + DOWNLOAD_EXTRACT_TIMESTAMP TRUE ) FetchContent_MakeAvailable(googletest) diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..948c787 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,32 @@ +FROM ubuntu:24.04 + +# Avoid prompts from apt +ENV DEBIAN_FRONTEND=noninteractive + +# Install build dependencies and game libraries +# Matches dependencies in scripts/install_dependencies.sh +RUN apt-get update && apt-get install -y \ + build-essential \ + cmake \ + mesa-common-dev \ + libglu1-mesa-dev \ + libgl1-mesa-dev \ + freeglut3-dev \ + libglew-dev \ + libdevil-dev \ + git \ + && rm -rf /var/lib/apt/lists/* + +# Set working directory +WORKDIR /app + +# Copy project files +COPY . . + +# Build the project +RUN mkdir -p build && cd build && \ + cmake .. && \ + make + +# Set the entrypoint to the built executable +CMD ["./build/main"] diff --git a/README.md b/README.md index 9fb51fe..d64eecc 100644 --- a/README.md +++ b/README.md @@ -30,11 +30,25 @@ With the above done, you should be ready to set up the needed environment. git clone https://github.com/robert-7/Go-Board-Game.git && cd Go-Board-Game ``` -## Building and Running +## Building and Running Locally To build and run the binary, simply run `make && ./main`. To clean up, run `make clean`. +## Building and Running with Docker + +You can also run the game in a Docker container without installing dependencies on your host machine. + +### Prerequisites + +- Docker +- Docker Compose + +### Instructions + +1. **Allow X11 connections** (Linux): Since the game runs in a container but displays on your host screen, you need to allow the container to connect to your X server. Do so with: `xhost +local:docker``` +1. **Build and Run**: Do so with `docker compose up --build`. The game window should appear on your screen. + ## Linting The repository uses the same commands locally and in CI. After installing the packages above, run: diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..c88ed8c --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,12 @@ +services: + go-game: + build: . + container_name: go-board-game + # Pass the DISPLAY environment variable to the container + environment: + - DISPLAY=${DISPLAY} + # Mount the X11 socket to allow the container to communicate with the X server + volumes: + - /tmp/.X11-unix:/tmp/.X11-unix + # Use host networking to simplify X11 communication + network_mode: host From 3bd1754c97245eb048a7ef99ef0ffd48970bc385 Mon Sep 17 00:00:00 2001 From: Robert Lech Date: Mon, 22 Dec 2025 21:10:49 -0500 Subject: [PATCH 2/4] refactor: Dockerfile uses install_dependencies.sh --- Dockerfile | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 948c787..c764d4b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,20 +3,18 @@ FROM ubuntu:24.04 # Avoid prompts from apt ENV DEBIAN_FRONTEND=noninteractive -# Install build dependencies and game libraries -# Matches dependencies in scripts/install_dependencies.sh +# Install base build tools RUN apt-get update && apt-get install -y \ build-essential \ - cmake \ - mesa-common-dev \ - libglu1-mesa-dev \ - libgl1-mesa-dev \ - freeglut3-dev \ - libglew-dev \ - libdevil-dev \ - git \ && rm -rf /var/lib/apt/lists/* +# Copy dependency script +COPY scripts/install_dependencies.sh /tmp/install_dependencies.sh + +# Run dependency script +RUN /tmp/install_dependencies.sh && \ + rm -rf /var/lib/apt/lists/* /tmp/install_dependencies.sh + # Set working directory WORKDIR /app From ead6fa76dd340bb20983efc4611699dd729565a7 Mon Sep 17 00:00:00 2001 From: Robert Lech Date: Mon, 22 Dec 2025 21:15:31 -0500 Subject: [PATCH 3/4] feat: only run tests on code change --- .pre-commit-config.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index acc584d..e3f9d98 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -25,3 +25,5 @@ repos: entry: scripts/run_lint.sh language: script pass_filenames: false + # Only run when C++ source, headers, CMake config, or lint config changes + files: \.(cpp|h|hpp|c|cc|cxx)$|CMakeLists\.txt$|\.clang-format$ From 9f4ed42193094a230746ebce9e0e76561f1ff23f Mon Sep 17 00:00:00 2001 From: Robert Lech Date: Mon, 22 Dec 2025 21:28:42 -0500 Subject: [PATCH 4/4] feat: adds Dockerfile optimizations --- Dockerfile | 7 +------ scripts/install_dependencies.sh | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index c764d4b..3fccaee 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,8 @@ -FROM ubuntu:24.04 +FROM ubuntu:25.10 # Avoid prompts from apt ENV DEBIAN_FRONTEND=noninteractive -# Install base build tools -RUN apt-get update && apt-get install -y \ - build-essential \ - && rm -rf /var/lib/apt/lists/* - # Copy dependency script COPY scripts/install_dependencies.sh /tmp/install_dependencies.sh diff --git a/scripts/install_dependencies.sh b/scripts/install_dependencies.sh index acbb869..df36c70 100755 --- a/scripts/install_dependencies.sh +++ b/scripts/install_dependencies.sh @@ -11,12 +11,12 @@ run_with_sudo() { run_with_sudo apt-get update run_with_sudo apt-get install -y \ + build-essential \ mesa-common-dev \ libglu1-mesa-dev \ libgl1-mesa-dev \ freeglut3-dev \ libglew-dev \ - libdevil1c2 \ libdevil-dev \ cmake \ clang-tidy \