mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Add container tool
This commit is contained in:
parent
5f941f75bb
commit
4c8ca3062c
3 changed files with 121 additions and 0 deletions
14
.github/workflows/ssh-debug.yml
vendored
14
.github/workflows/ssh-debug.yml
vendored
|
@ -30,6 +30,20 @@ jobs:
|
||||||
environment: ci
|
environment: ci
|
||||||
steps:
|
steps:
|
||||||
|
|
||||||
|
- name: Set up Python 3.10
|
||||||
|
uses: actions/setup-python@v5
|
||||||
|
with:
|
||||||
|
python-version: 3.10
|
||||||
|
|
||||||
|
- name: Setup Python Tools Scripts
|
||||||
|
uses: ./.github/actions/setup-python-tools-scripts
|
||||||
|
|
||||||
|
- name: Install Nox
|
||||||
|
run: |
|
||||||
|
python3 -m pip install 'nox==2022.8.7'
|
||||||
|
env:
|
||||||
|
PIP_INDEX_URL: https://pypi.org/simple
|
||||||
|
|
||||||
- name: Checkout Source Code
|
- name: Checkout Source Code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@ RELEASE_VENV_CONFIG = VirtualEnvPipConfig(
|
||||||
ptscripts.set_default_config(DEFAULT_REQS_CONFIG)
|
ptscripts.set_default_config(DEFAULT_REQS_CONFIG)
|
||||||
ptscripts.register_tools_module("tools.changelog")
|
ptscripts.register_tools_module("tools.changelog")
|
||||||
ptscripts.register_tools_module("tools.ci")
|
ptscripts.register_tools_module("tools.ci")
|
||||||
|
ptscripts.register_tools_module("tools.container")
|
||||||
ptscripts.register_tools_module("tools.docs")
|
ptscripts.register_tools_module("tools.docs")
|
||||||
ptscripts.register_tools_module("tools.gh")
|
ptscripts.register_tools_module("tools.gh")
|
||||||
ptscripts.register_tools_module("tools.pkg")
|
ptscripts.register_tools_module("tools.pkg")
|
||||||
|
|
106
tools/container.py
Normal file
106
tools/container.py
Normal file
|
@ -0,0 +1,106 @@
|
||||||
|
import os
|
||||||
|
|
||||||
|
from ptscripts import Context, command_group
|
||||||
|
|
||||||
|
cmd = command_group(name="container", help="Container Commands", description=__doc__)
|
||||||
|
|
||||||
|
|
||||||
|
def has_network(ctx, name):
|
||||||
|
p = ctx.run("docker", "network", "ls", capture=True)
|
||||||
|
return name in p.stdout.decode()
|
||||||
|
|
||||||
|
|
||||||
|
def create_network(ctx, name):
|
||||||
|
p = ctx.run(
|
||||||
|
"docker",
|
||||||
|
"network",
|
||||||
|
"create",
|
||||||
|
"-o",
|
||||||
|
"com.docker.network.driver.mtu=1500",
|
||||||
|
"--ipv6",
|
||||||
|
"--subnet",
|
||||||
|
"2001:db8::/64",
|
||||||
|
name,
|
||||||
|
)
|
||||||
|
if p.returncode != 0:
|
||||||
|
raise RuntimeError(f"docker network create returned {p.returncode}")
|
||||||
|
|
||||||
|
|
||||||
|
@cmd.command(
|
||||||
|
name="create",
|
||||||
|
arguments={
|
||||||
|
"image": {"help": "Name the container image to use."},
|
||||||
|
"name": {"help": "Name the container being created.", "default": ""},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
def create(ctx: Context, image: str, name: str = ""):
|
||||||
|
onci = "GITHUB_WORKFLOW" in os.environ
|
||||||
|
workdir = "/salt"
|
||||||
|
home = "/root"
|
||||||
|
network = "ip6net"
|
||||||
|
if not has_network(ctx, network):
|
||||||
|
ctx.info(f"Creating docker network: {network}")
|
||||||
|
create_network(ctx, network)
|
||||||
|
if onci:
|
||||||
|
workdir = "/__w/salt/salt"
|
||||||
|
home = "/github/home"
|
||||||
|
env = {
|
||||||
|
"HOME": home,
|
||||||
|
"SKIP_REQUIREMENTS_INSTALL": "1",
|
||||||
|
"PRINT_TEST_SELECTION": "0",
|
||||||
|
"PRINT_TEST_PLAN_ONLY": "0",
|
||||||
|
"PRINT_SYSTEM_INFO": "0",
|
||||||
|
"RERUN_FEAILURES": "0",
|
||||||
|
"SKIP_INITIAL_ONEDIR_FAILURES": "1",
|
||||||
|
"SKIP_INITIAL_GH_ACTIONS_FAILURES": "1",
|
||||||
|
"RAISE_DEPRECATIONS_RUNTIME_ERRORS": "1",
|
||||||
|
"LANG": "en_US.UTF-8",
|
||||||
|
"SHELL": "/bin/bash",
|
||||||
|
}
|
||||||
|
for var in [
|
||||||
|
"PIP_INDEX_URL",
|
||||||
|
"PIP_EXTRA_INDEX_URL",
|
||||||
|
"PIP_TRUSTED_HOST",
|
||||||
|
"PIP_DISABLE_PIP_VERSION_CHECK",
|
||||||
|
"SALT_TRANSPORT",
|
||||||
|
# Are both of these really needed?
|
||||||
|
"GITHUB_ACTIONS",
|
||||||
|
"GITHUB_ACTIONS_PIPELINE",
|
||||||
|
"CI",
|
||||||
|
"SKIP_CODE_COVERAGE",
|
||||||
|
"COVERAGE_CONTEXT",
|
||||||
|
"RERUN_FEAILURES",
|
||||||
|
]:
|
||||||
|
if var in os.environ:
|
||||||
|
env[var] = os.environ[var]
|
||||||
|
cmd = [
|
||||||
|
"/usr/bin/docker",
|
||||||
|
"create",
|
||||||
|
"--privileged",
|
||||||
|
# "--ulimit",
|
||||||
|
# "\"nofile=262144:262144\"",
|
||||||
|
f"--workdir={workdir}",
|
||||||
|
"-v",
|
||||||
|
"/tmp/:/var/lib/docker",
|
||||||
|
]
|
||||||
|
for key in env:
|
||||||
|
cmd.extend(["-e", f"{key}={env[key]}"])
|
||||||
|
if onci:
|
||||||
|
cmd.extend(["-v", "/home/runner/work:/__w"])
|
||||||
|
else:
|
||||||
|
cmd.extend(["-v", f"{os.getcwd()}:/salt"])
|
||||||
|
if name:
|
||||||
|
cmd.extend(["--name", name])
|
||||||
|
cmd.extend(
|
||||||
|
[
|
||||||
|
"--entrypoint",
|
||||||
|
"/usr/lib/systemd/systemd",
|
||||||
|
image,
|
||||||
|
"--systemd",
|
||||||
|
"--unit",
|
||||||
|
"rescue.target",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
ret = ctx.run(*cmd, capture=True, check=False)
|
||||||
|
if ret.returncode != 0:
|
||||||
|
ctx.warn(ret.stderr.decode())
|
Loading…
Add table
Reference in a new issue