Xiao commited on
Commit
4e0259c
·
1 Parent(s): 283f898

dockerfile multistage build

Browse files
.nginx/nginx.conf CHANGED
@@ -1,12 +1,16 @@
1
- server {
 
 
 
 
 
2
 
3
  listen 5000;
4
 
5
  location / {
6
  # root /usr/share/nginx/html;
7
- proxy_pass http://localhost:3000;
8
- # root /app/public;
9
- # index index.html index.htm;
10
  try_files $uri /index.html =404;
11
  }
12
 
@@ -31,3 +35,4 @@ server {
31
  root /usr/share/nginx/html;
32
  }
33
  }
 
 
1
+ events {
2
+ worker_connections 1024;
3
+ }
4
+
5
+ http {
6
+ server {
7
 
8
  listen 5000;
9
 
10
  location / {
11
  # root /usr/share/nginx/html;
12
+ root /app/public;
13
+ index index.html index.htm;
 
14
  try_files $uri /index.html =404;
15
  }
16
 
 
35
  root /usr/share/nginx/html;
36
  }
37
  }
38
+ }
nginx.conf → .nginx/nginx_2.conf RENAMED
File without changes
Dockerfile CHANGED
@@ -1,26 +1,35 @@
1
- # See https://hub.docker.com/r/nikolaik/python-nodejs
2
- # https://github.com/nikolaik/docker-python-nodejs
3
  # Default user is 'luminlab' with uid 1000, gid 1000
4
- FROM nikolaik/python-nodejs:python3.10-nodejs18
5
 
6
  # Install nginx and give permissions to 'luminlab'
7
  # See https://www.rockyourcode.com/run-docker-nginx-as-non-root-user/
8
- USER root
9
 
10
  RUN apt-get -y update && apt-get -y install nginx
11
 
 
 
 
 
 
 
 
 
 
 
12
  RUN mkdir -p /var/cache/nginx \
13
  /var/log/nginx \
14
  /var/lib/nginx
15
  RUN touch /var/run/nginx.pid
16
 
 
 
 
 
17
 
18
-
19
- # Set up a new user named "luminlab" with user ID 1000
20
- RUN useradd -m -u 1000 luminlab &&\
21
- groupadd luminlab &&\
22
- usermod -aG luminlab luminlab
23
-
24
 
25
 
26
  # # Set home to the user's home directory
@@ -29,31 +38,27 @@ RUN useradd -m -u 1000 luminlab &&\
29
 
30
  # # Set the working directory to the user's home directory
31
  # WORKDIR $HOME/app
32
- RUN chown -R luminlab:luminlab /var/cache/nginx \
33
- /var/log/nginx \
34
- /var/lib/nginx \
35
- /var/run/nginx.pid
36
 
37
  # syntax=docker/dockerfile:1.4
38
- ENV HOME=/home/luminlab \
39
- PATH=/home/luminlab/.local/bin:$PATH
40
 
41
- RUN mkdir $HOME/app
42
 
43
  # 1. For build React app
44
- FROM node:lts AS build
45
 
46
  # Set working directory
47
  WORKDIR /app
48
 
49
  #
50
- COPY --chown=luminlab:luminlab package.json /app/package.json
51
- COPY --chown=luminlab:luminlab package-lock.json /app/package-lock.json
52
 
53
  # Same as npm install
54
  RUN npm ci
55
 
56
- COPY --chown=luminlab:luminlab . .
57
 
58
  ENV CI=true
59
  ENV PORT=3000
@@ -81,28 +86,35 @@ ENV PORT=3000
81
  # COPY --chown=luminlab nginx.conf /etc/nginx/sites-available/default
82
 
83
  # COPY --chown=luminlab . .
84
- # 2. For Nginx setup
85
- FROM nginx:alpine AS prod
 
 
 
 
86
 
87
  # Copy config nginx
88
- COPY --chown=luminlab:luminlab --from=build /app/.nginx/nginx.conf /etc/nginx/conf.d/default.conf
 
 
89
 
 
90
  # Remove default nginx static assets
91
  # RUN rm -rf ./*
92
 
93
  # WORKDIR /usr/share/nginx/html
94
 
95
 
96
- WORKDIR $HOME
97
 
98
 
99
 
100
  # Copy static assets from builder stage
101
- COPY --chown=luminlab:luminlab --from=build /app ./app
102
 
103
 
 
 
104
 
105
- USER luminlab:luminlab
106
 
107
  # Switch to the "user" user
