-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathDockerfile.ocui
More file actions
76 lines (63 loc) · 2.13 KB
/
Copy pathDockerfile.ocui
File metadata and controls
76 lines (63 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# FIRST PART
FROM ubuntu:latest AS build-app
WORKDIR /
# Install deps!
RUN apt-get update
RUN apt-get install -y curl zip
# Install node and confirm commands are available
RUN curl -fsSL https://deb.nodesource.com/setup_lts.x | bash - && apt-get install -y nodejs
RUN nodejs --version
RUN npm --version
# # Make the oc directory, and copy code into it
WORKDIR /oc
COPY .dfx .dfx
COPY . .
# Build UI
WORKDIR /oc/frontend
RUN npm ci
RUN npm run build:docker
# SECOND PART
FROM ubuntu:latest
# Install new set of deps, there's some overlap.
RUN apt-get update
RUN apt-get install -y nginx
# Copy the built UI files from the previous stage
COPY --from=build-app /oc/frontend/app/build /usr/share/nginx/html
COPY --from=build-app /oc/frontend/app/public /usr/share/nginx/html
# Nginx conf for serving the UI, and proxying requests to the local canisters.
RUN echo 'server {\n\
listen 80;\n\
server_name localhost;\n\
\n\
location /api {\n\
add_header "Access-Control-Allow-Origin" "*";\n\
add_header "Access-Control-Allow-Methods" "GET, POST, PUT, DELETE, OPTIONS";\n\
add_header "Access-Control-Allow-Headers" "DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range";\n\
add_header "Access-Control-Expose-Headers" "Content-Length,Content-Range";\n\
\n\
if ($request_method = "OPTIONS") {\n\
return 204;\n\
}\n\
\n\
proxy_pass http://0.0.0.0:8080;\n\
proxy_set_header Host $host;\n\
proxy_set_header X-Real-IP $remote_addr;\n\
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n\
proxy_set_header X-Forwarded-Proto $scheme;\n\
proxy_hide_header "Access-Control-Allow-Origin";\n\
}\n\
\n\
location / {\n\
root /usr/share/nginx/html;\n\
try_files $uri /index.html;\n\
}\n\
}' > /etc/nginx/conf.d/default.conf
WORKDIR /oc
# Create a startup script! `dfx stop` makes sure that any files crated by the
# dfx run in the previous step are removed.
RUN echo '#!/bin/sh\n\
nginx -g "daemon off;"' > start.sh
RUN chmod +x start.sh
# Nginx runs on port 80...
EXPOSE 80
CMD ["/bin/sh", "start.sh"]