Skip to content

Commit 147dbcb

Browse files
committed
🐛: 修复部署脚本
1 parent 3f42574 commit 147dbcb

9 files changed

Lines changed: 177 additions & 78 deletions

File tree

Dockerfile

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,39 @@
1+
# Use the official Ubuntu base image
12
FROM ubuntu:jammy
2-
MAINTAINER jwstar
3+
LABEL maintainer="Evil0ctal"
4+
5+
# Set non-interactive frontend (useful for Docker builds)
36
ENV DEBIAN_FRONTEND=noninteractive
47

5-
RUN apt-get -y update \
6-
&& apt-get install -y --no-install-recommends \
7-
python3.11 python3-pip python3.11-dev
8+
# Update the package list and install Python and pip
9+
RUN apt-get update && apt-get install -y --no-install-recommends \
10+
python3.11 \
11+
python3-pip \
12+
python3.11-dev \
13+
&& apt-get clean \
14+
&& rm -rf /var/lib/apt/lists/*
815

9-
# Using Aliyun pipy mirror
10-
RUN pip3 install -i https://mirrors.aliyun.com/pypi/simple/ -U pip
11-
RUN pip3 config set global.index-url https://mirrors.aliyun.com/pypi/simple/
16+
# Set a working directory
17+
WORKDIR /app
1218

19+
# Copy the application source code to the container
1320
COPY . /app
14-
WORKDIR /app
15-
RUN pip3 --no-cache-dir install --user -r /app/requirements.txt
1621

22+
# Install virtualenv
23+
RUN pip3 install -i https://mirrors.aliyun.com/pypi/simple/ -U pip \
24+
&& pip3 config set global.index-url https://mirrors.aliyun.com/pypi/simple/ \
25+
&& pip3 install virtualenv
26+
27+
# Create and activate virtual environment
28+
# Using a virtual environment prevents conflicts between the app's dependencies and the system
29+
RUN python3.11 -m virtualenv venv
30+
ENV PATH="/app/venv/bin:$PATH"
31+
32+
# Install dependencies in the virtual environment
33+
RUN pip install --no-cache-dir -r requirements.txt
1734

18-
RUN chmod +x start.sh && \
19-
apt-get autoremove -y \
20-
&& apt-get remove -y python3-pip
35+
# Make the start script executable
36+
RUN chmod +x start.sh
2137

38+
# Command to run on container start
2239
CMD ["./start.sh"]

README.md

Lines changed: 75 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ https://www.tiktok.com/@evil0ctal/video/7156033831819037994
260260

261261
> 💡提示:最好将本项目部署至美国地区的服务器,否则可能会出现奇怪的BUG。
262262
263-
推荐大家使用[Digitalocean](https://www.digitalocean.com/)的服务器,主要是因为免费
263+
推荐大家使用[Digitalocean](https://www.digitalocean.com/)的服务器,因为可以白嫖
264264

265265
使用我的邀请链接注册,你可以获得$200的credit,当你在上面消费$25时,我也可以获得$25的奖励。
266266

@@ -270,6 +270,8 @@ https://www.tiktok.com/@evil0ctal/video/7156033831819037994
270270

271271
> 使用脚本一键部署本项目
272272
273+
- 本项目提供了一键部署脚本,可以在服务器上快速部署本项目。
274+
- 脚本是在Ubuntu 20.04 LTS上测试的,其他系统可能会有问题,如果有问题请自行解决。
273275
- 使用wget命令下载[install.sh](https://raw.githubusercontent.com/Evil0ctal/Douyin_TikTok_Download_API/main/bash/install.sh)至服务器并运行
274276

275277
```
@@ -278,59 +280,102 @@ wget -O install.sh https://raw.githubusercontent.com/Evil0ctal/Douyin_TikTok_Dow
278280

279281
> 开启/停止服务
280282
281-
- `systemctl start/stop Douyin_TikTok_Download_API.service`
283+
- 使用以下命令来控制服务的运行或停止:
284+
- `sudo systemctl start Douyin_TikTok_Download_API.service`
285+
- `sudo systemctl stop Douyin_TikTok_Download_API.service`
282286

283287
> 开启/关闭开机自动运行
284288
285-
- `systemctl enable/disable Douyin_TikTok_Download_API.service`
289+
- 使用以下命令来设置服务开机自动运行或取消开机自动运行:
290+
- `sudo systemctl enable Douyin_TikTok_Download_API.service`
291+
- `sudo systemctl disable Douyin_TikTok_Download_API.service`
286292

287293
> 更新项目
288294
295+
- 项目更新时,确保更新脚本在虚拟环境中执行,更新所有依赖。进入项目bash目录并运行update.sh:
289296
- `cd /www/wwwroot/Douyin_TikTok_Download_API/bash && sudo bash update.sh`
290297

291298
## 💽部署(方式二 Docker)
292299

293-
> 💡Docker Image repo: [Docker Hub](https://hub.docker.com/repository/docker/evil0ctal/douyin_tiktok_download_api)
300+
> 💡提示:Docker部署是最简单的部署方式,适合不熟悉Linux的用户,这种方法适合保证环境一致性、隔离性和快速设置。
301+
> 请使用能正常访问Douyin或TikTok的服务器,否则可能会出现奇怪的BUG。
294302
295-
- 安装docker
303+
### 准备工作
296304

297-
```yaml
298-
curl -fsSL get.docker.com -o get-docker.sh&&sh get-docker.sh &&systemctl enable docker&&systemctl start docker
299-
```
305+
开始之前,请确保您的系统已安装Docker。如果还未安装Docker,可以从[Docker官方网站](https://www.docker.com/products/docker-desktop/)下载并安装。
306+
307+
### 步骤1:拉取Docker镜像
300308

301-
- 留下config.ini和docker-compose.yml文件即可
302-
- 运行命令,让容器在后台运行
309+
首先,从Docker Hub拉取最新的Douyin_TikTok_Download_API镜像。
303310

304-
```yaml
305-
docker-compose up -d
311+
```bash
312+
docker pull evil0ctal/douyin_tiktok_download_api:latest
306313
```
307314

308-
- 查看容器日志
315+
如果需要,可以替换`latest`为你需要部署的具体版本标签。
316+
317+
### 步骤2:运行Docker容器
309318

310-
```yaml
311-
docker logs -f douyin_tiktok_download_api
319+
拉取镜像后,您可以从此镜像启动一个容器。以下是运行容器的命令,包括基本配置:
320+
321+
```bash
322+
docker run -d --name douyin_tiktok_api -p 80:80 evil0ctal/douyin_tiktok_download_api
312323
```
313324

314-
- 删除容器
325+
这个命令的每个部分作用如下:
326+
327+
* `-d`:在后台运行容器(分离模式)。
328+
* `--name douyin_tiktok_api `:将容器命名为`douyin_tiktok_api `
329+
* `-p 80:80`:将主机上的80端口映射到容器的80端口。根据您的配置或端口可用性调整端口号。
330+
* `evil0ctal/douyin_tiktok_download_api`:要使用的Docker镜像名称。
315331

316-
```yaml
317-
docker rm -f douyin_tiktok_download_api
332+
### 步骤3:验证容器是否运行
333+
334+
使用以下命令检查您的容器是否正在运行:
335+
336+
```bash
337+
docker ps
318338
```
319339

320-
- 更新
340+
这将列出所有活动容器。查找`douyin_tiktok_api `以确认其正常运行。
341+
342+
### 步骤4:访问应用程序
343+
344+
容器运行后,您应该能够通过`http://localhost`或API客户端访问Douyin_TikTok_Download_API。如果配置了不同的端口或从远程位置访问,请调整URL。
345+
346+
### 可选:自定义Docker命令
321347

322-
```yaml
323-
docker-compose pull && docker-compose down && docker-compose up -d
348+
对于更高级的部署,您可能希望自定义Docker命令,包括环境变量、持久数据的卷挂载或其他Docker参数。这是一个示例:
349+
350+
```bash
351+
docker run -d --name douyin_tiktok_api -p 80:80 \
352+
-v /path/to/your/data:/data \
353+
-e MY_ENV_VAR=my_value \
354+
evil0ctal/douyin_tiktok_download_api
324355
```
325356

326-
## ❤️ 贡献者
357+
* `-v /path/to/your/data:/data`:将主机上的`/path/to/your/data`目录挂载到容器的`/data`目录,用于持久化或共享数据。
358+
* `-e MY_ENV_VAR=my_value`:在容器内设置环境变量`MY_ENV_VAR`,其值为`my_value`
359+
360+
### 配置文件修改
361+
362+
项目的大部分配置可以在以下几个目录中的`config.yaml`文件进行修改:
363+
364+
* `/crawlers/douyin/web/config.yaml`
365+
* `/crawlers/tiktok/web/config.yaml`
366+
* `/crawlers/tiktok/app/config.yaml`
367+
368+
### 步骤5:停止并移除容器
327369

328-
[![](https://github.com/Evil0ctal.png?size=50)](https://github.com/Evil0ctal)
329-
[![](https://github.com/jw-star.png?size=50)](https://github.com/jw-star)
330-
[![](https://github.com/Jeffrey-deng.png?size=50)](https://github.com/Jeffrey-deng)
331-
[![](https://github.com/chris-ss.png?size=50)](https://github.com/chris-ss)
332-
[![](https://github.com/weixuan00.png?size=50)](https://github.com/weixuan00)
333-
[![](https://github.com/Tairraos.png?size=50)](https://github.com/Tairraos)
370+
需要停止和移除容器时,使用以下命令:
371+
372+
```bash
373+
# Stop
374+
docker stop douyin_tiktok_api
375+
376+
# Remove
377+
docker rm douyin_tiktok_api
378+
```
334379

335380
## 📸截图
336381

@@ -372,8 +417,8 @@ Web main interface:
372417

373418
[![Star History Chart](https://api.star-history.com/svg?repos=Evil0ctal/Douyin_TikTok_Download_API&type=Timeline)](https://star-history.com/#Evil0ctal/Douyin_TikTok_Download_API&Timeline)
374419

375-
[MIT License](https://github.com/Evil0ctal/Douyin_TikTok_Download_API/blob/Stable/LICENSE)
420+
[Apache-2.0 license](https://github.com/Evil0ctal/Douyin_TikTok_Download_API/blob/Stable/LICENSE)
376421

377422
> Start: 2021/11/06
423+
378424
> GitHub: [@Evil0ctal](https://github.com/Evil0ctal)
379-
> Contact: Evil0ctal1985@gmail.com

bash/install.sh

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,52 @@
11
#!/bin/bash
22

3-
echo 'installing Git...'
3+
# Set script to exit on any errors.
4+
set -e
45

5-
apt-get install git
6+
echo 'Updating package lists...'
7+
sudo apt-get update
68

7-
echo 'installing Python3...'
9+
echo 'Installing Git...'
10+
sudo apt-get install -y git
811

9-
apt install python3
12+
echo 'Installing Python3...'
13+
sudo apt install -y python3
1014

11-
echo 'installing PIP3...'
15+
echo 'Installing PIP3...'
16+
sudo apt install -y python3-pip
1217

13-
apt install python3-pip
18+
echo 'Installing Virtualenv...'
19+
sudo pip3 install virtualenv
1420

1521
echo 'Creating path: /www/wwwroot'
16-
17-
mkdir -p /www/wwwroot
22+
sudo mkdir -p /www/wwwroot
1823

1924
cd /www/wwwroot || exit
2025

2126
echo 'Cloning Douyin_TikTok_Download_API.git from Github!'
22-
23-
git clone https://github.com/Evil0ctal/Douyin_TikTok_Download_API.git
27+
sudo git clone https://github.com/Evil0ctal/Douyin_TikTok_Download_API.git
2428

2529
cd Douyin_TikTok_Download_API/ || exit
2630

27-
sudo pip install -r requirements.txt --break-system-packages
31+
echo 'Creating a virtual environment'
32+
virtualenv venv
2833

29-
echo 'Add Douyin_TikTok_Download_API to system service'
34+
echo 'Activating the virtual environment'
35+
source venv/bin/activate
3036

31-
cp /www/wwwroot/Douyin_TikTok_Download_API/daemon/* /etc/systemd/system/
37+
echo 'Installing dependencies from requirements.txt'
38+
pip install -r requirements.txt
3239

33-
systemctl enable Douyin_TikTok_Download_API.service
40+
echo 'Deactivating the virtual environment'
41+
deactivate
3442

35-
echo 'Starting Douyin_TikTok_Download_API service'
43+
echo 'Adding Douyin_TikTok_Download_API to system service'
44+
sudo cp daemon/* /etc/systemd/system/
3645

37-
systemctl start Douyin_TikTok_Download_API.service
46+
echo 'Enabling Douyin_TikTok_Download_API service'
47+
sudo systemctl enable Douyin_TikTok_Download_API.service
48+
49+
echo 'Starting Douyin_TikTok_Download_API service'
50+
sudo systemctl start Douyin_TikTok_Download_API.service
3851

52+
echo 'Douyin_TikTok_Download_API installation complete!'

bash/update.sh

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,31 @@
11
#!/bin/bash
22

3+
# Ask for confirmation to proceed with the update
34
read -r -p "Do you want to update Douyin_TikTok_Download_API? [y/n] " input
4-
case $input in
5-
[yY])
6-
cd ..
7-
git pull
8-
echo "Restarting Douyin_TikTok_Download_API service"
9-
systemctl restart Douyin_TikTok_Download_API.service
10-
echo "Successfully restarted all services!"
11-
;;
12-
[nN]| *)
13-
echo "Exiting..."
14-
exit 1
15-
;;
16-
esac
5+
case $input in
6+
[yY])
7+
# Navigate to the project directory or exit if it fails
8+
cd /www/wwwroot/Douyin_TikTok_Download_API || { echo "The directory does not exist."; exit 1; }
9+
10+
# Pull the latest changes from the repository
11+
git pull
12+
13+
# Activate the virtual environment
14+
source venv/bin/activate
15+
16+
# Optionally, update Python dependencies
17+
pip install -r requirements.txt
18+
19+
# Deactivate the virtual environment
20+
deactivate
21+
22+
# Restart the service to apply changes
23+
echo "Restarting Douyin_TikTok_Download_API service"
24+
sudo systemctl restart Douyin_TikTok_Download_API.service
25+
echo "Successfully restarted all services!"
26+
;;
27+
[nN]|*)
28+
echo "Exiting..."
29+
exit 1
30+
;;
31+
esac

config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Web:
2424
# API
2525
API:
2626
# Network Configuration
27-
Host_IP: 0.0.0.0 # use 127.0.0.1 for local access only | 仅本地访问请使用
27+
Host_IP: 0.0.0.0 # default IP | 默认IP
2828
Host_Port: 80 # default port is 80 | 默认端口为80
2929
Docs_URL: /docs # API documentation URL | API文档URL
3030
Redoc_URL: /redoc # API documentation URL | API文档URL

daemon/Douyin_TikTok_Download_API.service

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
[Unit]
2-
Description=Douyin_TikTok_Download_API deamon
3-
After=rc-local.service
2+
Description=Douyin_TikTok_Download_API daemon
3+
After=network.target
44

55
[Service]
66
Type=simple
77
User=root
88
Group=root
99
WorkingDirectory=/www/wwwroot/Douyin_TikTok_Download_API
10-
ExecStart=python3 start.py
10+
ExecStart=/www/wwwroot/Douyin_TikTok_Download_API/venv/bin/python3 start.py
1111
Restart=always
1212

1313
[Install]

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ services: # 定义服务列表
66
network_mode: host # 使用主机网络模式
77
container_name: douyin_tiktok_download_api # 容器名称
88
restart: always # 容器退出后总是重启
9-
volumes: # 挂载卷配置
9+
volumes: # 挂载卷配置
1010
- ./douyin_tiktok_download_api/douyin_web/config.yaml:/crawlers/douyin/web/config.yaml
1111
- ./douyin_tiktok_download_api/tiktok_web/config.yaml:/crawlers/tiktok/web/config.yaml
1212
- ./douyin_tiktok_download_api/tiktok_app/config.yaml:/crawlers/tiktok/app/config.yaml

start.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
# ==============================================================================
3535

3636

37-
from app.main import app, Host_IP, Host_Port
37+
from app.main import Host_IP, Host_Port
3838
import uvicorn
3939

4040
if __name__ == '__main__':

start.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
#!/bin/sh
22

3-
python3 start.py
3+
# Activating the virtual environment
4+
# shellcheck disable=SC2039
5+
source /www/wwwroot/Douyin_TikTok_Download_API/venv/bin/activate
6+
7+
# Starting the Python application
8+
python start.py
9+
10+
# Deactivating the virtual environment (optional, since the script is ending)
11+
deactivate

0 commit comments

Comments
 (0)