-
Notifications
You must be signed in to change notification settings - Fork 50
/
run.sh
executable file
·235 lines (211 loc) · 6.1 KB
/
run.sh
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#!/bin/bash
ADMIN_PASSWORD=${ADMIN_PASSWORD:-docker}
REGISTRY_NAME=${REGISTRY_NAME:-Docker Registry}
SSL_CERT_PATH=${SSL_CERT_PATH:-}
SSL_CERT_KEY_PATH=${SSL_CERT_KEY_PATH:-}
CACHE_REDIS_PASSWORD=${REDIS_PASSWORD:-docker}
CACHE_LRU_REDIS_PASSWORD=${REDIS_PASSWORD:-docker}
export CACHE_REDIS_PASSWORD
export CACHE_LRU_REDIS_PASSWORD
# nginx config
cat << EOF > /usr/local/openresty/nginx/conf/registry.conf
user root;
daemon off;
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 2048;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
server_names_hash_bucket_size 64;
server_name_in_redirect on;
include /usr/local/openresty/nginx/conf/mime.types;
default_type application/octet-stream;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
upstream manage {
server localhost:4000;
}
upstream registry {
server localhost:5000;
}
server {
listen 80;
client_max_body_size 0;
proxy_set_header Host \$http_host;
proxy_set_header X-Forwarded-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-Scheme \$scheme;
proxy_set_header Authorization "";
location / {
auth_basic "$REGISTRY_NAME";
auth_basic_user_file /etc/registry.users;
proxy_pass http://registry;
}
location /v1/_ping {
auth_basic off;
proxy_pass http://registry;
}
location /v1/users {
auth_basic off;
proxy_pass http://registry;
}
location /static {
alias /app/static;
expires 1d;
}
location = /manage { rewrite ^ /manage/; }
location /manage/ { try_files \$uri @manage; }
location @manage {
auth_basic "$REGISTRY_NAME";
auth_basic_user_file /etc/registry.users;
proxy_redirect off;
include uwsgi_params;
uwsgi_param SCRIPT_NAME /manage;
uwsgi_modifier1 30;
uwsgi_pass unix:/tmp/uwsgi-manage.sock;
}
}
EOF
if [ ! -z "$SSL_CERT_PATH" ]; then
cat << EOF >> /usr/local/openresty/nginx/conf/registry.conf
server {
listen 443;
ssl on;
ssl_certificate $SSL_CERT_PATH;
ssl_certificate_key $SSL_CERT_KEY_PATH;
client_max_body_size 0;
proxy_set_header Host \$http_host;
proxy_set_header X-Forwarded-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-Scheme \$scheme;
proxy_set_header Authorization "";
location / {
auth_basic "$REGISTRY_NAME";
auth_basic_user_file /etc/registry.users;
proxy_pass http://registry;
}
location /v1/_ping {
auth_basic off;
proxy_pass http://registry;
}
location /v1/users {
auth_basic off;
proxy_pass http://registry;
}
location /static {
alias /app/static;
expires 1d;
}
location = /manage { rewrite ^ /manage/; }
location /manage/ { try_files \$uri @manage; }
location @manage {
auth_basic "$REGISTRY_NAME";
auth_basic_user_file /etc/registry.users;
proxy_redirect off;
include uwsgi_params;
uwsgi_param SCRIPT_NAME /manage;
uwsgi_modifier1 30;
uwsgi_pass unix:/tmp/uwsgi-manage.sock;
}
}
EOF
fi
cat << EOF >> /usr/local/openresty/nginx/conf/registry.conf
}
EOF
# uwsgi config (manage)
cat << EOF > /etc/manage.ini
[uwsgi]
chdir = /app
socket = /tmp/uwsgi-manage.sock
workers = 8
buffer-size = 32768
master = true
max-requests = 5000
static-map = /static=/app/static
module = wsgi:application
EOF
# redis config
cat << EOF >> /etc/redis.conf
daemonize no
requirepass $CACHE_REDIS_PASSWORD
maxmemory 2mb
maxmemory-policy allkeys-lru
EOF
# supervisor config
cat << EOF > /etc/supervisor/supervisor.conf
[supervisord]
nodaemon=false
[unix_http_server]
file=/var/run/supervisor.sock
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///var/run//supervisor.sock
[program:redis]
priority=05
user=root
command=/usr/bin/redis-server /etc/redis.conf
directory=/var/lib/redis
autostart=true
autorestart=true
stopsignal=QUIT
[program:registry]
priority=10
user=root
command=gunicorn --access-logfile - --debug --max-requests 5000 --graceful-timeout 3600 -t 3600 -k gevent -b 0.0.0.0:5000 -w 4 wsgi:application
directory=/docker-registry
autostart=true
autorestart=true
stopsignal=QUIT
[program:manage]
priority=20
user=root
command=/usr/local/bin/uwsgi --ini /etc/manage.ini
directory=/app
autostart=true
autorestart=true
stopsignal=QUIT
[program:nginx]
priority=50
user=root
command=/usr/local/openresty/nginx/sbin/nginx -c /usr/local/openresty/nginx/conf/registry.conf
directory=/tmp
autostart=true
autorestart=true
EOF
# create password file if needed
if [ ! -e "/etc/registry.users" ] ; then
htpasswd -bc /etc/registry.users admin $ADMIN_PASSWORD
fi
# configure registry
cd /docker-registry
bash setup-configs.sh
# run supervisor
supervisord -c /etc/supervisor/supervisor.conf -n