From 1158907a6f5d14c36d942d1d3a8cb5a1a47b3d2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A5=9E=E6=A5=BD=E5=9D=82=C2=B7=E5=96=B5?= Date: Tue, 1 Dec 2020 11:03:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0docker=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 49 +++++++++++++++++++++++++++++++++++++++++++++ README.md | 10 ++++----- docker-compose.yaml | 20 ++++++++++++++++++ entrypoint.sh | 27 +++++++++++++++++++++++++ scripts/jd.py | 2 +- scripts/qq.py | 2 +- 6 files changed, 103 insertions(+), 7 deletions(-) create mode 100644 Dockerfile create mode 100644 docker-compose.yaml create mode 100644 entrypoint.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..06fdb26 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,49 @@ +FROM node:15-buster + +RUN apt update && apt install software-properties-common -y && apt clean && rm -rf /var/lib/apt/lists/* + +RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys CC86BB64 + +RUN add-apt-repository "deb http://ppa.launchpad.net/rmescandon/yq/ubuntu focal main" -y + +RUN apt update && apt install sqlite python git moreutils yq -y && apt clean && rm -rf /var/lib/apt/lists/* + +WORKDIR /tmp + +ADD https://golang.org/dl/go1.15.5.linux-amd64.tar.gz /tmp/go1.15.5.linux-amd64.tar.gz + +RUN tar -C /usr/local -xzf go1.15.5.linux-amd64.tar.gz && echo 'export PATH=$PATH:/usr/local/go/bin' >> /etc/profile + +WORKDIR /opt + +RUN git clone https://github.com/kallydev/privacy + +WORKDIR /opt/privacy/server + +RUN export PATH=$PATH:/usr/local/go/bin && go build -o app main/main.go + +WORKDIR /opt/privacy/website + +RUN yarn install && yarn build + +ADD entrypoint.sh /opt/privacy/entrypoint.sh + +RUN chmod +x /opt/privacy/entrypoint.sh + +VOLUME [ "/opt/privacy/database", "/opt/privacy/source" ] + +ENV qq=true +ENV jd=true +ENV sf=false +ENV wb=false + +ENV host=0.0.0.0 +ENV port=80 + +ENV mask=true + +EXPOSE 80 + +WORKDIR /opt/privacy + +ENTRYPOINT [ "/opt/privacy/entrypoint.sh" ] diff --git a/README.md b/README.md index 95e7887..873168e 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ 在项目文件夹根目录下创建并进入 database 文件夹,创建数据库。 ```bash -mkdir database & cd database +mkdir database && cd database sqlite3 database.db ``` @@ -65,11 +65,11 @@ CREATE TABLE sf 2. 导入 QQ 库 -把 `6.9更新总库.txt` 文件放到项目根目录下,然后执行 `python scripts/qq.py`。 +把 `6.9更新总库.txt` 文件放到项目根目录下的`source`目录,然后执行 `python scripts/qq.py`。 3. 导入京东库 -把 `www_jd_com_12g.txt` 文件放到项目根目录下,然后执行 `python scripts/jd.py`。 +把 `www_jd_com_12g.txt` 文件放到项目根目录下的`source`目录,然后执行 `python scripts/jd.py`。 - 创建索引 @@ -100,8 +100,8 @@ npm install -g yarn 2. 安装 Golang ```bash -sudo apt install -y snap -sudo snap install golang --classic +sudo apt install -y snapd +sudo snap install go --classic ``` 3. 下载源代码 diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..be03f9c --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,20 @@ +version: "3.3" + +services: + server: + build: . + image: privacy + network_mode: bridge + volumes: + - ./database:/opt/privacy/database + - ./source:/opt/privacy/source + environment: + - qq=true + - jd=true + - sf=false + - wb=false + - host=0.0.0.0 + - port=80 + - mask=true + ports: + - 80:80 diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..2f964ae --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +# 设置环境变量 +yq w config.yaml database.tables.qq $qq | yq w - database.tables.jd $jd | yq w - database.tables.sf $sf | yq w - database.tables.wb $wb | yq w - http.host $host | yq w - http.port $port | yq w - mask $mask | sponge config.yaml + +# 如果不存在数据库,创建 +if [[ ! -f database/database.db ]];then + mkdir -p database && sqlite3 database/database.db < scripts/database/create_database.sql + if [[ -f source/6.9更新总库.txt ]];then python scripts/qq.py;fi + if [[ -f source/www_jd_com_12g.txt ]];then python scripts/jd.py;fi + sqlite3 database/database.db < scripts/database/create_index.sql +fi + +# 如果需要重新导入qq +if [[ -f database/.reimportqq ]];then + if [[ -f source/6.9更新总库.txt ]];then python scripts/qq.py;fi + rm database/.reimportqq +fi + +# 如果需要重新导入jd +if [[ -f database/.reimportjd ]];then + if [[ -f source/www_jd_com_12g.txt ]];then python scripts/jd.py;fi + rm database/.reimportjd +fi + +# 启动服务器 +cd server && ./app diff --git a/scripts/jd.py b/scripts/jd.py index 59a3b15..74aaf8e 100644 --- a/scripts/jd.py +++ b/scripts/jd.py @@ -107,5 +107,5 @@ class Converter(object): if __name__ == '__main__': - converter = Converter("database/database.db", "www_jd_com_12g.txt") + converter = Converter("database/database.db", "source/www_jd_com_12g.txt") converter.start() diff --git a/scripts/qq.py b/scripts/qq.py index 2c152f8..63aa8e8 100644 --- a/scripts/qq.py +++ b/scripts/qq.py @@ -99,5 +99,5 @@ class Scanner: if __name__ == '__main__': - scanner = Scanner("database/database.db", "6.9更新总库.txt") + scanner = Scanner("database/database.db", "source/6.9更新总库.txt") scanner.start()