Skip to content

Commit

Permalink
Add DockerFile (#6)
Browse files Browse the repository at this point in the history
It is practical to include a Docker file so that a prepared solver can be deployed easily.
  • Loading branch information
bh2smith authored Apr 30, 2022
1 parent 5c6bff1 commit 8ebe252
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 4 deletions.
10 changes: 10 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.github
tests
data
.env.sample
.gitignore
.pylintrc
Dockerfile
LICENSE
mypy.ini
README.md
36 changes: 36 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: deploy

on:
push:
branches: [main]
tags: [v*]

jobs:
deploy:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- uses: actions/checkout@v2

- uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- id: meta
uses: docker/metadata-action@v3
with:
images: ghcr.io/${{ github.repository }}
labels: |
org.opencontainers.image.licenses=MIT OR Apache-2.0
- uses: docker/build-push-action@v2
with:
context: .
file: Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM python:alpine
RUN apk add --update gcc libc-dev linux-headers

WORKDIR /app

# Only copies requirements.txt and src directory (see .dockerignore)
COPY . .
RUN pip install -r requirements.txt

ENTRYPOINT [ "python3", "-m" , "src._server"]
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,16 @@ pip install -r requirements.txt
python -m src._server
```

This can also be run via docker with

```sh
docker run -p 8000:8000 gchr.io/cowprotocol/solver-template-py
```

# Feed an Auction Instance to the Solver

```shell
curl -X POST "http://127.0.0.1:8000/solve/" \
curl -X POST "http://127.0.0.1:8000/solve" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
--data "@data/small_example.json"
Expand Down Expand Up @@ -65,7 +71,7 @@ docker run -it --rm --add-host host.docker.internal:host-gateway ghcr.io/cowprot
Clone the services project with

```shell
git clone https://github.com/cowprotocol/services.git
git clone https://github.com/cowprotocol/services.git
```

```shell
Expand Down
4 changes: 2 additions & 2 deletions src/_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
class ServerSettings(BaseSettings):
"""Basic Server Settings"""

host: str = "127.0.0.1"
host: str = "0.0.0.0"
port: int = 8000


Expand All @@ -53,7 +53,7 @@ def health() -> bool:
return True


@app.post("/solve/", response_model=SettledBatchAuctionModel)
@app.post("/solve", response_model=SettledBatchAuctionModel)
async def solve(problem: BatchAuctionModel, request: Request): # type: ignore
"""API POST solve endpoint handler"""
logging.debug(f"Received solve request {await request.json()}")
Expand Down

0 comments on commit 8ebe252

Please sign in to comment.