diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c3b54cc..39620de 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,6 +21,10 @@ jobs: - name: Check-out repository uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - - name: Build Dev Docker Image + - name: Build Docker Image run: | make docker_build + + - name: Build Development Docker Image and Run Pre-commit + run: | + make docker_pre_commit_action diff --git a/docker/Dockerfile.dev b/docker/Dockerfile.dev new file mode 100644 index 0000000..7940c51 --- /dev/null +++ b/docker/Dockerfile.dev @@ -0,0 +1,44 @@ +ARG PYTHON_VERSION=3.11 + +FROM python:${PYTHON_VERSION} AS base +# Install uv +COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ + +ENV TEST_WORKSPACE=/app + + +# Change the working directory to the `app` directory +WORKDIR /app + +# Enable bytecode compilation +ENV UV_COMPILE_BYTECODE=1 + +# Copy from the cache instead of linking since it's a mounted volume +ENV UV_LINK_MODE=copy + + +# Install dependencies +RUN --mount=type=cache,target=/root/.cache/uv \ + --mount=type=bind,source=uv.lock,target=uv.lock \ + --mount=type=bind,source=pyproject.toml,target=pyproject.toml \ + uv sync --frozen --no-install-project + +# Copy the project into the image +COPY . /app + +COPY /src/sc2anonserverpy/grpc_server.py \ + /src/sc2anonserverpy/grpc_client.py \ + /app/ + +# Sync the project +RUN --mount=type=cache,target=/root/.cache/uv \ + uv sync --frozen + +# Place executables in the environment at the front of the path +ENV PATH="/app/.venv/bin:$PATH" + +# Reset the entrypoint, don't invoke "python" by default +ENTRYPOINT [] + + +CMD [ "sh" ] diff --git a/makefile b/makefile index 4478120..efead28 100644 --- a/makefile +++ b/makefile @@ -6,8 +6,10 @@ PYTHON_VERSION = 3.13 # Docker variables: DOCKER_DIR = ./docker DOCKER_FILE = $(DOCKER_DIR)/Dockerfile +DOCKER_FILE_DEVCONTAINER = $(DOCKER_DIR)/Dockerfile.dev DOCKER_TAG = kaszanas/sc2anonserverpy +DEVCONTAINER = kaszanas/sc2anonserverpy-devcontainer ############################ #### Using the tools ####### @@ -19,11 +21,16 @@ run_server: ## Run the server python3 grpc_server.py .PHONY: run_client -run_client: ## Run the client +run_client: ## Run the client without multiprocessing docker run -it --rm \ + -v ".\processing:/app/processing" $(DOCKER_TAG) \ - python3 grpc_client.py - + python3 grpc_client.py \ + --input_dir /app/processing/demos/input \ + --output_dir /app/processing/demos/output \ + --agents 1 \ + --chunksize 1 \ + --use_multiprocessing False ############################ #### Docker commands ####### @@ -43,6 +50,30 @@ docker_run_it: ## Run the container in interactive mode docker run -it --rm $(DOCKER_TAG) +.PHONY: docker_build_devcontainer +docker_build_devcontainer: ## Builds the devcontainer image. + @echo "Building the Dockerfile: $(DOCKER_FILE_DEVCONTAINER)" + @echo "Setting tag to: $(DEVCONTAINER)" + @echo "Using Python version: $(PYTHON_VERSION)" + docker build \ + --build-arg="PYTHON_VERSION=$(PYTHON_VERSION)" \ + -f $(DOCKER_FILE_DEVCONTAINER) . \ + --tag=$(DEVCONTAINER) + + +############################ +#### GitHub Actions ######## +############################ +.PHONY: docker_pre_commit_action +docker_pre_commit_action: ## Runs pre-commit hooks using Docker. + @echo "Running pre-commit hooks using Docker." + @make docker_build_devcontainer + @echo "Using the devcontainer image: $(DEVCONTAINER)" + docker run \ + $(DEVCONTAINER) \ + pre-commit run --all-files + + .PHONY: help help: ## Show available make targets @awk '/^[^\t ]*:.*?##/{sub(/:.*?##/, ""); printf "\033[36m%-30s\033[0m %s\n", $$1, substr($$0, index($$0,$$2))}' $(MAKEFILE_LIST)