Browse Source

feat: local env configure

master^2
dnomd343 2 years ago
parent
commit
ea92ff82c9
  1. 23
      Basis/Constant.py
  2. 2
      Dockerfile
  3. 10
      env.yaml
  4. 2
      main.py

23
Basis/Constant.py

@ -1,6 +1,9 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import os
import yaml
# Global Options # Global Options
Version = 'dev' Version = 'dev'
@ -17,6 +20,26 @@ TestHost = 'proxyc.net'
TestSite = 'www.bing.com' TestSite = 'www.bing.com'
PathEnv = '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin' PathEnv = '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin'
# Load Env Options
yamlFile = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../env.yaml')
yamlContent = open(yamlFile, 'r', encoding = 'utf-8').read()
envOptions = yaml.load(yamlContent, Loader = yaml.FullLoader)
if 'version' in envOptions:
Version = envOptions['version']
if 'loglevel' in envOptions:
LogLevel = envOptions['loglevel']
if 'dir' in envOptions:
WorkDir = envOptions['dir']
if 'dns' in envOptions:
DnsServer = envOptions['dns']
if 'api' in envOptions:
if 'port' in envOptions['api']:
ApiPort = envOptions['api']['port']
if 'path' in envOptions['api']:
ApiPath = envOptions['api']['path']
if 'token' in envOptions['api']:
ApiToken = envOptions['api']['token']
# Shadowsocks Info # Shadowsocks Info
mbedtlsMethods = [ mbedtlsMethods = [
'aes-128-cfb128', 'aes-128-cfb128',

2
Dockerfile

@ -31,7 +31,7 @@ FROM ${PYTHON_IMG} AS wheels
WORKDIR /wheels/ WORKDIR /wheels/
RUN apk add linux-headers RUN apk add linux-headers
COPY --from=build-base /apk/ /apk/ COPY --from=build-base /apk/ /apk/
RUN /apk/build-base && pip wheel colorlog flask IPy psutil pysocks requests salsa20 RUN /apk/build-base && pip wheel colorlog flask IPy psutil pysocks pyyaml requests salsa20
COPY --from=gevent /wheels/*.whl /wheels/ COPY --from=gevent /wheels/*.whl /wheels/
COPY --from=numpy /wheels/*.whl /wheels/ COPY --from=numpy /wheels/*.whl /wheels/

10
env.yaml

@ -0,0 +1,10 @@
version: 'v0.1'
loglevel: 'INFO'
dir: '/tmp/ProxyC'
dns:
- 223.5.5.5
- 119.29.29.29
api:
port: 17839
path: '/v1'
token: 'dnomd343'

2
main.py

@ -13,7 +13,7 @@ from Basis import Constant
def mainArgParse(rawArgs: list) -> argparse.Namespace: def mainArgParse(rawArgs: list) -> argparse.Namespace:
mainParser = argparse.ArgumentParser(description = 'Start running API server') mainParser = argparse.ArgumentParser(description = 'Start running API server')
mainParser.add_argument('--log', type = str, default = Constant.LogLevel, help = 'output log level') mainParser.add_argument('--log', type = str, default = Constant.LogLevel, help = 'output log level')
mainParser.add_argument('--dns', type = str, nargs = '+', help = 'specify dns server') mainParser.add_argument('--dns', type = str, default = Constant.DnsServer, nargs = '+', help = 'specify dns server')
mainParser.add_argument('--port', type = int, default = Constant.ApiPort, help = 'port for running') mainParser.add_argument('--port', type = int, default = Constant.ApiPort, help = 'port for running')
mainParser.add_argument('--path', type = str, default = Constant.ApiPath, help = 'root path for api server') mainParser.add_argument('--path', type = str, default = Constant.ApiPath, help = 'root path for api server')
mainParser.add_argument('--token', type = str, default = Constant.ApiToken, help = 'token for api server') mainParser.add_argument('--token', type = str, default = Constant.ApiToken, help = 'token for api server')

Loading…
Cancel
Save