diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000000..177f829808a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,44 @@ +# syntax=docker/dockerfile:1 + +# Stage 1: Build the Rancher UI +FROM node:17-alpine as build-stage + +# Create the app directory +RUN mkdir -p /rancher-ui + +# Set the working directory +WORKDIR /rancher-ui + +# Copy the package.json and yarn.lock files +COPY package.json ./ +COPY yarn.lock ./ + +# Copy the source code +COPY pkg ./pkg +COPY shell ./shell + +# Copy the configuration files +COPY .eslint* ./ +COPY babel.config.js ./ +COPY svgTransform.js ./ +COPY tsconfig.json tsconfig.paths.json ./ +COPY vue-shim.d.ts vue.config.js ./ + +# Install the dependencies +RUN yarn install + +# Build the Rancher UI +# Make sure we use the proper SSL provider +RUN NODE_OPTIONS="--openssl-legacy-provider --max_old_space_size=4096" \ + ./node_modules/.bin/vue-cli-service build --mode production + +# Copy the Nginx configuration +# We do this last to avoid invalidating the cache +COPY nginx ./nginx + +# Stage 2: Serve the Rancher UI +FROM nginx:alpine + +# Copy the Rancher UI build +COPY --from=build-stage /rancher-ui/nginx/templates/* /etc/nginx/templates/ +COPY --from=build-stage /rancher-ui/dist /usr/share/nginx/html diff --git a/makefile b/makefile new file mode 100644 index 00000000000..b905c0830fb --- /dev/null +++ b/makefile @@ -0,0 +1,19 @@ +TEST_RANCHER_INSTANCE=rancher.18.236.138.233.sslip.io + +build: + docker buildx build -t rancher-nginx . + +run: build + docker run --name=rancher_nginx -e RANCHER_API=$(API) -d -p 8080:80 rancher-nginx + +local-test: stop + docker run --name=rancher_nginx -e RANCHER_API=$(TEST_RANCHER_INSTANCE) -d -p 8080:80 rancher-nginx + sleep 2 + docker ps + +show-nginx-config: + docker exec -it rancher_nginx nginx -T + +stop: + docker stop rancher_nginx + docker rm rancher_nginx diff --git a/nginx/templates/default.conf.template b/nginx/templates/default.conf.template new file mode 100644 index 00000000000..318aaded594 --- /dev/null +++ b/nginx/templates/default.conf.template @@ -0,0 +1,94 @@ +upstream api { + server ${RANCHER_API}; +} + +upstream ember { + server ${RANCHER_API}; + # server http://127.0.0.1:8000; +} + +log_format custom '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$request_uri"'; + +server { + listen 80; + listen [::]:80; + server_name localhost; + + # access_log /var/log/nginx/host.access.log main; + access_log /var/log/nginx/host.access.log custom; + + location ~ ^/k8s/|/pp/|/api/|/apis/|/v1/|/v3/|/v3-public/|/api-ui|/meta/|/rancherversion|/healthz { + proxy_pass https://api/$request_uri; + # proxy_pass https://rancher.18.236.138.233.sslip.io/$request_uri; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + + add_header x-response-header 'this-is-a-test'; + } + + location ~* ^/v1- { + proxy_pass https://api; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + + location /c/.*/edit { + proxy_pass https://ember; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + + location ~ ^/k/|/g/|/n/|/p/|/assets|/translations|/engines-dist { + proxy_pass https://ember; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + + location / { + root /usr/share/nginx/html; + index index.html; + try_files $uri $uri/ /index.html; + } + + #error_page 404 /404.html; + + # redirect server error pages to the static page /50x.html + # + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } + + # proxy the PHP scripts to Apache listening on 127.0.0.1:80 + # + #location ~ \.php$ { + # proxy_pass http://127.0.0.1; + #} + + # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 + # + #location ~ \.php$ { + # root html; + # fastcgi_pass 127.0.0.1:9000; + # fastcgi_index index.php; + # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; + # include fastcgi_params; + #} + + # deny access to .htaccess files, if Apache's document root + # concurs with nginx's one + # + #location ~ /\.ht { + # deny all; + #} +}