mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-21 16:16:33 +03:00
chore: Add Dockerfile for easier deployment (#427)
This commit is contained in:
parent
a4033747d3
commit
cddfb12806
35
Dockerfile
Normal file
35
Dockerfile
Normal file
|
@ -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"]
|
26
config/docker/README.md
Normal file
26
config/docker/README.md
Normal file
|
@ -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` - [`<redoc>` tag attributes](https://github.com/Rebilly/ReDoc#redoc-tag-attributes)
|
11
config/docker/docker-run.sh
Normal file
11
config/docker/docker-run.sh
Normal file
|
@ -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;'
|
26
config/docker/index.tpl.html
Normal file
26
config/docker/index.tpl.html
Normal file
|
@ -0,0 +1,26 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>%PAGE_TITLE%</title>
|
||||
<link rel="icon" href="%PAGE_FAVICON%">
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
redoc {
|
||||
display: block;
|
||||
}
|
||||
</style>
|
||||
<link href="https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700" rel="stylesheet">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<redoc spec-url="%SPEC_URL%" %REDOC_OPTIONS%></redoc>
|
||||
<script src="/redoc.standalone.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
50
config/docker/nginx.conf
Normal file
50
config/docker/nginx.conf
Normal file
|
@ -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';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
BIN
demo/favicon.png
Normal file
BIN
demo/favicon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.0 KiB |
|
@ -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
|
Loading…
Reference in New Issue
Block a user