cowprotocol / solver-template-py

A hollow framework for a CoW Protocol solver
MIT License
39 stars 25 forks source link

Add DockerFile #6

Closed bh2smith closed 2 years ago

bh2smith commented 2 years ago

It is practical to include a Docker file so that a prepared solver can be deployed easily. Here we add a docker file and auto deployment. This required changing the host address from 127.0.0.1 to 0.0.0.0 (i.e. the bind-address). I am no networking expert, but I vaguely understand what is happening here.

Credit goes to @poolpitako for discovering the bind-address change!

Test Plan

run the docker image (you may have to build it)

docker build . -t test-solver-image
docker run -p 8000:8000 test-solver-image

Send an order via curl

with 127.0.0.1

curl -X POST "http://127.0.0.1:8000/solve/?instance_name=SmallExample" \
  -H  "accept: application/json" \
  -H  "Content-Type: application/json" \
  --data "@data/small_example.json"

Or with 0.0.0.0

curl -X POST "http://0.0.0.0:8000/solve/?instance_name=SmallExample" \
  -H  "accept: application/json" \
  -H  "Content-Type: application/json" \
  --data "@data/small_example.json"

This also still works when running

python -m src._server

To test container to container compatibility run the following:

# Solver server image
docker run -p 8000:8000 test-solver-image
# Driver image
docker run -it --rm --env-file .env --add-host host.docker.internal:host-gateway ghcr.io/cowprotocol/services solver

Place an order on gnosis chain barn and watch the magic happen!