随着容器,Kuberenetes,12 Factor等的增加,在开发,分期和生产中复制相同的环境变得更加容易.但是,域名约定似乎没有共同标准.
据我所知,有两种方法:
*.dev.foobar.tld*.staging.foobar.tld*.foobar.tld*.foobar-dev.tld*.foobar-staging.tld*.foobar.tld我可以用两种方法看到起伏,但我很好奇普通的实践是什么.
作为附注,Cloudflare不会为您发放子子域的证书(例如*.stage.foobar.tld).
我正在为docker-py的模块编写测试,但我似乎无法让测试正常工作。
我正在测试的功能如下所示:
def parse_env_file(env_file):
"""
Reads a line-separated environment file.
The format of each line should be "key=value".
"""
environment = []
if os.path.isfile(env_file):
with open(env_file, 'r') as f:
# We can't use f.readlines() here as it's not implemented in Mock
for line in f.read().split('\n'):
parse_line = line.strip().split('=')
if len(parse_line) == 2 and line[0] != '#':
k = parse_line[0]
v = parse_line[1]
environment.append('{0}={1}'.format(k, v))
return environment
Run Code Online (Sandbox Code Playgroud)
然后测试看起来像这样:
def test_parse_env_file_proper(self):
with mock.patch('os.path.isfile', return_value=True):
mock_env_file = 'USER=jdoe\nPASS=secret'
with mock.patch('{}.open'.format(__name__), mock.mock_open(read_data=mock_env_file)): …Run Code Online (Sandbox Code Playgroud)