mirror of
https://github.com/honmashironeko/ProxyCat.git
synced 2026-10-24 16:44:26 +00:00
10 files changed
+227
-1
No files matched your search
@@ -0,0 +1,12 @@
|
||||
FROM python:3.8
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY . /app
|
||||
RUN python -m venv /venv
|
||||
|
||||
RUN /venv/bin/pip install --no-cache-dir -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple/
|
||||
|
||||
EXPOSE 1080
|
||||
|
||||
ENTRYPOINT ["/venv/bin/python", "ProxyCat-V1.9.py"]
|
||||
@@ -8,7 +8,6 @@ DEFAULT_CONFIG = {
|
||||
'password': '',
|
||||
'use_getip': False,
|
||||
'proxy_file': 'ip.txt',
|
||||
'check_proxies' : True
|
||||
}
|
||||
|
||||
def load_config(config_file='config.ini'):
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
services:
|
||||
app:
|
||||
build: .
|
||||
volumes:
|
||||
- "./config.ini:/app/config.ini"
|
||||
- "./getip.py:/app/getip.py"
|
||||
- "./ip.txt:/app/ip.txt"
|
||||
ports:
|
||||
- "1080:1080"
|
||||
@@ -0,0 +1,12 @@
|
||||
FROM python:3.8
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY . /app
|
||||
RUN python -m venv /venv
|
||||
|
||||
RUN /venv/bin/pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
EXPOSE 1080
|
||||
|
||||
ENTRYPOINT ["/venv/bin/python", "ProxyCat-V1.9.py"]
|
||||
@@ -0,0 +1,9 @@
|
||||
services:
|
||||
app:
|
||||
build: .
|
||||
volumes:
|
||||
- "./config.ini:/app/config.ini"
|
||||
- "./getip.py:/app/getip.py"
|
||||
- "./ip.txt:/app/ip.txt"
|
||||
ports:
|
||||
- "1080:1080"
|
||||
@@ -0,0 +1,20 @@
|
||||
<p align="center">
|
||||
<a href="/docker/README_EN.md">English</a>
|
||||
·
|
||||
<a href="/docker/README.md">简体中文</a>
|
||||
</p>
|
||||
|
||||
## 为什么要使用脚本生成dockerfile
|
||||
|
||||
本项目分为多种语言,不同语言内容可能存在差异,为了减少维护成本 ,使用脚本生成dockerfile,方便后续维护。
|
||||
|
||||
## 使用方法
|
||||
|
||||
*生成dockerfile和docker-compose.yml*
|
||||
|
||||
``` shell
|
||||
cd docker
|
||||
python docker_tools.py -l CN
|
||||
```
|
||||
|
||||
> 执行结束后会生成命令,按照指引运行即可
|
||||
@@ -0,0 +1,22 @@
|
||||
<p align="center">
|
||||
<a href="/docker/README_EN.md">English</a>
|
||||
·
|
||||
<a href="/docker/README.md">简体中文</a>
|
||||
</p>
|
||||
|
||||
Warning: this document uses machine translation
|
||||
|
||||
## Why Use a Script to Generate Dockerfiles
|
||||
|
||||
This project supports multiple languages, and the content may vary between languages. To reduce maintenance costs, scripts are used to generate Dockerfiles, making it easier for future updates.
|
||||
|
||||
## Usage
|
||||
|
||||
*Generate Dockerfile and docker-compose.yml*
|
||||
|
||||
```shell
|
||||
cd docker
|
||||
python docker_tools.py -l CN
|
||||
```
|
||||
|
||||
> After execution, commands will be generated. Follow the instructions to run them.
|
||||
@@ -0,0 +1,122 @@
|
||||
import os
|
||||
import logging
|
||||
from typing import Dict
|
||||
|
||||
# todo: 优化docker-compose
|
||||
|
||||
# 项目根目录
|
||||
PROJECT_ROOT: str = os.path.realpath('../')
|
||||
# 模板目录
|
||||
TEMPLATE_PATH: str = os.path.join(PROJECT_ROOT, 'docker/template')
|
||||
# venv bin 路径
|
||||
VENV_BIN_PATH = '/venv/bin'
|
||||
# 语言
|
||||
language: str
|
||||
# 当前语言配置
|
||||
current_config: 'DockerConfig'
|
||||
|
||||
|
||||
class DockerConfig:
|
||||
def __init__(self, source_path, run_file='ProxyCat-V1.9.py',
|
||||
pip_install_cmd=f'{VENV_BIN_PATH}/pip install --no-cache-dir -r requirements.txt'):
|
||||
# 源代码路径,因每个语言项目目录不同,所以需要传入项目根目录
|
||||
self.source_path = os.path.join(PROJECT_ROOT, source_path)
|
||||
# pip install命令
|
||||
self.pip_install_cmd = pip_install_cmd
|
||||
# 启动文件
|
||||
self.run_file = run_file
|
||||
|
||||
def get_template_fields4dockerfile(self):
|
||||
return {
|
||||
'run_file': self.run_file,
|
||||
'pip_install_cmd': self.pip_install_cmd
|
||||
}
|
||||
|
||||
def get_template_fields4docker_compose(self):
|
||||
return {
|
||||
'none': None
|
||||
}
|
||||
|
||||
|
||||
configs: Dict[str, DockerConfig] = {
|
||||
'CN': DockerConfig(source_path='ProxyCat-CN',
|
||||
# 符合中国宝宝体质
|
||||
pip_install_cmd=f'{VENV_BIN_PATH}/pip install --no-cache-dir -r requirements.txt' \
|
||||
' -i https://pypi.tuna.tsinghua.edu.cn/simple/'),
|
||||
'EN': DockerConfig(source_path='ProxyCat-EN')
|
||||
}
|
||||
|
||||
|
||||
def get_args():
|
||||
import argparse
|
||||
parser = argparse.ArgumentParser(description='a generate docker compose file tool')
|
||||
parser.add_argument('-l', '--language', default='CN', help="LANGUAGE(support: CN, EN),default: CN")
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def get_template(template_name: str) -> str:
|
||||
with open(os.path.join(TEMPLATE_PATH, template_name), 'r') as f:
|
||||
return f.read()
|
||||
|
||||
|
||||
def write_file(file_name, content: str):
|
||||
def w_f(p):
|
||||
with open(p, 'w') as f:
|
||||
f.write(content)
|
||||
logging.info(f"write {p} success")
|
||||
|
||||
# 文件路径
|
||||
f_p = os.path.join(current_config.source_path, file_name)
|
||||
# 目录不存在报错
|
||||
if not os.path.exists(os.path.dirname(f_p)):
|
||||
logging.error(f"{os.path.dirname(f_p)} dir is not exists")
|
||||
if os.path.exists(f_p):
|
||||
logging.warning(f"{f_p} is exists")
|
||||
confirm = input(f'{f_p} is exists, overwrite?(Y/n)')
|
||||
if confirm.strip().lower() == 'y' or confirm.strip() == '':
|
||||
w_f(f_p)
|
||||
else:
|
||||
logging.info(f"{f_p} is not overwrite")
|
||||
else:
|
||||
w_f(f_p)
|
||||
|
||||
|
||||
def generate_docker_compose():
|
||||
t = get_template('docker-compose_template')
|
||||
dockerfile_content = t.format(
|
||||
**current_config.get_template_fields4docker_compose()
|
||||
)
|
||||
write_file('docker-compose.yml', dockerfile_content)
|
||||
|
||||
|
||||
def generate_docker_file():
|
||||
t = get_template('Dockerfile_template')
|
||||
dockerfile_content = t.format(
|
||||
**current_config.get_template_fields4dockerfile()
|
||||
)
|
||||
write_file('Dockerfile', dockerfile_content)
|
||||
|
||||
|
||||
def get_test_cmd():
|
||||
return \
|
||||
f'docker: \n' + \
|
||||
f'\tcd {current_config.source_path} \n' + \
|
||||
f'\tdocker build -t proxycat:latest . \n' + \
|
||||
f'\tdocker run -it proxycat:latest -h\n' + \
|
||||
f'docker-compose\n' + \
|
||||
f'\tcd {current_config.source_path} \n' + \
|
||||
f'\tdocker-compose up -d'
|
||||
|
||||
|
||||
def init(args):
|
||||
global language, current_config
|
||||
language = args.language.upper()
|
||||
current_config = configs.get(language)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
the_args = get_args()
|
||||
init(the_args)
|
||||
generate_docker_file()
|
||||
generate_docker_compose()
|
||||
print(get_test_cmd())
|
||||
@@ -0,0 +1,12 @@
|
||||
FROM python:3.8
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY . /app
|
||||
RUN python -m venv /venv
|
||||
|
||||
RUN {pip_install_cmd}
|
||||
|
||||
EXPOSE 1080
|
||||
|
||||
ENTRYPOINT ["/venv/bin/python", "{run_file}"]
|
||||
@@ -0,0 +1,9 @@
|
||||
services:
|
||||
app:
|
||||
build: .
|
||||
volumes:
|
||||
- "./config.ini:/app/config.ini"
|
||||
- "./getip.py:/app/getip.py"
|
||||
- "./ip.txt:/app/ip.txt"
|
||||
ports:
|
||||
- "1080:1080"
|
||||
Reference in new issue
Block a user