diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..0e2bfed2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,35 @@ +# To run: +# docker build -t redoc . +# docker run -it --rm -p 80:80 -e SPEC_URL='http://localhost:8000/swagger.yaml' redoc +# Ensure http://localhost:8000/swagger.yaml is served with cors. A good solution is: +# npm i -g http-server +# http-server -p 8000 --cors + +FROM node:alpine + +RUN apk update && apk add --no-cache git + +# generate bundle +WORKDIR /build +COPY . /build +RUN yarn install --frozen-lockfile --ignore-optional --ignore-scripts +RUN npm run bundle:standalone + +FROM nginx:alpine + +ENV PAGE_TITLE="ReDoc" +ENV PAGE_FAVICON="favicon.png" +ENV SPEC_URL="http://petstore.swagger.io/v2/swagger.json" +ENV PORT=80 +ENV REDOC_OPTIONS= + +# copy files to the nginx folder +COPY --from=0 build/bundles /usr/share/nginx/html +COPY config/docker/index.tpl.html /usr/share/nginx/html/index.html +COPY demo/favicon.png /usr/share/nginx/html/ +COPY config/docker/nginx.conf /etc/nginx/ +COPY config/docker/docker-run.sh /usr/local/bin + +EXPOSE 80 + +CMD ["sh", "/usr/local/bin/docker-run.sh"] diff --git a/config/docker/README.md b/config/docker/README.md new file mode 100644 index 00000000..c0c23eda --- /dev/null +++ b/config/docker/README.md @@ -0,0 +1,26 @@ +# Redoc docker image + +## Build + + docker build -t redoc . + +## Usage + +Serve remote spec by URL: + + docker run -it --rm -p 80:80 \ + -e SPEC_URL='http://localhost:8000/swagger.yaml' redoc + +Serve local file: + + docker run -it --rm -p 80:80 \ + -v $(PWD)/demo/swagger.yaml:/usr/share/nginx/html/swagger.yaml \ + -e SPEC_URL=swagger.yaml redoc + +## Runtime configuration options + +- `PAGE_TITLE` (default `"ReDoc"`) - page title +- `PAGE_FAVICON` (default `"favicon.png"`) - URL to page favicon +- `SPEC_URL` (default `"http://petstore.swagger.io/v2/swagger.json"`) - URL to spec +- `PORT` (default `80`) - nginx port +- `REDOC_OPTIONS` - [`` tag attributes](https://github.com/Rebilly/ReDoc#redoc-tag-attributes) \ No newline at end of file diff --git a/config/docker/docker-run.sh b/config/docker/docker-run.sh new file mode 100644 index 00000000..47339b01 --- /dev/null +++ b/config/docker/docker-run.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +set -e + +sed -i -e "s|%PAGE_TITLE%|$PAGE_TITLE|g" /usr/share/nginx/html/index.html +sed -i -e "s|%PAGE_FAVICON%|$PAGE_FAVICON|g" /usr/share/nginx/html/index.html +sed -i -e "s|%SPEC_URL%|$SPEC_URL|g" /usr/share/nginx/html/index.html +sed -i -e "s|%REDOC_OPTIONS%|${REDOC_OPTIONS}|g" /usr/share/nginx/html/index.html +sed -i -e "s|80|${PORT}|g" /etc/nginx/nginx.conf + +exec nginx -g 'daemon off;' diff --git a/config/docker/index.tpl.html b/config/docker/index.tpl.html new file mode 100644 index 00000000..27a0595c --- /dev/null +++ b/config/docker/index.tpl.html @@ -0,0 +1,26 @@ + + + + + + %PAGE_TITLE% + + + + + + + + + + + \ No newline at end of file diff --git a/config/docker/nginx.conf b/config/docker/nginx.conf new file mode 100644 index 00000000..bb79f9ce --- /dev/null +++ b/config/docker/nginx.conf @@ -0,0 +1,50 @@ +worker_processes 1; + +events { + worker_connections 1024; +} + +http { + include mime.types; + default_type application/octet-stream; + + sendfile on; + + keepalive_timeout 65; + + server { + listen 80; + server_name localhost; + index index.html index.htm; + + location / { + alias /usr/share/nginx/html/; + + if ($request_method = 'OPTIONS') { + add_header 'Access-Control-Allow-Origin' '*'; + add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; + # + # Custom headers and headers various browsers *should* be OK with but aren't + # + add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; + # + # Tell client that this pre-flight info is valid for 20 days + # + add_header 'Access-Control-Max-Age' 1728000; + add_header 'Content-Type' 'text/plain charset=UTF-8'; + add_header 'Content-Length' 0; + return 204; + } + if ($request_method = 'POST') { + add_header 'Access-Control-Allow-Origin' '*'; + add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; + add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; + } + if ($request_method = 'GET') { + add_header 'Access-Control-Allow-Origin' '*'; + add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; + add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; + } + } + } +} diff --git a/demo/favicon.png b/demo/favicon.png new file mode 100644 index 00000000..6f4c7acf Binary files /dev/null and b/demo/favicon.png differ diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index b1fe9826..00000000 --- a/docker-compose.yml +++ /dev/null @@ -1,8 +0,0 @@ -dev: - image: node:7-alpine - command: sh -c "npm install; npm start -- --host=0.0.0.0" - ports: - - "9000:9000" - volumes: - - "./:/code" - working_dir: /code