import uuid
from gravixlayer import GravixLayer
client = GravixLayer() # defaults to cloud="aws", region="us-east-1"
policy = client.network_policies.create(
name=f"git-egress-{uuid.uuid4().hex[:8]}",
egress_mode="allow_all",
description="Temporary egress for git",
)
sandbox = None
try:
sandbox = client.runtime.create(
network_policy_ids=[policy.id],
timeout=600,
)
repo = "/workspace/repo"
sandbox.git.clone(
url="https://github.com/octocat/Hello-World.git",
path=repo,
branch="master",
depth=1,
)
sandbox.git.create_branch(repo, "demo-branch")
sandbox.git.checkout(repo, "demo-branch")
sandbox.file.write(f"{repo}/note.txt", "hello\n")
sandbox.git.add(repo, paths=["note.txt"])
sandbox.git.commit(
repo,
"add note",
author_name="Demo",
author_email="demo@example.com",
)
print(sandbox.git.status(repo).stdout)
finally:
if sandbox is not None:
sandbox.kill()
client.network_policies.delete(policy.id)