From f7b0071d2e0380b34686cae8a2a40f8252f76186 Mon Sep 17 00:00:00 2001 From: simon987 Date: Thu, 23 May 2019 21:19:01 -0400 Subject: [PATCH] Update dockerfile --- Dockerfile | 28 +++++++++++++++++++--------- nginx.conf | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 9 deletions(-) create mode 100644 nginx.conf diff --git a/Dockerfile b/Dockerfile index ea9861e..5f65925 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,26 @@ -# Build +# Build API FROM golang:1.11.5 as go_build WORKDIR /go/src/github.com/simon987/task_tracker/ -COPY . . +COPY .git .git +COPY api api +COPY client client +COPY config config +COPY main main +COPY storage storage RUN go get ./main/ && GOOS=linux CGO_ENABLED=0 go build -a -installsuffix cgo -o tt_api ./main/ -# Execute in alpine -FROM alpine:3.9.2 +# Build Web +FROM node:10-alpine as npm_build +COPY ./web/ ./ +RUN cd ./angular/ && npm install +RUN cd ./angular/ && ./node_modules/@angular/cli/bin/ng build --prod --optimization --output-path "/webroot" + +FROM nginx:alpine WORKDIR /root -COPY --from=go_build ["/go/src/github.com/simon987/task_tracker/tt_api",\ - "/go/src/github.com/simon987/task_tracker/schema.sql",\ - "/go/src/github.com/simon987/task_tracker/config.yml",\ - "./"] -CMD ["./tt_api"] +COPY nginx.conf schema.sql config.yml ./ +COPY --from=go_build ["/go/src/github.com/simon987/task_tracker/tt_api", "./"] +COPY --from=npm_build ["/webroot", "/webroot"] + +CMD ["sh", "-c", "nginx -c /root/nginx.conf && /root/tt_api"] diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..d28596a --- /dev/null +++ b/nginx.conf @@ -0,0 +1,45 @@ +user nginx; +worker_processes 1; + +error_log /var/log/nginx/error.log warn; +pid /var/run/nginx.pid; + + +events { + worker_connections 1024; +} + + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + + sendfile on; + + keepalive_timeout 65; + + server { + listen 80; + + index index.html; + root /webroot; + + location / { + try_files $uri $uri/ /index.html; + } + + location ~ /api(.*)$ { + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header Host $host; + proxy_pass http://127.0.0.1:3010$1?$args; + } + } +} \ No newline at end of file