From 69780a75f318b5374d56776e78f01fc9cb744892 Mon Sep 17 00:00:00 2001 From: Chris Hines <chris.hines@monash.edu> Date: Mon, 18 May 2020 10:53:39 +1000 Subject: [PATCH] deploy nginx snippets automatically --- .gitlab-ci.yml | 3 +++ nginx_snippets/logging.conf | 6 ++++++ nginx_snippets/tes.conf | 40 +++++++++++++++++++++++++++++++++++++ nginx_snippets/tws.conf | 12 +++++++++++ 4 files changed, 61 insertions(+) create mode 100644 nginx_snippets/logging.conf create mode 100644 nginx_snippets/tes.conf create mode 100644 nginx_snippets/tws.conf diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8c864ea..f8307b6 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -31,6 +31,7 @@ deploy_test: DOCKER_HOST: unix:///var/run/docker.sock script: - echo "deploying test" + - cp ./nginx_snippets/* /etc/nginx/snippets/ - docker login -u $DOCKERHUBUSER -p $DOCKERHUBPASSWORD docker.io - docker stop strudel2_backend || echo "Failed to stop existing container" - docker ps -a -q | xargs -I{} docker rm {} || echo "No containers to remove" @@ -50,6 +51,7 @@ deploy_dev: DOCKER_HOST: unix:///var/run/docker.sock script: - echo "deploying dev" + - cp ./nginx_snippets/* /etc/nginx/snippets/ - docker login -u $DOCKERHUBUSER -p $DOCKERHUBPASSWORD docker.io - docker stop strudel2_backend || echo "Failed to stop existing container" - docker ps -a -q | xargs -I{} docker rm {} || echo "No containers to remove" @@ -69,6 +71,7 @@ deploy_prod: DOCKER_HOST: unix:///var/run/docker.sock script: - echo "deploying prod" + - cp ./nginx_snippets/* /etc/nginx/snippets/ - docker login -u $DOCKERHUBUSER -p $DOCKERHUBPASSWORD docker.io - docker stop strudel2_backend || echo "Failed to stop existing container" - docker ps -a -q | xargs -I{} docker rm {} || echo "No containers to remove" diff --git a/nginx_snippets/logging.conf b/nginx_snippets/logging.conf new file mode 100644 index 0000000..ff35c09 --- /dev/null +++ b/nginx_snippets/logging.conf @@ -0,0 +1,6 @@ +location /logging/ { + access_log "/var/log/nginx/logging"; + error_log "/var/log/nginx/logging.err"; + add_header 'Access-Control-Allow-Origin' $http_origin; + return 204; +} diff --git a/nginx_snippets/tes.conf b/nginx_snippets/tes.conf new file mode 100644 index 0000000..f108c73 --- /dev/null +++ b/nginx_snippets/tes.conf @@ -0,0 +1,40 @@ +location /tes/ { + proxy_pass http://localhost:8080/; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection $connection_upgrade; + add_header 'Access-Control-Allow-Origin' $http_origin always; + add_header 'Access-Control-Allow-Credentials' 'true' always; + + if ($request_method = 'OPTIONS') { + add_header 'Access-Control-Allow-Origin' $http_origin always; + add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, DELETE'; + # + # Custom headers and headers various browsers *should* be OK with but aren't + # + add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range'; + add_header 'Access-Control-Allow-Credentials' 'true' always; + # + # 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' $http_origin always; + add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, DELETE'; + add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range'; + add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range'; + add_header 'Access-Control-Allow-Credentials' 'true' always; + } + if ($request_method = 'GET') { + add_header 'Access-Control-Allow-Origin' $http_origin always; + add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, DELETE'; + add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range'; + add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range'; + add_header 'Access-Control-Allow-Credentials' 'true' always; + } +} + diff --git a/nginx_snippets/tws.conf b/nginx_snippets/tws.conf new file mode 100644 index 0000000..f68f496 --- /dev/null +++ b/nginx_snippets/tws.conf @@ -0,0 +1,12 @@ +location / { + proxy_pass http://localhost:8090; + proxy_set_header Origin ''; + proxy_set_header Referer /; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection $connection_upgrade; + add_header 'Access-Control-Allow-Origin' $http_origin; + add_header 'Access-Control-Allow-Credentials' 'true'; + client_max_body_size 50M; + +} -- GitLab