mirror of
https://github.com/Redocly/redoc.git
synced 2025-08-06 21:30:21 +03:00
add Dockerfile for deployment
This commit is contained in:
parent
3924d3c1be
commit
3cab3a27e4
26
Dockerfile
Normal file
26
Dockerfile
Normal file
|
@ -0,0 +1,26 @@
|
|||
FROM node:carbon
|
||||
|
||||
ENV API_TITLE "ReDoc"
|
||||
ENV API_URL "http://petstore.swagger.io/v2/swagger.json"
|
||||
ENV PORT 8080
|
||||
|
||||
# install nginx
|
||||
RUN apt-get update
|
||||
RUN apt-get install nginx -y
|
||||
|
||||
# generate bundle
|
||||
WORKDIR /build
|
||||
RUN npm install -g yarn --loglevel=warn
|
||||
COPY . /build
|
||||
RUN yarn install
|
||||
RUN npm run bundle
|
||||
|
||||
# copy files to the nginx folder
|
||||
RUN cp bundles/* /usr/share/nginx/html
|
||||
COPY index.tpl.html /usr/share/nginx/html/index.html
|
||||
COPY nginx.conf /etc/nginx/
|
||||
COPY docker-run.sh /usr/share/nginx/
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
CMD ["sh", "/usr/share/nginx/docker-run.sh"]
|
17
docker-run.sh
Normal file
17
docker-run.sh
Normal file
|
@ -0,0 +1,17 @@
|
|||
#! /bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
if [ -n "$API_TITLE" ]; then
|
||||
sed -i "s|%API_TITLE%|$API_TITLE|g" /usr/share/nginx/html/index.html
|
||||
fi
|
||||
|
||||
if [ -n "$API_URL" ]; then
|
||||
sed -i "s|%API_URL%|$API_URL|g" /usr/share/nginx/html/index.html
|
||||
fi
|
||||
|
||||
if [ -n "$PORT" ]; then
|
||||
sed -i "s|8080|${PORT}|g" /etc/nginx/nginx.conf
|
||||
fi
|
||||
|
||||
exec nginx -g 'daemon off;'
|
25
index.tpl.html
Normal file
25
index.tpl.html
Normal file
|
@ -0,0 +1,25 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>%API_TITLE%</title>
|
||||
<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="%API_URL%"></redoc>
|
||||
<script src="/redoc.standalone.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
50
nginx.conf
Normal file
50
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 8080;
|
||||
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';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user