108
  # ENTRYPOINT ["sh", "run_hf.sh"]
 
1
+ ARG PY_VER=3.10
2
+
3
  # Default user is 'luminlab' with uid 1000, gid 1000
4
+ FROM python:${PY_VER} as lean
5
 
6
  # Install nginx and give permissions to 'luminlab'
7
  # See https://www.rockyourcode.com/run-docker-nginx-as-non-root-user/
 
8
 
9
  RUN apt-get -y update && apt-get -y install nginx
10
 
11
+
12
+
13
+
14
+
15
+ # Set up a new user named "luminlab" with user ID 1000
16
+ RUN useradd -m -u 1000 luminlab
17
+ # groupadd luminlab &&\
18
+ # usermod -aG luminlab luminlab
19
+
20
+
21
  RUN mkdir -p /var/cache/nginx \
22
  /var/log/nginx \
23
  /var/lib/nginx
24
  RUN touch /var/run/nginx.pid
25
 
26
+ RUN chown -R luminlab /var/cache/nginx \
27
+ /var/log/nginx \
28
+ /var/lib/nginx \
29
+ /var/run/nginx.pid
30
 
31
+ # COPY --chown=luminlab .nginx/nginx.conf /etc/nginx/conf.d/default.conf
32
+ COPY --chown=luminlab .nginx/nginx.conf /etc/nginx/nginx.conf
 
 
 
 
33
 
34
 
35
  # # Set home to the user's home directory
 
38
 
39
  # # Set the working directory to the user's home directory
40
  # WORKDIR $HOME/app
 
 
 
 
41
 
42
  # syntax=docker/dockerfile:1.4
43
+ # ENV HOME=/home/luminlab \
44
+ # PATH=/home/luminlab/.local/bin:$PATH
45
 
46
+ # RUN mkdir $HOME/app
47
 
48
  # 1. For build React app
49
+ FROM node:16-slim AS node
50
 
51
  # Set working directory
52
  WORKDIR /app
53
 
54
  #
55
+ COPY package.json /app/package.json
56
+ COPY package-lock.json /app/package-lock.json
57
 
58
  # Same as npm install
59
  RUN npm ci
60
 
61
+ # COPY --chown=luminlab:luminlab . .
62
 
63
  ENV CI=true
64
  ENV PORT=3000
 
86
  # COPY --chown=luminlab nginx.conf /etc/nginx/sites-available/default
87
 
88
  # COPY --chown=luminlab . .
89
+
90
+ USER luminlab:luminlab
91
+
92
+ FROM lean AS prod
93
+
94
+
95
 
96
  # Copy config nginx
97
+ # COPY --chown=luminlab:luminlab --from=dev /var/cache/nginx /var/cache/nginx
98
+ # COPY --chown=luminlab:luminlab --from=dev /var/log/nginx /var/log/nginx
99
+ # COPY --chown=luminlab:luminlab --from=dev /var/lib/nginx /var/lib/nginx
100
 
101
+ COPY --chown=luminlab --from=node /app ./app
102
  # Remove default nginx static assets
103
  # RUN rm -rf ./*
104
 
105
  # WORKDIR /usr/share/nginx/html
106
 
107
 
108
+ WORKDIR /app
109
 
110
 
111
 
112
  # Copy static assets from builder stage
 
113
 
114
 
115
+ # RUN chown -R luminlab:luminlab /var
116
+
117
 
 
118
 
119
  # Switch to the "user" user
120
  # ENTRYPOINT ["sh", "run_hf.sh"]
docker-compose.yaml CHANGED
@@ -3,11 +3,17 @@ services:
3
  build:
4
  context: .
5
  container_name: luminlab-nginx-frontend
6
- user: root
 
 
 
 
 
7
  ports:
8
  - "80:3000"
9
  - "3000:3000"
10
  volumes:
11
  - ./run_hf.sh:/app/run_hf.sh
 
12
 
13
 
 
3
  build:
4
  context: .
5
  container_name: luminlab-nginx-frontend
6
+ # user: root
7
+ #UID=${UID} GID=${GID} docker-compose up
8
+ #(or define UID and GID as environment variables)
9
+ # user: "${UID}:${GID}"
10
+ user: 1000:1000
11
+ # user: root
12
  ports:
13
  - "80:3000"
14
  - "3000:3000"
15
  volumes:
16
  - ./run_hf.sh:/app/run_hf.sh
17
+ - .nginx/nginx.conf:/etc/nginx/nginx.conf
18
 
19