diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..3ac4ab0 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,10 @@ +.github +tests +data +.env.sample +.gitignore +.pylintrc +Dockerfile +LICENSE +mypy.ini +README.md diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml new file mode 100644 index 0000000..97ecb86 --- /dev/null +++ b/.github/workflows/deploy.yaml @@ -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 }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..dea8b09 --- /dev/null +++ b/Dockerfile @@ -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"] \ No newline at end of file diff --git a/README.md b/README.md index be33bb9..881d0be 100644 --- a/README.md +++ b/README.md @@ -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" @@ -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 diff --git a/src/_server.py b/src/_server.py index e323c2a..570874b 100644 --- a/src/_server.py +++ b/src/_server.py @@ -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 @@ -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()}")