Skip to content

Commit 0560c84

Browse files
authored
Merge pull request #4 from jvm123/feature/docker
Add Dockerfile and Makefile, to allow for simple containerized execution
2 parents ebb2950 + e75b192 commit 0560c84

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

Dockerfile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Use an official Python image as the base
2+
FROM python:3.12-slim
3+
4+
# Set the working directory inside the container
5+
WORKDIR /app
6+
7+
# Install system dependencies
8+
RUN apt-get update && apt-get install -y --no-install-recommends \
9+
build-essential \
10+
&& rm -rf /var/lib/apt/lists/*
11+
12+
# Copy the project files into the container
13+
COPY . /app
14+
15+
# Install Python dependencies
16+
RUN pip install --root-user-action=ignore -e .
17+
18+
# Expose the project directory as a volume
19+
VOLUME ["/app"]
20+
21+
# Set the entry point to the openevolve-run.py script
22+
ENTRYPOINT ["python", "/app/openevolve-run.py"]

Makefile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Variables
2+
PROJECT_DIR := $(shell pwd)
3+
DOCKER_IMAGE := openevolve
4+
VENV_DIR := $(PROJECT_DIR)/env
5+
PYTHON := $(VENV_DIR)/bin/python
6+
PIP := $(VENV_DIR)/bin/pip
7+
8+
# Default target
9+
.PHONY: all
10+
all: install test
11+
12+
# Create and activate the virtual environment
13+
.PHONY: venv
14+
venv:
15+
python3 -m venv $(VENV_DIR)
16+
17+
# Install Python dependencies in the virtual environment
18+
.PHONY: install
19+
install: venv
20+
$(PIP) install -e .
21+
22+
# Run Black code formatting
23+
.PHONY: lint
24+
lint: venv
25+
$(PYTHON) -m black openevolve examples tests
26+
27+
# Run tests using the virtual environment
28+
.PHONY: test
29+
test: venv
30+
$(PYTHON) -m unittest discover -s tests -p "test_*.py"
31+
32+
# Build the Docker image
33+
.PHONY: docker-build
34+
docker-build:
35+
docker build -t $(DOCKER_IMAGE) .
36+
37+
# Run the Docker container with the example
38+
.PHONY: docker-run
39+
docker-run:
40+
docker run --rm -v $(PROJECT_DIR):/app $(DOCKER_IMAGE) examples/function_minimization/initial_program.py examples/function_minimization/evaluator.py --config examples/function_minimization/config.yaml --iterations 1000

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ OpenEvolve follows an evolutionary approach with the following components:
2727

2828
### Installation
2929

30+
To install natively, use:
3031
```bash
3132
git clone https://github.com/codelion/openevolve.git
3233
cd openevolve
@@ -60,6 +61,14 @@ OpenEvolve can also be run from the command line:
6061
python openevolve-run.py path/to/initial_program.py path/to/evaluator.py --config path/to/config.yaml --iterations 1000
6162
```
6263

64+
### Docker
65+
66+
You can also install and execute via Docker:
67+
```bash
68+
docker build -t openevolve .
69+
docker run --rm -v .:/app openevolve examples/function_minimization/initial_program.py examples/function_minimization/evaluator.py --config examples/function_minimization/config.yaml --iterations 1000
70+
```
71+
6372
## Configuration
6473

6574
OpenEvolve is highly configurable. You can specify configuration options in a YAML file:

0 commit comments

Comments
 (0)