diff --git a/.travis.yml b/.travis.yml index c279026ed5a..a86ba06ce05 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,8 @@ branches: - master - /^v\d+\.\d+(\.\d+)?(-\S*)?$/ before_deploy: "npm run build-core" +env: + - DOCKER_IMAGE_NAME=swaggerapi/swagger-editor deploy: provider: npm email: apiteam@swagger.io @@ -16,3 +18,14 @@ deploy: tags: true repo: swagger-api/swagger-editor node: '6.9' +after_success: + - if [ $DOCKER_HUB_USERNAME ]; then + docker login --email=$DOCKER_HUB_EMAIL --username=$DOCKER_HUB_USERNAME --password=$DOCKER_HUB_PASSWORD; + docker build -t $DOCKER_IMAGE_NAME .; + if [ ! -z "$TRAVIS_TAG" ]; then + docker tag $DOCKER_IMAGE_NAME:latest $DOCKER_IMAGE_NAME:$TRAVIS_TAG; + fi; + if [ ! -z "$TRAVIS_TAG" ] || [ "$TRAVIS_BRANCH" = "master" ]; then + docker push $DOCKER_IMAGE_NAME; + fi; + fi; diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000000..ed068a54d28 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM alpine:3.4 + +MAINTAINER fehguy + +RUN apk add --update nginx +RUN mkdir -p /run/nginx + +COPY nginx.conf /etc/nginx/ + +# copy swagger files to the `/js` folder +COPY ./index.html /usr/share/nginx/html/ +ADD ./dist/*.js /usr/share/nginx/html/dist/ +ADD ./dist/*.css /usr/share/nginx/html/dist/ +ADD ./docker-run.sh /usr/share/nginx/ + +EXPOSE 8080 + +CMD ["sh", "/usr/share/nginx/docker-run.sh"] diff --git a/docker-run.sh b/docker-run.sh new file mode 100644 index 00000000000..dee6380651b --- /dev/null +++ b/docker-run.sh @@ -0,0 +1,9 @@ +#! /bin/sh + +set -e + +INDEX_FILE=/usr/share/nginx/html/index.html + +# TODO: this is empty but we'll be adding configuration values here + +exec nginx -g 'daemon off;' \ No newline at end of file diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 00000000000..dda3d6de083 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,49 @@ +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; + + location / { + root /usr/share/nginx/html; + index index.html index.htm; + 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'; + } + } + } +}