Skip to content

Commit dd4dc84

Browse files
committed
Fix a few issues with docker compose deploy
1 parent b57d40b commit dd4dc84

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

ctfcli/core/deployment/ssh.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,28 @@ def deploy(self, *args, **kwargs) -> DeploymentResult:
2626

2727
def _deploy_compose_stack(self, *args, **kwargs) -> DeploymentResult:
2828
host_url = urlparse(self.host)
29-
target_path = host_url.path or "~/"
29+
target_path = str(host_url.path)
30+
if target_path == '/': # Don't put challenges in the root of the filesystem.
31+
target_path = ''
32+
elif target_path == '//': # If you really want to, add a second slash as part of your path: ssh://1.1.1.1//
33+
target_path = '/'
34+
elif target_path.startswith('/~/'): # Support relative paths by starting your path with /~/
35+
target_path = target_path.removeprefix('/~/')
3036
try:
31-
subprocess.run(["ssh", host_url.netloc, f"mkdir -p {target_path}/"], check=True)
37+
subprocess.run(["ssh", host_url.netloc, f"mkdir -p '{target_path}/'"], check=True)
3238
subprocess.run(
3339
["rsync", "-a", "--delete", self.challenge.challenge_directory, f"{host_url.netloc}:{target_path}"],
3440
check=True,
3541
)
42+
if not target_path:
43+
remote_path = f"{self.challenge.challenge_directory.name}"
44+
else:
45+
remote_path = f"{target_path}/{self.challenge.challenge_directory.name}"
3646
subprocess.run(
3747
[
3848
"ssh",
3949
host_url.netloc,
40-
f"cd {target_path}/{self.challenge.challenge_directory.name} && "
50+
f"cd {remote_path} && "
4151
"docker compose up -d --build --remove-orphans -y",
4252
],
4353
check=True,

0 commit comments

Comments
 (0)