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/.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$ 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..3fccaee --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +FROM ubuntu:25.10 + +# Avoid prompts from apt +ENV DEBIAN_FRONTEND=noninteractive + +# 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 + +# 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 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 \