FindKotnol commited on
Commit
cdfea06
·
verified ·
1 Parent(s): f43f2ca

feat: add nginx

Browse files
Files changed (1) hide show
  1. Dockerfile +99 -36
Dockerfile CHANGED
@@ -4,7 +4,7 @@ RUN apk update
4
 
5
  RUN apk upgrade
6
 
7
- RUN apk add --no-cache ffmpeg mimalloc2 py3-pillow
8
 
9
  RUN adduser --disabled-password --uid 1000 user
10
 
@@ -20,44 +20,107 @@ WORKDIR $HOME/app
20
 
21
  RUN pip install --no-cache-dir copyparty
22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  RUN chown -R user:user $HOME
24
 
25
  USER user
26
 
27
  EXPOSE 7860
28
 
29
- CMD ["/bin/sh", "-c", "\
30
- if [ -z \"$ADMIN_PASSWORD\" ]; then \
31
- echo 'ERROR: ADMIN_PASSWORD is not found.'; \
32
- exit 1; \
33
- fi; \
34
- cat > /home/user/app/copyparty.conf <<EOF\n\
35
- [global]\n\
36
- dedup\n\
37
- e2dsa\n\
38
- hash-mt: 0\n\
39
- hist: /data/.hist\n\
40
- i: 0.0.0.0\n\
41
- mtag-mt: 1\n\
42
- no-dirsz\n\
43
- no-htp\n\
44
- no-robots\n\
45
- no-thumb\n\
46
- p: 7860\n\
47
- q\n\
48
- rproxy: -1\n\
49
- safe-dedup: 1\n\
50
- xf-proto-fb: https\n\
51
- xff-src: lan\n\
52
- \n\
53
- [accounts]\n\
54
- admin: $ADMIN_PASSWORD\n\
55
- \n\
56
- [/]\n\
57
- /data\n\
58
- accs:\n\
59
- r: *\n\
60
- A: admin\n\
61
- EOF\n\
62
- python -m copyparty -c /home/user/app/copyparty.conf \
63
- "]
 
4
 
5
  RUN apk upgrade
6
 
7
+ RUN apk add --no-cache ffmpeg mimalloc2 nginx py3-pillow
8
 
9
  RUN adduser --disabled-password --uid 1000 user
10
 
 
20
 
21
  RUN pip install --no-cache-dir copyparty
22
 
23
+ RUN cat >/home/user/app/start.sh <<'EOF_START'
24
+ #!/bin/sh
25
+ set -eu
26
+
27
+ if [ -z "${ADMIN_PASSWORD:-}" ]; then
28
+ echo "ERROR: ADMIN_PASSWORD is not found."
29
+ exit 1
30
+ fi
31
+
32
+ if [ -z "${BASE_DOWNLOAD_URL:-}" ]; then
33
+ echo "ERROR: BASE_DOWNLOAD_URL is not found."
34
+ exit 1
35
+ fi
36
+
37
+ BASE_DOWNLOAD_URL="${BASE_DOWNLOAD_URL%/}"
38
+
39
+ cat > /home/user/app/copyparty.conf <<EOF
40
+ [global]
41
+ dedup
42
+ e2dsa
43
+ hist: /data/.hist
44
+ no-robots
45
+ no-thumb
46
+ q
47
+ rproxy: -1
48
+ safe-dedup: 1
49
+ xf-proto-fb: https
50
+ xff-src: lan
51
+
52
+ [accounts]
53
+ admin: ${ADMIN_PASSWORD}
54
+
55
+ [/]
56
+ /data
57
+ accs:
58
+ r: *
59
+ A: admin
60
+ EOF
61
+
62
+ cat > /home/user/app/nginx.conf <<EOF
63
+ pid /tmp/nginx.pid;
64
+
65
+ events {
66
+ worker_connections 1024;
67
+ }
68
+
69
+ http {
70
+ include /etc/nginx/mime.types;
71
+ default_type application/octet-stream;
72
+ access_log off;
73
+ error_log /dev/stderr warn;
74
+ sendfile on;
75
+
76
+ client_body_temp_path /tmp/nginx-client-body;
77
+ proxy_temp_path /tmp/nginx-proxy;
78
+ fastcgi_temp_path /tmp/nginx-fastcgi;
79
+ uwsgi_temp_path /tmp/nginx-uwsgi;
80
+ scgi_temp_path /tmp/nginx-scgi;
81
+
82
+ map \$http_upgrade \$connection_upgrade {
83
+ default upgrade;
84
+ "" close;
85
+ }
86
+
87
+ server {
88
+ listen 7860;
89
+ server_name _;
90
+ root /data;
91
+
92
+ location / {
93
+ set \$redirect_file "";
94
+ if (\$request_method ~ ^(GET|HEAD)$) { set \$redirect_file A; }
95
+ if (\$args = "") { set \$redirect_file \${redirect_file}B; }
96
+ if (-f \$request_filename) { set \$redirect_file \${redirect_file}C; }
97
+ if (\$redirect_file = ABC) { return 302 ${BASE_DOWNLOAD_URL}\$request_uri; }
98
+
99
+ proxy_http_version 1.1;
100
+ proxy_pass http://127.0.0.1:3923;
101
+ proxy_request_buffering off;
102
+ proxy_set_header Connection \$connection_upgrade;
103
+ proxy_set_header Host \$host;
104
+ proxy_set_header Upgrade \$http_upgrade;
105
+ proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
106
+ proxy_set_header X-Forwarded-Host \$host;
107
+ proxy_set_header X-Forwarded-Proto https;
108
+ proxy_set_header X-Real-IP \$remote_addr;
109
+ }
110
+ }
111
+ }
112
+ EOF
113
+
114
+ python -m copyparty -c /home/user/app/copyparty.conf &
115
+ exec nginx -c /home/user/app/nginx.conf -g "daemon off;"
116
+ EOF_START
117
+
118
+ RUN chmod +x /home/user/app/start.sh
119
+
120
  RUN chown -R user:user $HOME
121
 
122
  USER user
123
 
124
  EXPOSE 7860
125
 
126
+ CMD ["/bin/sh", "/home/user/app/start.sh"]