Skip to content

Commit 3c12166

Browse files
committed
debugging
1 parent 21a0ef0 commit 3c12166

File tree

2 files changed

+77
-5
lines changed

2 files changed

+77
-5
lines changed

custom-domain/dstack-ingress/scripts/certman.py

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,26 @@ def install_plugin(self) -> bool:
8686

8787
def setup_credentials(self) -> bool:
8888
"""Setup credentials file for certbot using provider implementation."""
89-
return self.provider.setup_certbot_credentials()
89+
print(f"Setting up credentials for {self.provider_type} provider")
90+
result = self.provider.setup_certbot_credentials()
91+
if result:
92+
print(f"Credentials setup successful for {self.provider_type}")
93+
else:
94+
print(f"Credentials setup failed for {self.provider_type}")
95+
return result
9096

9197
def _build_certbot_command(self, action: str, domain: str, email: str) -> List[str]:
9298
"""Build certbot command using provider configuration."""
99+
print(f"Building certbot command for action: {action}, domain: {domain}")
100+
93101
plugin = self.provider.CERTBOT_PLUGIN
102+
print(f"Using plugin: {plugin}")
103+
94104
if not plugin:
95105
raise ValueError(f"No certbot plugin configured for {self.provider_type}")
96106

97107
propagation_seconds = self.provider.CERTBOT_PROPAGATION_SECONDS
108+
print(f"Propagation seconds configured: {propagation_seconds}")
98109

99110
base_cmd = ["certbot", action]
100111

@@ -105,37 +116,77 @@ def _build_certbot_command(self, action: str, domain: str, email: str) -> List[s
105116
"--non-interactive",
106117
]
107118
)
119+
print(f"Added plugin and non-interactive flags")
108120

109121
# Add credentials file if provider has one configured
110122
if self.provider.CERTBOT_CREDENTIALS_FILE:
111123
credentials_file = os.path.expanduser(
112124
self.provider.CERTBOT_CREDENTIALS_FILE
113125
)
126+
print(f"Credentials file path (expanded): {credentials_file}")
127+
114128
if os.path.exists(credentials_file):
115-
base_cmd.extend([f"--{plugin}-credentials={credentials_file}"])
129+
credentials_arg = f"--{plugin}-credentials={credentials_file}"
130+
base_cmd.extend([credentials_arg])
131+
print(f"Added credentials argument: {credentials_arg}")
132+
else:
133+
print(f"Warning: Credentials file does not exist: {credentials_file}")
134+
else:
135+
print(f"No credentials file configured for provider")
116136

117137
if action == "certonly":
118138
base_cmd.extend(
119139
["--agree-tos", "--no-eff-email", "--email", email, "-d", domain]
120140
)
141+
print(f"Added certonly-specific arguments")
121142

143+
# Print the final command with masked email
144+
masked_cmd = []
145+
for i, arg in enumerate(base_cmd):
146+
if i > 0 and base_cmd[i-1] == "--email":
147+
masked_cmd.append("<email>")
148+
else:
149+
masked_cmd.append(arg)
150+
print(f"Final certbot command: {' '.join(masked_cmd)}")
151+
122152
return base_cmd
123153

124154
def obtain_certificate(self, domain: str, email: str) -> bool:
125155
"""Obtain a new certificate for the domain."""
126-
print(f"Obtaining new certificate for {domain} using {self.provider_type}")
156+
print(f"Starting certificate obtaining process for {domain} using {self.provider_type}")
157+
158+
# Check if credentials are set up
159+
print(f"Checking credentials setup...")
160+
if not self.setup_credentials():
161+
print(f"Failed to setup credentials for {self.provider_type}", file=sys.stderr)
162+
return False
163+
print(f"Credentials setup completed")
127164

128165
cmd = self._build_certbot_command("certonly", domain, email)
166+
print(f"Executing certbot command...")
129167

130168
try:
131-
result = subprocess.run(cmd, capture_output=True, text=True)
169+
result = subprocess.run(cmd, capture_output=True, text=True, timeout=300)
170+
171+
print(f"Certbot command completed with return code: {result.returncode}")
172+
173+
if result.stdout:
174+
print(f"Certbot stdout: {result.stdout}")
175+
132176
if result.returncode != 0:
133-
print(f"Certificate obtaining failed: {result.stderr}", file=sys.stderr)
177+
print(f"Certificate obtaining failed with return code {result.returncode}")
178+
if result.stderr:
179+
print(f"Certificate obtaining failed: {result.stderr}", file=sys.stderr)
180+
if result.stdout:
181+
print(f"Certificate stdout on failure: {result.stdout}", file=sys.stderr)
134182
return False
135183

136184
print(f"Certificate obtained successfully for {domain}")
137185
return True
138186

187+
except subprocess.TimeoutExpired:
188+
print(f"Certbot command timed out after 300 seconds", file=sys.stderr)
189+
return False
139190
except Exception as e:
140191
print(f"Error running certbot: {e}", file=sys.stderr)
141192
return False

custom-domain/dstack-ingress/scripts/dns_providers/namecheap.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,38 @@ def __init__(self):
3434

3535
def setup_certbot_credentials(self) -> bool:
3636
"""Setup credentials file for certbot."""
37+
print(f"Setting up Namecheap credentials file...")
38+
3739
try:
3840
cred_dir = os.path.expanduser("~/.namecheap")
41+
print(f"Creating credentials directory: {cred_dir}")
3942
os.makedirs(cred_dir, exist_ok=True)
4043

4144
cred_file = os.path.join(cred_dir, "namecheap.ini")
45+
print(f"Writing credentials file: {cred_file}")
46+
4247
with open(cred_file, "w") as f:
4348
f.write(f"# Namecheap API credentials used by Certbot\n")
4449
f.write(f"dns_namecheap_username={self.username}\n")
4550
f.write(f"dns_namecheap_api_key={self.api_key}\n")
4651

52+
print(f"Setting file permissions to 0o600")
4753
os.chmod(cred_file, 0o600)
54+
55+
print(f"Credentials file created successfully: {cred_file}")
56+
57+
# Verify file contents (without showing sensitive data)
58+
if os.path.exists(cred_file):
59+
with open(cred_file, "r") as f:
60+
lines = f.readlines()
61+
print(f"Credentials file has {len(lines)} lines")
62+
for i, line in enumerate(lines):
63+
if line.startswith('#'):
64+
print(f"Line {i+1}: {line.strip()}")
65+
elif '=' in line:
66+
key = line.split('=')[0]
67+
print(f"Line {i+1}: {key}=<value>")
68+
4869
return True
4970
except Exception as e:
5071
print(f"Error setting up certbot credentials: {e}")

0 commit comments

Comments
 (0)