initial commit
This commit is contained in:
commit
10c655c720
3
.gitignore
vendored
Executable file
3
.gitignore
vendored
Executable file
@ -0,0 +1,3 @@
|
||||
*~
|
||||
.DS_Store
|
||||
*.swp
|
35
Dockerfile
Normal file
35
Dockerfile
Normal file
@ -0,0 +1,35 @@
|
||||
FROM thallian/confd-env:latest
|
||||
|
||||
RUN addgroup syncer
|
||||
RUN adduser -h /var/lib/koreader-sync -D -G syncer syncer
|
||||
|
||||
RUN apk --no-cache add tar make git openssl perl gcc musl-dev pcre pcre-dev openssl-dev lua lua-dev unzip curl
|
||||
RUN apk --no-cache --repository http://dl-3.alpinelinux.org/alpine/edge/testing/ --allow-untrusted add luarocks5.1
|
||||
|
||||
RUN luarocks-5.1 install luasec
|
||||
RUN luarocks-5.1 install luaposix
|
||||
RUN luarocks-5.1 install redis-lua
|
||||
RUN luarocks-5.1 install busted
|
||||
|
||||
RUN mkdir /tmp/openresty
|
||||
RUN wget -qO- https://openresty.org/download/openresty-1.9.15.1.tar.gz | tar -xz -C /tmp/openresty --strip 1
|
||||
|
||||
WORKDIR /tmp/openresty
|
||||
RUN ./configure --prefix=/opt/openresty && make && make install
|
||||
RUN rm -r /tmp/openresty
|
||||
ENV PATH /opt/openresty/nginx/sbin:$PATH
|
||||
|
||||
WORKDIR /var/lib/koreader-sync
|
||||
RUN git clone https://github.com/ostinelli/gin
|
||||
ADD /rootfs /
|
||||
|
||||
RUN cd gin && patch -N -p1 < ../gin.patch
|
||||
RUN cd gin && luarocks-5.1 make
|
||||
ENV GIN_ENV production
|
||||
|
||||
RUN git clone https://github.com/koreader/koreader-sync-server.git server
|
||||
RUN chown -R syncer:syncer /var/lib/koreader-sync
|
||||
|
||||
RUN apk del tar make git gcc musl-dev pcre-dev openssl-dev lua-dev
|
||||
|
||||
EXPOSE 7200
|
3
rootfs/etc/confd/conf.d/nginx.conf.toml
Normal file
3
rootfs/etc/confd/conf.d/nginx.conf.toml
Normal file
@ -0,0 +1,3 @@
|
||||
[template]
|
||||
src = "nginx.conf.tmpl"
|
||||
dest = "/var/lib/koreader-sync/server/config/nginx.conf"
|
3
rootfs/etc/confd/conf.d/redis.conf.toml
Normal file
3
rootfs/etc/confd/conf.d/redis.conf.toml
Normal file
@ -0,0 +1,3 @@
|
||||
[template]
|
||||
src = "redis.conf.tmpl"
|
||||
dest = "/etc/redis.conf"
|
3
rootfs/etc/confd/conf.d/redis.lua.toml
Normal file
3
rootfs/etc/confd/conf.d/redis.lua.toml
Normal file
@ -0,0 +1,3 @@
|
||||
[template]
|
||||
src = "redis.lua.tmpl"
|
||||
dest = "/var/lib/koreader-sync/server/db/redis.lua"
|
38
rootfs/etc/confd/templates/nginx.conf.tmpl
Normal file
38
rootfs/etc/confd/templates/nginx.conf.tmpl
Normal file
@ -0,0 +1,38 @@
|
||||
pid tmp/{{"{{"}}GIN_ENV{{"}}"}}-nginx.pid;
|
||||
|
||||
# This number should be at maxium the number of CPU on the server
|
||||
worker_processes 4;
|
||||
#daemon off;
|
||||
|
||||
events {
|
||||
# Number of connections per worker
|
||||
worker_connections 4096;
|
||||
}
|
||||
|
||||
http {
|
||||
# use sendfile
|
||||
sendfile on;
|
||||
|
||||
# Gin initialization
|
||||
{{"{{"}}GIN_INIT{{"}}"}}
|
||||
|
||||
ssl_session_cache shared:SSL:10m;
|
||||
ssl_session_timeout 10m;
|
||||
|
||||
server {
|
||||
# List port
|
||||
listen {{"{{"}}GIN_PORT{{"}}"}};
|
||||
|
||||
keepalive_timeout 70;
|
||||
|
||||
# Access log with buffer, or disable it completetely if unneeded
|
||||
access_log logs/{{"{{"}}GIN_ENV{{"}}"}}-access.log combined buffer=16k;
|
||||
# access_log off;
|
||||
|
||||
# Error log
|
||||
error_log logs/{{"{{"}}GIN_ENV{{"}}"}}-error.log debug;
|
||||
|
||||
# Gin runtime
|
||||
{{"{{"}}GIN_RUNTIME{{"}}"}}
|
||||
}
|
||||
}
|
49
rootfs/etc/confd/templates/redis.conf.tmpl
Normal file
49
rootfs/etc/confd/templates/redis.conf.tmpl
Normal file
@ -0,0 +1,49 @@
|
||||
{{if (getenv "REDIS_BIND")}}
|
||||
bind {{getenv "REDIS_BIND"}}
|
||||
{{end}}
|
||||
protected-mode no
|
||||
port 6379
|
||||
tcp-backlog 511
|
||||
timeout 0
|
||||
tcp-keepalive 0
|
||||
daemonize no
|
||||
supervised no
|
||||
loglevel notice
|
||||
logfile ''
|
||||
databases 16
|
||||
save 900 1
|
||||
save 300 10
|
||||
save 60 10000
|
||||
stop-writes-on-bgsave-error yes
|
||||
rdbcompression yes
|
||||
rdbchecksum yes
|
||||
dbfilename dump.rdb
|
||||
dir /var/lib/redis/
|
||||
{{if (getenv "REDIS_PASSWORD")}}
|
||||
requirepass {{getenv "REDIS_PASSWORD"}}
|
||||
{{end}}
|
||||
appendonly no
|
||||
appendfsync everysec
|
||||
no-appendfsync-on-rewrite no
|
||||
auto-aof-rewrite-percentage 100
|
||||
auto-aof-rewrite-min-size 64mb
|
||||
aof-load-truncated yes
|
||||
lua-time-limit 5000
|
||||
slowlog-log-slower-than 10000
|
||||
slowlog-max-len 128
|
||||
latency-monitor-threshold 0
|
||||
notify-keyspace-events ""
|
||||
hash-max-ziplist-entries 512
|
||||
hash-max-ziplist-value 64
|
||||
list-max-ziplist-size -2
|
||||
list-compress-depth 0
|
||||
set-max-intset-entries 512
|
||||
zset-max-ziplist-entries 128
|
||||
zset-max-ziplist-value 64
|
||||
hll-sparse-max-bytes 3000
|
||||
activerehashing yes
|
||||
client-output-buffer-limit normal 0 0 0
|
||||
client-output-buffer-limit slave 256mb 64mb 60
|
||||
client-output-buffer-limit pubsub 32mb 8mb 60
|
||||
hz 10
|
||||
aof-rewrite-incremental-fsync yes
|
44
rootfs/etc/confd/templates/redis.lua.tmpl
Normal file
44
rootfs/etc/confd/templates/redis.lua.tmpl
Normal file
@ -0,0 +1,44 @@
|
||||
local Gin = require 'gin.core.gin'
|
||||
|
||||
-- First, specify the environment settings for this database, for instance:
|
||||
local DbSettings = {
|
||||
development = {
|
||||
host = "127.0.0.1",
|
||||
port = 6379,
|
||||
database = 1,
|
||||
pool = 5
|
||||
},
|
||||
|
||||
test = {
|
||||
host = "127.0.0.1",
|
||||
port = 6379,
|
||||
database = 2,
|
||||
pool = 5
|
||||
},
|
||||
|
||||
production = {
|
||||
host = "{{getenv "REDIS_HOST"}}",
|
||||
port = 6379,
|
||||
database = 3,
|
||||
pool = 5
|
||||
}
|
||||
}
|
||||
|
||||
-- Then initialize and return your database:
|
||||
local Redis = {
|
||||
options = {},
|
||||
}
|
||||
|
||||
function Redis:new()
|
||||
local redis = require("resty.redis")
|
||||
local option = DbSettings[Gin.env]
|
||||
local red = redis:new()
|
||||
red:set_timeout(1000) -- 1 sec
|
||||
local ok, err = red:connect(option.host, option.port)
|
||||
if ok then
|
||||
red:select(option.database)
|
||||
return red
|
||||
end
|
||||
end
|
||||
|
||||
return Redis
|
5
rootfs/etc/services.d/koreader-sync/run
Normal file
5
rootfs/etc/services.d/koreader-sync/run
Normal file
@ -0,0 +1,5 @@
|
||||
#!/usr/bin/with-contenv sh
|
||||
|
||||
cd /var/lib/koreader-sync/server
|
||||
s6-setuidgid syncer gin start
|
||||
tail -f /var/lib/koreader-sync/server/logs/production-access.log
|
47
rootfs/var/lib/koreader-sync/gin.patch
Normal file
47
rootfs/var/lib/koreader-sync/gin.patch
Normal file
@ -0,0 +1,47 @@
|
||||
diff --git a/gin-0.2.0-1.rockspec b/gin-0.2.0-1.rockspec
|
||||
index b9601ec..55f4469 100644
|
||||
--- a/gin-0.2.0-1.rockspec
|
||||
+++ b/gin-0.2.0-1.rockspec
|
||||
@@ -18,8 +18,9 @@ dependencies = {
|
||||
"busted = 2.0.rc10-0",
|
||||
"lua-cjson = 2.1.0-1",
|
||||
"luasocket = 3.0rc1-2",
|
||||
+ "luasec = 0.5-2",
|
||||
"luafilesystem = 1.6.3-1",
|
||||
- "luaposix = 33.3.1-1",
|
||||
+ "luaposix = 33.4.0",
|
||||
"penlight = 1.3.2-2",
|
||||
"luadbi = 0.5-1"
|
||||
}
|
||||
diff --git a/gin/spec/runners/integration.lua b/gin/spec/runners/integration.lua
|
||||
index 5ef537a..21ec8f9 100644
|
||||
--- a/gin/spec/runners/integration.lua
|
||||
+++ b/gin/spec/runners/integration.lua
|
||||
@@ -1,5 +1,6 @@
|
||||
-- dep
|
||||
local http = require 'socket.http'
|
||||
+local https = require 'ssl.https'
|
||||
local url = require 'socket.url'
|
||||
local json = require 'cjson'
|
||||
local ltn12 = require 'ltn12'
|
||||
@@ -82,8 +83,9 @@ local function set_accept_header(request, api_version)
|
||||
end
|
||||
|
||||
local function hit_server(request)
|
||||
+ local scheme = request.scheme or 'http'
|
||||
local full_url = url.build({
|
||||
- scheme = 'http',
|
||||
+ scheme = scheme,
|
||||
host = '127.0.0.1',
|
||||
port = Gin.settings.port,
|
||||
path = request.path,
|
||||
@@ -91,7 +93,8 @@ local function hit_server(request)
|
||||
})
|
||||
|
||||
local response_body = {}
|
||||
- local ok, response_status, response_headers = http.request({
|
||||
+ local http_request = (scheme == 'https') and https.request or http.request
|
||||
+ local ok, response_status, response_headers = http_request({
|
||||
method = request.method,
|
||||
url = full_url,
|
||||
source = ltn12.source.string(request.body),
|
Loading…
Reference in New Issue
Block a user