diff --git a/deploy/task2/default.conf b/deploy/task2/default.conf new file mode 100644 index 0000000..926c161 --- /dev/null +++ b/deploy/task2/default.conf @@ -0,0 +1,40 @@ +upstream backend2 { + server backend2: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://backend2; + } +} \ No newline at end of file diff --git a/deploy/task2/docker-compose.yml b/deploy/task2/docker-compose.yml new file mode 100644 index 0000000..735c7f3 --- /dev/null +++ b/deploy/task2/docker-compose.yml @@ -0,0 +1,23 @@ +version: '3' +services: + static: + image: nginx + volumes: + - "./default.conf:/etc/nginx/conf.d/default.conf" + - "../../build/task2:/usr/share/nginx/html" + restart: unless-stopped + networks: + net: + ipv4_address: 10.103.204.2 + backend2: + build: + dockerfile: ./task2-backend/Dockerfile + context: ../.. + restart: unless-stopped + networks: + net: {} + +networks: + net: + external: + name: tasks-net \ No newline at end of file diff --git a/task2-backend/Dockerfile b/task2-backend/Dockerfile new file mode 100644 index 0000000..c038795 --- /dev/null +++ b/task2-backend/Dockerfile @@ -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 gcc g++ make + +COPY . . +RUN go build -o task2 github.com/mainnika/a-quest/task2-backend + +FROM alpine + +ENV GOPATH /root/go +ENV PATH ${GOPATH}/bin:${PATH} + +RUN mkdir -p /app +WORKDIR /app + +COPY --from=builder /app/task2 . +COPY --from=builder /app/task2-backend/config config + +EXPOSE 8081 + +CMD ["/app/task2"] \ No newline at end of file