From cb34ae11ebfc6adeac70dc463fd69de4c918fd3c Mon Sep 17 00:00:00 2001 From: Nikita Tokarchuk Date: Sun, 5 Jan 2020 18:05:27 +0100 Subject: [PATCH] task1 deployment --- deploy/docker-compose.yml | 20 +++++++++++++++++ deploy/task1/Dockerfile.task1 | 27 ++++++++++++++++++++++ deploy/task1/default.conf | 40 +++++++++++++++++++++++++++++++++ deploy/task1/docker-compose.yml | 23 +++++++++++++++++++ task1/js/main.js | 2 +- 5 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 deploy/docker-compose.yml create mode 100644 deploy/task1/Dockerfile.task1 create mode 100644 deploy/task1/default.conf create mode 100644 deploy/task1/docker-compose.yml diff --git a/deploy/docker-compose.yml b/deploy/docker-compose.yml new file mode 100644 index 0000000..2dd2cdc --- /dev/null +++ b/deploy/docker-compose.yml @@ -0,0 +1,20 @@ +version: "3.7" + +services: + redis: + image: redis + # volumes: + # - "./default.conf:/etc/nginx/conf.d/default.conf" + # - "./html:/usr/share/nginx/html" + restart: unless-stopped + networks: + - net + +networks: + net: + driver: bridge + name: tasks-net + ipam: + driver: default + config: + - subnet: 10.103.0.1/16 \ No newline at end of file diff --git a/deploy/task1/Dockerfile.task1 b/deploy/task1/Dockerfile.task1 new file mode 100644 index 0000000..26d9a06 --- /dev/null +++ b/deploy/task1/Dockerfile.task1 @@ -0,0 +1,27 @@ +FROM alpine as builder + +ENV GOPATH /root/go +ENV PATH ${GOPATH}/bin:${PATH} + +RUN mkdir -p /app +WORKDIR /app + +RUN apk add --no-cache go git curl + +COPY . . +RUN go build -o task1 github.com/mainnika/a-quest/task1-backend + +FROM alpine + +ENV GOPATH /root/go +ENV PATH ${GOPATH}/bin:${PATH} + +RUN mkdir -p /app +WORKDIR /app + +COPY --from=builder task1 . +COPY --from=builder task1-backend/config . + +EXPOSE 8081 + +CMD ["/app/task1"] \ No newline at end of file diff --git a/deploy/task1/default.conf b/deploy/task1/default.conf new file mode 100644 index 0000000..d47dd12 --- /dev/null +++ b/deploy/task1/default.conf @@ -0,0 +1,40 @@ +upstream backend1 { + server backend1:8081; +} + +server { + listen 80; + server_name _; + + location / { + + if ($request_method = 'OPTIONS') { + add_header 'Access-Control-Allow-Origin' '*'; + add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS'; + add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range'; + 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 = 'GET') { + add_header 'Access-Control-Allow-Origin' '*'; + add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS'; + 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'; + } + + root /usr/share/nginx/html; + index index.html index.htm; + } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } + + location = /answer { + proxy_pass http://backend1; + } +} \ No newline at end of file diff --git a/deploy/task1/docker-compose.yml b/deploy/task1/docker-compose.yml new file mode 100644 index 0000000..e42d276 --- /dev/null +++ b/deploy/task1/docker-compose.yml @@ -0,0 +1,23 @@ +version: '3' +services: + static: + image: nginx + volumes: + - "./default.conf:/etc/nginx/conf.d/default.conf" + - "../../build/task1:/usr/share/nginx/html" + restart: unless-stopped + networks: + net: + ipv4_address: 10.103.204.1 + backend1: + build: + dockerfile: ./Dockerfile.task1 + context: ../../task1-backend + restart: unless-stopped + networks: + net: {} + +networks: + net: + external: + name: tasks-net \ No newline at end of file diff --git a/task1/js/main.js b/task1/js/main.js index 24f7f49..0cb24b3 100755 --- a/task1/js/main.js +++ b/task1/js/main.js @@ -62,7 +62,7 @@ import '../css/util.css'; var rocking = setInterval((txt.text("Ρ…ΠΌ πŸš€"), function () { txt.text(txt.text() + "πŸš€") }), 50); - fetch('//127.0.0.1:8081/answer/check', { + fetch('/answer/check', { method: 'POST', body: JSON.stringify({ answer: answer.val().trim(), name: name.val().trim() }), })