Parcourir la source

feat: multistage build with nginx container serving frontend

Fela Maslen il y a 5 ans
Parent
commit
b60642b949
3 fichiers modifiés avec 41 ajouts et 0 suppressions
  1. 4 0
      gmus-web/.dockerignore
  2. 17 0
      gmus-web/Dockerfile
  3. 20 0
      gmus-web/nginx.conf

+ 4 - 0
gmus-web/.dockerignore

@@ -0,0 +1,4 @@
+Dockerfile
+.dockerignore
+node_modules
+build

+ 17 - 0
gmus-web/Dockerfile

@@ -0,0 +1,17 @@
+FROM node:14-alpine AS builder
+
+WORKDIR /app
+COPY package.json yarn.lock ./
+RUN yarn
+COPY src ./src
+COPY public ./public
+COPY tsconfig.json .
+
+ENV REACT_APP_API_URL=http://localhost:3002
+RUN yarn build && rm -rf node_modules
+
+FROM nginx:alpine
+
+WORKDIR /app
+COPY nginx.conf /etc/nginx/nginx.conf
+COPY --from=0 /app/build .

+ 20 - 0
gmus-web/nginx.conf

@@ -0,0 +1,20 @@
+events {
+  worker_connections 768;
+}
+
+http {
+  server {
+    listen 80;
+
+    root /app;
+
+    location / {
+      try_files $uri $uri/ =404;
+    }
+
+    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
+      expires 1y;
+      log_not_found off;
+    }
+  }
+}