Skip to content

Commit 4aab013

Browse files
authored
feature: add caching nginx (#153)
1 parent 4f3542a commit 4aab013

File tree

5 files changed

+118
-1
lines changed

5 files changed

+118
-1
lines changed

charts/verdaccio/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apiVersion: v2
22
description: A lightweight private node.js proxy registry
33
name: verdaccio
4-
version: 4.19.0
4+
version: 4.20.0
55
appVersion: 6.0.0
66
home: https://verdaccio.org
77
icon: https://cdn.verdaccio.dev/logos/default.png
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
{{- if .Values.cachingNginx.enabled }}
2+
apiVersion: v1
3+
kind: ConfigMap
4+
metadata:
5+
name: {{ template "verdaccio.fullname" . }}-nginx-config
6+
data:
7+
nginx.conf: |
8+
user nginx;
9+
worker_processes 4;
10+
pid /var/run/nginx.pid;
11+
error_log /dev/stderr info;
12+
events {
13+
worker_connections 10240;
14+
use epoll;
15+
}
16+
http {
17+
include /etc/nginx/mime.types;
18+
default_type application/octet-stream;
19+
server_names_hash_max_size 512;
20+
server_names_hash_bucket_size 64;
21+
sendfile on;
22+
tcp_nopush on;
23+
tcp_nodelay on;
24+
proxy_buffer_size 4k;
25+
proxy_buffers 1024 4k;
26+
proxy_read_timeout 2m;
27+
proxy_send_timeout 2m;
28+
fastcgi_buffer_size 4k;
29+
fastcgi_buffers 1024 4k;
30+
keepalive_timeout 10;
31+
keepalive_requests 100;
32+
reset_timedout_connection on;
33+
client_max_body_size 100m;
34+
gzip on;
35+
gzip_types text/css application/x-javascript application/javascript text/javascript text/plain;
36+
gzip_comp_level 6;
37+
gzip_min_length 100;
38+
gzip_http_version 1.0;
39+
gzip_proxied any;
40+
gzip_disable "msie6";
41+
gzip_vary on;
42+
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
43+
ssl_ciphers 'EECDH+ECDSA+AESGCM:EECDH+aRSA+AESGCM:EECDH+ECDSA+SHA384:EECDH+ECDSA+SHA256:EECDH+aRSA+SHA384:EECDH+aRSA+SHA256:EECDH+aRSA+RC4:EECDH:EDH+aRSA:RC4:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!SRP:!DSS:!RC4';
44+
ssl_session_cache shared:SSL:10m;
45+
ssl_session_timeout 30m;
46+
ssl_buffer_size 4k;
47+
ssl_prefer_server_ciphers on;
48+
ssl_session_tickets off;
49+
log_format main escape=json
50+
'{'
51+
'"time_local":"$time_local",'
52+
'"remote_addr":"$remote_addr",'
53+
'"remote_user":"$remote_user",'
54+
'"request":"$request",'
55+
'"status": "$status",'
56+
'"body_bytes_sent":"$body_bytes_sent",'
57+
'"request_time":"$request_time",'
58+
'"http_referrer":"$http_referer",'
59+
'"http_user_agent":"$http_user_agent"'
60+
'}';
61+
access_log /dev/stdout main;
62+
real_ip_header X-Real-IP;
63+
set_real_ip_from 0.0.0.0/0;
64+
proxy_cache_path {{ .Values.cachingNginx.proxyCachePath }}
65+
include /etc/nginx/conf.d/*.conf;
66+
}
67+
default.conf: |
68+
server {
69+
listen 80;
70+
location / {
71+
proxy_pass http://127.0.0.1:4873;
72+
proxy_http_version 1.1;
73+
proxy_set_header Upgrade $http_upgrade;
74+
proxy_set_header Connection 'upgrade';
75+
proxy_set_header Host $host;
76+
}
77+
}
78+
{{- end }}

charts/verdaccio/templates/deployment.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ spec:
3131
{{- if .Values.secretEnvVars }}
3232
checksum/env-secret: {{ include (print $.Template.BasePath "/secret.yaml") . | sha256sum }}
3333
{{- end }}
34+
{{- if .Values.cachingNginx.enabled }}
35+
checksum/config-nginx: {{ include (print $.Template.BasePath "/configmap-nginx.yaml") . | sha256sum }}
36+
{{- end }}
3437
{{- include "verdaccio.podAnnotations" . | nindent 8 }}
3538
labels:
3639
{{- include "verdaccio.podLabels" . | nindent 8 }}
@@ -46,6 +49,23 @@ spec:
4649
{{- include "tplvalues.render" (dict "value" . "context" $) | nindent 8 }}
4750
{{- end }}
4851
containers:
52+
{{- if .Values.cachingNginx.enabled }}
53+
- name: {{ template "verdaccio.name" . }}-nginx
54+
imagePullPolicy: {{ .Values.cachingNginx.pullPolicy }}
55+
image: {{ .Values.cachingNginx.repository }}:{{ .Values.cachingNginx.tag }}
56+
volumeMounts:
57+
- name: config-volume
58+
mountPath: /etc/nginx/nginx.conf
59+
subPath: nginx.conf
60+
- name: config-volume
61+
mountPath: /etc/nginx/conf.d/default.conf
62+
subPath: default.conf
63+
resources:
64+
{{ toYaml .Values.cachingNginx.resources | nindent 12 }}
65+
ports:
66+
- containerPort: 80
67+
name: caching-nginx
68+
{{- end }}
4969
- name: {{ template "verdaccio.name" . }}
5070
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
5171
imagePullPolicy: {{ .Values.image.pullPolicy }}
@@ -126,6 +146,11 @@ spec:
126146
secret:
127147
secretName: {{ include "verdaccio.fullname" . }}-htpasswd
128148
{{- end }}
149+
{{- if .Values.cachingNginx.enabled }}
150+
- name: config-volume
151+
configMap:
152+
name: {{ include "verdaccio.fullname" . }}-nginx-config
153+
{{- end }}
129154
{{- with .Values.persistence.volumes }}
130155
{{- include "tplvalues.render" (dict "value" . "context" $) | nindent 6 }}
131156
{{- end }}

charts/verdaccio/templates/service.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ spec:
2525
{{- end }}
2626
ports:
2727
- port: {{ .Values.service.port }}
28+
{{- if .Values.cachingNginx.enabled }}
29+
targetPort: caching-nginx
30+
{{- else }}
2831
targetPort: http
32+
{{- end }}
2933
protocol: TCP
3034
name: {{ .Values.service.name | default "http"}}
3135
{{- if contains "NodePort" .Values.service.type }}

charts/verdaccio/values.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,3 +278,13 @@ extraManifests: []
278278
# app: verdaccio
279279
# endpoints:
280280
# - port: metrics
281+
282+
# Additional container with caching nginx
283+
# Can be useful for intensive load
284+
cachingNginx:
285+
enabled: false
286+
repository: nginx
287+
tag: 1.25.0
288+
pullPolicy: IfNotPresent
289+
proxyCachePath: '/var/cache/nginx levels=1:2 keys_zone=STATIC:100m inactive=12h max_size=1g;'
290+
resources: {}

0 commit comments

Comments
 (0)