mirror of
https://github.com/askh/pypimirror.git
synced 2026-01-26 16:49:44 +00:00
Add the .env file option 'REQUEST_TIMEOUT_SEC'
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
SERVER_IP=0.0.0.0
|
||||
SERVER_PORT=3141
|
||||
ROOT_PASSWORD=root
|
||||
REQUEST_TIMEOUT_SEC=120
|
||||
|
||||
|
||||
@@ -10,5 +10,5 @@ RUN pip3 install -U pip
|
||||
ENV PATH="/home/devpisrv/.local/bin:${PATH}"
|
||||
RUN pip install -U -r /tmp/requirements.txt
|
||||
COPY src/devpisrv.py /usr/local/bin/
|
||||
ENTRYPOINT ["devpisrv.py"]
|
||||
ENTRYPOINT ["devpisrv.py", "--overwrite-config"]
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# Конфигурационные файлы для запуска частичного зеркала PyPi используя docker-compose
|
||||
# Конфигурационные файлы для запуска частичного зеркала PyPI используя docker-compose
|
||||
|
||||
Конфигурационные файлы предназначены для развёртывания зеркала PyPi для
|
||||
локального применения, например, на случай, если доступ к серверам PyPi окажется
|
||||
Конфигурационные файлы предназначены для развёртывания зеркала PyPI для
|
||||
локального применения, например, на случай, если доступ к серверам PyPI окажется
|
||||
заблокирован. Используется [devpi](https://devpi.net/), который запускается
|
||||
используя docker-compose.
|
||||
|
||||
|
||||
@@ -2,3 +2,6 @@
|
||||
index-url=http://mirror.example.com:3141/root/pypi/+simple/
|
||||
trusted-host=mirror.example.com
|
||||
timeout=120
|
||||
|
||||
[search]
|
||||
index=http://mirror.example.com:3141/root/pypi/
|
||||
|
||||
@@ -6,14 +6,22 @@ import subprocess
|
||||
from dotenv import dotenv_values
|
||||
import yaml
|
||||
|
||||
DEFAULT_REQUEST_TIMEOUT_SEC = 10
|
||||
|
||||
arg_parser = argparse.ArgumentParser(description="The script for start devpi-server")
|
||||
arg_parser.add_argument(
|
||||
'-d',
|
||||
'--data-dir',
|
||||
type=str,
|
||||
default = '/var/local/devpisrv',
|
||||
help = 'Path to the data directory'
|
||||
default='/var/local/devpisrv',
|
||||
help='Path to the data directory'
|
||||
)
|
||||
arg_parser.add_argument(
|
||||
'-w',
|
||||
'--overwrite-config',
|
||||
action='store_true',
|
||||
default=False,
|
||||
help='Overwrite the config file if exists')
|
||||
args = arg_parser.parse_args()
|
||||
|
||||
server_dir = os.path.join(args.data_dir, "server")
|
||||
@@ -21,19 +29,29 @@ config_dir = os.path.join(args.data_dir, "config")
|
||||
env_file = os.path.join(config_dir, ".env")
|
||||
config_file = os.path.join(config_dir, "devpi.conf")
|
||||
|
||||
if not os.path.exists(config_file):
|
||||
if not(os.path.exists(args.data_dir) and os.path.isdir(args.data_dir)):
|
||||
sys.exit(f"The data directory {args.data_dir} not available.")
|
||||
for subdir_path in [server_dir, config_dir]:
|
||||
if not os.path.exists(subdir_path):
|
||||
os.mkdir(subdir_path, mode=0o770)
|
||||
|
||||
if not os.path.exists(config_file) or args.overwrite_config:
|
||||
env_config_values = dotenv_values(env_file) if os.path.isfile(env_file) else { }
|
||||
|
||||
config_data = {
|
||||
'devpi-server': {
|
||||
'serverdir': os.path.abspath(server_dir),
|
||||
'host': '0.0.0.0',
|
||||
'restrict-modify': 'root'
|
||||
'restrict-modify': 'root',
|
||||
'request-timeout': int(env_config_values.get('REQUEST_TIMEOUT_SEC') or \
|
||||
DEFAULT_REQUEST_TIMEOUT_SEC)
|
||||
}
|
||||
}
|
||||
if os.path.isfile(env_file):
|
||||
env_config_values = dotenv_values(env_file)
|
||||
if 'ROOT_PASSWORD' in env_config_values.keys():
|
||||
config_data['devpi-server']['root-passwd'] = \
|
||||
env_config_values['ROOT_PASSWORD']
|
||||
}
|
||||
|
||||
if 'ROOT_PASSWORD' in env_config_values.keys():
|
||||
config_data['devpi-server']['root-passwd'] = \
|
||||
env_config_values['ROOT_PASSWORD']
|
||||
|
||||
with open(config_file, 'w') as file:
|
||||
yaml.dump(config_data, file)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user