slimtoolkit / slimtoolkit/slim

container start fail with sanic+sanic-openapi

Open
#106 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

triage
Dominant language
Go
Stars
23.4k
Forks
840
PR merge metrics
No merged PRs in 30d

Description

I have a simple sanic server, it runs ok with normal docker, but failed to launch when slimed.

$ docker build -t server .
$ docker-slim build server .
$ docker run -d server.slim

and container exit with error

Traceback (most recent call last):
  File "main.py", line 12, in <module>
    app.blueprint(swagger_blueprint)
  File "/usr/local/lib/python3.7/site-packages/sanic/app.py", line 726, in blueprint
    blueprint.register(self, options)
  File "/usr/local/lib/python3.7/site-packages/sanic/blueprints.py", line 158, in register
    uri, future.file_or_directory, *future.args, **future.kwargs
  File "/usr/local/lib/python3.7/site-packages/sanic/app.py", line 704, in static
    content_type,
  File "/usr/local/lib/python3.7/site-packages/sanic/static.py", line 146, in register
    )(_handler)
  File "/usr/local/lib/python3.7/site-packages/sanic/app.py", line 201, in response
    name=name,
  File "/usr/local/lib/python3.7/site-packages/sanic/router.py", line 147, in add
    self._add(uri, methods, handler, host, name)
  File "/usr/local/lib/python3.7/site-packages/sanic/router.py", line 303, in _add
    route = merge_route(route, methods, handler)
  File "/usr/local/lib/python3.7/site-packages/sanic/router.py", line 255, in merge_route
    uri, ",".join(list(duplicated))
sanic.router.RouteExists: Route already registered: /swagger/<file_uri:/?.+> [HEAD,GET]

code as below, include main.py, Dockerfile and requirements.txt

Dockerfile

FROM python:3.7
COPY requirements.txt /requirements.txt
RUN pip install -r requirements.txt

COPY . /app
WORKDIR /app
EXPOSE 8000
CMD python main.py

main.py

from sanic import Sanic
from sanic_openapi import swagger_blueprint
app = Sanic()
app.blueprint(swagger_blueprint)
if __name__ == "__main__":
    app.run(host="0.0.0.0", port=8000)

requirements.txt

sanic
sanic-openapi

Note that if I commented out line app.blueprint(swagger_blueprint), slim container can launch success

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure using Dockerfile, main.py, and requirements.txt with the shown docker-slim build and docker run commands. Start by comparing the normal and slimmed containers around app.blueprint(swagger_blueprint); done means the slimmed container launches successfully without removing that blueprint.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, python
Domain
devops
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.