-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathci.py
53 lines (45 loc) · 1.6 KB
/
ci.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
import sys
import os
import logging
import anyio
import dagger
PORT = int(os.environ.get("PORT", 2222))
logging.getLogger().setLevel(level=os.getenv('LOGLEVEL', "INFO").upper())
async def test():
roles = ["dagger", "helm", "dbeaver", "sonarqube tasks_from=scanner"]
async with dagger.Connection(dagger.Config(log_output=sys.stderr)) as client:
context = client.host().directory(".")
ansible_image = client.container().build(
context, "roles/ansible/files/image/alpine_ansible/Dockerfile"
)
host_image = client.container().build(
context, "roles/ansible/files/image/ubuntu_host/Dockerfile"
)
host = (
host_image.with_env_variable("PORT", str(PORT))
.with_exposed_port(PORT)
.with_exec([])
)
for role in roles:
result = (
ansible_image.with_service_binding("host", host)
.with_env_variable("ANSIBLE_HOST_KEY_CHECKING", "False")
.with_exec(
[
"ansible",
"ubuntu_host",
"-m",
"include_role",
"-a",
f"name={role}",
"-e",
f"ansible_port={PORT}",
"-i",
"roles/ansible/files/image/alpine_ansible/inventory",
]
)
)
await result.exit_code()
logging.info(f"{role=} success")
if __name__ == "__main__":
anyio.run(test)