This repository has been archived by the owner on May 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
podmanpy-reproducer.py
72 lines (59 loc) · 1.73 KB
/
podmanpy-reproducer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from pathlib import Path
import click
import podman
from podman.errors import ImageNotFound
@click.group()
def cli():
pass
@cli.command()
def postgres_container(
image="docker.io/library/postgres",
tag='latest'
):
client = podman.from_env()
image_tag = f'{image}:{tag}'
try:
client.images.get(image_tag)
except ImageNotFound:
client.images.pull(image, tag=tag)
container = client.containers.run(
image_tag,
ports={'5432/tcp': 0},
detach=True,
auto_remove=True,
)
container = client.containers.get(container.id)
port = int(container.ports[f'5432/tcp'][0]['HostPort'])
print(f'postgres running and exposed on localhost:{port}')
container.stop(timeout=0)
CLICKHOUSE_CONFIG = str((Path(__file__).parent / 'config').absolute())
@cli.command()
def clickhouse_container(
image='docker.io/clickhouse/clickhouse-server',
tag='latest'
):
client = podman.from_env()
image_tag = f'{image}:{tag}'
try:
client.images.get(image_tag)
except ImageNotFound:
client.images.pull(image, tag=tag)
container = client.containers.run(
image_tag,
ports={'9000/tcp': 0},
detach=True,
auto_remove=True,
volumes={CLICKHOUSE_CONFIG: {'bind': '/etc/clickhouse-server/config.d/', 'mode': 'ro'}},
)
container = client.containers.get(container.id)
port = int(container.ports[f'9000/tcp'][0]['HostPort'])
print(f'clickhouse running and exposed on localhost:{port}')
container.stop(timeout=0)
@cli.command()
@click.pass_context
def all(ctx):
"Run all cases"
ctx.invoke(postgres_container)
ctx.invoke(clickhouse_container)
if __name__ == '__main__':
cli()