Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overriding SWAGGER_JSON and URL does not work for Docker distribution #5213

Closed
sgwood63 opened this issue Mar 3, 2019 · 11 comments
Closed

Comments

@sgwood63
Copy link

sgwood63 commented Mar 3, 2019

Context

  • OS: Alpine (Docker)
  • Browser: any
  • Method of installation: Docker
  • Swagger-UI version: 3.20.X and 3.21.X at least
  • Swagger/OpenAPI version: any

SWAGGER_JSON environment variable ignored by Docker deployment

The Docker build of swaggerapi/swagger-ui does not work when overriding the SWAGGER_JSON with a mounted file as documented in https://github.com/swagger-api/swagger-ui/blob/master/docs/usage/installation.md.

run.sh updates the nginx index.html if a mounted file $SWAGGER_JSON exists.

if [[ -f $SWAGGER_JSON ]]; then
  cp -s $SWAGGER_JSON $NGINX_ROOT
  REL_PATH="./$(basename $SWAGGER_JSON)"
  sed -i "s|https://petstore.swagger.io/v2/swagger.json|$REL_PATH|g" $INDEX_FILE
  sed -i "s|http://example.com/api|$REL_PATH|g" $INDEX_FILE
fi

Problem is that the base image used by swaggerapi/swagger-ui - FROM nginx:1.15-alpine - has a index.html.gz file which takes precedence over the index.html, so the updated index.html is ignored.

To reproduce:

Have your swagger.json in /bar

docker pull swaggerapi/swagger-ui
docker run -p 80:8080 -e SWAGGER_JSON=/foo/swagger.json -v /bar:/foo swaggerapi/swagger-ui

Access swagger-ui @ http:///

Will see petstore, not your swagger.json.

URL environment variable ignored by Docker deployment

To reproduce:

Have your swagger.json in http:///swagger.json

docker pull swaggerapi/swagger-ui
docker run -p 80:8080 -e URL="http:///swagger.json" swaggerapi/swagger-ui

Access swagger-ui @ http:///

Will see petstore, not http:///swagger.json.

@Aya-Yang
Copy link

Aya-Yang commented Mar 4, 2019

I have met with the same problem...

@mercuriete
Copy link

same problem

@ChristianUlbrich
Copy link

I think the problem is #5199 because it gzip's the nginx-bundled index.html into index.html.gz on image build time which in turn, as @sgwood63 pointed out has precedence over the generated index.html on runtime.

Basically the idea of "optimizing" html file on build does not make sense if there are some generated html files on runtime as well.

@shockey
Copy link
Contributor

shockey commented Mar 5, 2019

Regression! 😱

We'll ship a fix for this ASAP, probably later today.

@ChristianUlbrich
Copy link

The gzipping should simply happen in the shell init script on runtime. I'd PR' it myself; but I won't be able to do so before the weekend...

@shockey
Copy link
Contributor

shockey commented Mar 6, 2019

Fixed! We've updated our swaggerapi/swagger-ui:latest and swaggerapi/swagger-ui:v3.21.0 images on Docker Hub to include the patch from #5219.

I'm also going to build out a small integration test suite that pulls down a real Docker image and checks it for env var configuration effectiveness, so that we automatically catch this in our releases going forward.

Apologies for the disruption!

@anuras
Copy link

anuras commented Mar 8, 2019

Is it actually fixed? I seem to observe the same behaviour as described in the first post with setting SWAGGER_JSON, (running on Windows, though).

@shockey
Copy link
Contributor

shockey commented Apr 9, 2019

@anuras, should be - can you make sure you're pulling a fresh image from Docker Hub? We overwrote existing tags to fix this, so you might have an old cached version locally.

@imcaizheng
Copy link

@shockey
Does it relevant to #3348?

@xshrim
Copy link

xshrim commented Jul 10, 2019

you should use API_URL, not SWAGGER_JSON.
example:
docker run -it -e API_URL=http://192.168.43.103:9090/swagger.json -p 8081:8080 swaggerapi/swagger-ui
192.168.43.103 is host ip.

@sitetester
Copy link

I have a swagger.json on my desktop, so running this command worked:

docker run -p 9000:8080 -e SWAGGER_JSON=/mnt/swagger.json -v ~/Desktop:/mnt swaggerapi/swagger-ui

localhost:9000 is loading correct file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants