Skip to content

Instantly share code, notes, and snippets.

@syhily
Last active June 4, 2022 15:58
Show Gist options
  • Save syhily/d05770ee5e09ca6875cda80c73b07725 to your computer and use it in GitHub Desktop.
Save syhily/d05770ee5e09ca6875cda80c73b07725 to your computer and use it in GitHub Desktop.
How to use docker talebook with MySQL.
#!/usr/bin/env bash
# Patch current talebook for adding permission
grep -qxF 'user.permission = ' /var/www/talebook/webserver/handlers/user.py || sed -i '/user.email = email/a \ \ \ \ \ \ \ \ user.permission = '\''DEPRU'\''' /var/www/talebook/webserver/handlers/user.py
# Start talebook
source /var/www/talebook/docker/start.sh
#!/usr/bin/env bash
# Backup database schema
docker exec talebook_db_1 /usr/bin/mysqldump -u calibre --password=calibre --no-data --no-tablespaces calibre > /volume1/docker/talebook/calibre.sql
# Clean up the reading progress
rm -rf /volume1/docker/talebook/books/extract/*
rm -rf /volume1/docker/talebook/books/progress/*
rm -rf /volume1/docker/talebook/books/upload/*
# Empty the daily access logs
echo "" > /volume1/docker/talebook/log/talebook.log
echo "" > /volume1/docker/talebook/log/nodejs.log
echo "" > /volume1/docker/talebook/log/nginx/talebook-access.log
echo "" > /volume1/docker/talebook/log/nginx/talebook-error.log
-- MySQL dump 10.13 Distrib 5.7.37, for Linux (x86_64)
--
-- Host: localhost Database: calibre
-- ------------------------------------------------------
-- Server version 5.7.37
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
--
-- Table structure for table `items`
--
DROP TABLE IF EXISTS `items`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `items` (
`book_id` int(11) NOT NULL,
`count_guest` int(11) NOT NULL,
`count_visit` int(11) NOT NULL,
`count_download` int(11) NOT NULL,
`website` varchar(255) NOT NULL,
`collector_id` int(11) DEFAULT NULL,
PRIMARY KEY (`book_id`),
KEY `collector_id` (`collector_id`),
CONSTRAINT `items_ibfk_1` FOREIGN KEY (`collector_id`) REFERENCES `readers` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `messages`
--
DROP TABLE IF EXISTS `messages`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `messages` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(200) DEFAULT NULL,
`status` varchar(100) DEFAULT NULL,
`unread` tinyint(1) DEFAULT NULL,
`create_time` datetime DEFAULT NULL,
`update_time` datetime DEFAULT NULL,
`data` text,
`reader_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `reader_id` (`reader_id`),
CONSTRAINT `messages_ibfk_1` FOREIGN KEY (`reader_id`) REFERENCES `readers` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `readers`
--
DROP TABLE IF EXISTS `readers`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `readers` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(200) DEFAULT NULL,
`password` varchar(200) DEFAULT NULL,
`salt` varchar(200) DEFAULT NULL,
`name` varchar(100) DEFAULT NULL,
`email` varchar(200) DEFAULT NULL,
`avatar` varchar(200) DEFAULT NULL,
`admin` tinyint(1) DEFAULT NULL,
`active` tinyint(1) DEFAULT NULL,
`permission` varchar(100) NOT NULL DEFAULT 'DEPU',
`create_time` datetime DEFAULT NULL,
`update_time` datetime DEFAULT NULL,
`access_time` datetime DEFAULT NULL,
`extra` text,
PRIMARY KEY (`id`),
UNIQUE KEY `email` (`email`),
UNIQUE KEY `username` (`username`)
) ENGINE=InnoDB AUTO_INCREMENT=126 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `scanfiles`
--
DROP TABLE IF EXISTS `scanfiles`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `scanfiles` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`scan_id` int(11) DEFAULT NULL,
`import_id` int(11) DEFAULT NULL,
`name` varchar(512) DEFAULT NULL,
`path` varchar(1024) DEFAULT NULL,
`hash` varchar(512) DEFAULT NULL,
`status` varchar(24) DEFAULT NULL,
`title` varchar(100) DEFAULT NULL,
`author` varchar(100) DEFAULT NULL,
`publisher` varchar(100) DEFAULT NULL,
`tags` varchar(100) DEFAULT NULL,
`create_time` datetime DEFAULT NULL,
`update_time` datetime DEFAULT NULL,
`book_id` int(11) DEFAULT NULL,
`data` text,
PRIMARY KEY (`id`),
UNIQUE KEY `hash` (`hash`)
) ENGINE=InnoDB AUTO_INCREMENT=30 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `social_auth_association`
--
DROP TABLE IF EXISTS `social_auth_association`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `social_auth_association` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`server_url` varchar(255) DEFAULT NULL,
`handle` varchar(255) DEFAULT NULL,
`secret` varchar(255) DEFAULT NULL,
`issued` int(11) DEFAULT NULL,
`lifetime` int(11) DEFAULT NULL,
`assoc_type` varchar(64) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `server_url` (`server_url`,`handle`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `social_auth_code`
--
DROP TABLE IF EXISTS `social_auth_code`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `social_auth_code` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`email` varchar(200) DEFAULT NULL,
`code` varchar(32) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `code` (`code`,`email`),
KEY `ix_social_auth_code_code` (`code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `social_auth_nonce`
--
DROP TABLE IF EXISTS `social_auth_nonce`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `social_auth_nonce` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`server_url` varchar(255) DEFAULT NULL,
`timestamp` int(11) DEFAULT NULL,
`salt` varchar(40) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `server_url` (`server_url`,`timestamp`,`salt`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `social_auth_partial`
--
DROP TABLE IF EXISTS `social_auth_partial`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `social_auth_partial` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`token` varchar(32) DEFAULT NULL,
`data` text,
`next_step` int(11) DEFAULT NULL,
`backend` varchar(32) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `ix_social_auth_partial_token` (`token`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `social_auth_usersocialauth`
--
DROP TABLE IF EXISTS `social_auth_usersocialauth`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `social_auth_usersocialauth` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`provider` varchar(32) DEFAULT NULL,
`uid` varchar(255) DEFAULT NULL,
`user_id` int(11) NOT NULL,
`extra_data` text,
PRIMARY KEY (`id`),
UNIQUE KEY `provider` (`provider`,`uid`),
KEY `ix_social_auth_usersocialauth_user_id` (`user_id`),
CONSTRAINT `social_auth_usersocialauth_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `readers` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2022-04-18 11:20:12
version: "3.4"
services:
talebook:
image: talebook/talebook:latest
container_name: talebook
ports:
- "8083:80"
volumes:
- /volume1/docker/talebook:/data
- /volume1/docker/talebook/books/settings/manual.py:/data/books/settings/manual.py
- /volume1/docker/talebook/books/bootstrap.sh:/var/www/talebook/bootstrap.sh
restart: always
depends_on:
- db
- douban-api
command: /var/www/talebook/bootstrap.sh
db:
image: mysql:5.7
restart: always
environment:
- MYSQL_ROOT_PASSWORD=calibre
- MYSQL_USER=calibre
- MYSQL_PASSWORD=calibre
- MYSQL_DATABASE=calibre
volumes:
- /volume1/docker/talebook/calibre.sql:/docker-entrypoint-initdb.d/calibre.sql
- /volume1/docker/talebook/mysql:/var/lib/mysql
douban-api:
image: ghcr.io/cxfksword/douban-api-rs:latest
container_name: douban-api
ports:
- "8089:80"
restart: always
#!/usr/bin/env python3
#-*- coding: UTF-8 -*-
import os
settings = {
"user_database": 'mysql+pymysql://calibre:calibre@db:3306/calibre',
"db_engine_args": {
"echo": False,
"pool_size": 50,
"max_overflow": 50,
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment