diff --git a/.gitignore b/.gitignore index 2f01eb3c1..83c46b69e 100644 --- a/.gitignore +++ b/.gitignore @@ -37,6 +37,7 @@ src/portal/src/**/*.js src/portal/src/**/*.js.map src/portal/src/lib/coverage src/portal/ng-swagger-gen +src/portal/docker-build/nginx.conf **/npm*.log **/*ngsummary.json diff --git a/src/portal/docker-build/Dockerfile b/src/portal/docker-build/Dockerfile new file mode 100644 index 000000000..0e052fb01 --- /dev/null +++ b/src/portal/docker-build/Dockerfile @@ -0,0 +1,35 @@ +FROM node:16.5.0 as builder + +WORKDIR /build_dir + +COPY src/portal /build_dir +COPY api/v2.0/legacy_swagger.yaml /build_dir/swagger.yaml +COPY api/v2.0/swagger.yaml /build_dir/swagger2.yaml +COPY api/swagger.yaml /build_dir/swagger3.yaml + +RUN apt-get update \ + && apt-get install -y --no-install-recommends python-yaml +RUN npm install --unsafe-perm +RUN npm run postinstall +RUN npm run generate-build-timestamp +RUN node --max_old_space_size=2048 'node_modules/@angular/cli/bin/ng' build --configuration production +RUN python -c 'import sys, yaml, json; y=yaml.load(sys.stdin.read()); print json.dumps(y)' < swagger.yaml > dist/swagger.json +RUN python -c 'import sys, yaml, json; y=yaml.load(sys.stdin.read()); print json.dumps(y)' < swagger2.yaml > dist/swagger2.json +RUN python -c 'import sys, yaml, json; y=yaml.load(sys.stdin.read()); print json.dumps(y)' < swagger3.yaml > dist/swagger3.json + +COPY LICENSE /build_dir/dist + + +FROM nginx:1.17 + +COPY --from=builder /build_dir/dist /usr/share/nginx/html +COPY src/portal/docker-build/nginx.conf /etc/nginx/nginx.conf + +EXPOSE 8080 +VOLUME /var/cache/nginx /var/log/nginx /run + +STOPSIGNAL SIGQUIT + +HEALTHCHECK CMD curl --fail -s http://127.0.0.1:8080 || exit 1 +USER nginx +CMD ["nginx", "-g", "daemon off;"] diff --git a/src/portal/docker-build/README.md b/src/portal/docker-build/README.md new file mode 100644 index 000000000..7e0b451a1 --- /dev/null +++ b/src/portal/docker-build/README.md @@ -0,0 +1,23 @@ +Steps to deploy Harbor UI in a nginx container, it can be used for testing + +1. Go to docker-build dir + +`cd ./docker-build` + +2. Copy `nginx.conf.example` to `nginx.conf`, and modify nginx.conf file to specify an available back-end server + +`cp nginx.conf.example nginx.conf` + +`location ~ /(api|c)/* { + proxy_pass ${an available back-end server addr}; + }` + +3. Build harbor-ui image + +`docker build -f ./Dockerfile -t harbor-ui:test ./../../..` + +4. Run harbor-ui image + +`docker run -p 8080:8080 harbor-ui:test` + +5. Open your browser on http://localhost:8080 diff --git a/src/portal/docker-build/nginx.conf.example b/src/portal/docker-build/nginx.conf.example new file mode 100644 index 000000000..0f6db9cb6 --- /dev/null +++ b/src/portal/docker-build/nginx.conf.example @@ -0,0 +1,41 @@ +worker_processes auto; +pid /tmp/nginx.pid; + +events { + worker_connections 1024; +} + +http { + + client_body_temp_path /tmp/client_body_temp; + proxy_temp_path /tmp/proxy_temp; + fastcgi_temp_path /tmp/fastcgi_temp; + uwsgi_temp_path /tmp/uwsgi_temp; + scgi_temp_path /tmp/scgi_temp; + + server { + listen 8080; + server_name localhost; + + root /usr/share/nginx/html; + index index.html index.htm; + include /etc/nginx/mime.types; + + gzip on; + gzip_min_length 1000; + gzip_proxied expired no-cache no-store private auth; + gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript; + + location / { + try_files $uri $uri/ /index.html; + } + + location = /index.html { + add_header Cache-Control "no-store, no-cache, must-revalidate"; + } + + location ~ /(api|c)/* { + proxy_pass https://example.com; + } + } +}