Skip to content

add synapsectl command for deploying to device, and associated build / package / deploy scripts#106

Merged
emmazhou merged 28 commits intomainfrom
emma-deploy
May 10, 2025
Merged

add synapsectl command for deploying to device, and associated build / package / deploy scripts#106
emmazhou merged 28 commits intomainfrom
emma-deploy

Conversation

@emmazhou
Copy link
Copy Markdown
Contributor

@emmazhou emmazhou commented May 8, 2025

No description provided.

Comment thread synapse/cli/deploy.py
'''

cmd = [
"docker",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we detect whether docker is installed upfront and not let them get this far if docker won't be found or isn't running?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn't go so far as to uninstall docker to test, but when it's not running:
Screenshot 2025-05-08 at 3 26 51 PM

Copy link
Copy Markdown
Contributor

@maxhodak maxhodak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is unreviewable, way way too long

Comment thread synapse/cli/deploy.py Outdated
Comment on lines +539 to +555
# Send the command to start the application
shell.send(f"sudo systemctl start {app_name}.service\n")
time.sleep(2) # Wait for the command to execute

# Collect output to check for errors
output = ""
while shell.recv_ready():
chunk = shell.recv(4096).decode("utf-8")
output += chunk

# If there's an error, we'll usually see it in the output
if "error" in output.lower() or "failed" in output.lower():
progress.update(task, visible=False)
console.print(
f"[bold red]Error:[/bold red] Failed to start application:\n{output}"
)
return False
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scifi will be responsible for managing start/stop of the server. This can be replaced with configuring the device and then starting

Comment thread synapse/cli/deploy.py Outdated

# Send su command
shell.send("su -\n")
time.sleep(1) # Wait for password prompt
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there no way to ensure the command has been executed beyond sleeping? This seems both slow and unreliable

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this should all be handled on the scifi side, both for reliability and to keep SSH restricted.

Comment thread synapse/cli/deploy.py Outdated
Comment on lines +301 to +310
# Deploy directly using paramiko
client = None
sftp = None
shell = None

# Create SSH client
import paramiko

client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are sftp utility functions in synapse/client/sftp.py that could probably wrap a lot of this

Comment thread synapse/cli/deploy.py
-DVCPKG_INSTALLED_DIR=${VCPKG_ROOT}/vcpkg_installed \
-DBUILD_SHARED_LIBS=ON \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_FOR_ARM64=ON &&
Copy link
Copy Markdown
Contributor

@polymerizedsage polymerizedsage May 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this is scifi-server specific and can probably be removed

Comment thread synapse/cli/deploy.py Outdated
Comment on lines +157 to +183
set -e
APP_NAME="{app_name}"

# Copy the template ops directory to a temporary working area inside the container
TEMPLATE_DIR="/synapse_ops"
TEMP_DIR="/tmp/synapse_package_ops"
rm -rf "$TEMP_DIR"
cp -r "$TEMPLATE_DIR" "$TEMP_DIR"

# Replace placeholders in every file
find "$TEMP_DIR" -type f -exec sed -i 's/{{{{APP_NAME}}}}/'"$APP_NAME"'/g' {{}} +

# Rename the systemd service template to the correct name
# The template file is literally called "{{APP_NAME}}.service" (double braces).
if [ -f "$TEMP_DIR/package/systemd/{{{{APP_NAME}}}}.service" ]; then
mv "$TEMP_DIR/package/systemd/{{{{APP_NAME}}}}.service" "$TEMP_DIR/package/systemd/$APP_NAME.service"
fi

# Ensure the packaging script is executable and points to the correct source dir
chmod +x "$TEMP_DIR/package/package.sh"
sed -i 's|SOURCE_DIR=.*|SOURCE_DIR="/home/workspace"|' "$TEMP_DIR/package/package.sh"

# Finally, run the packaging script from the workspace root so that the .deb lands
# in the application directory that is mounted from the host.
cd /home/workspace
bash "$TEMP_DIR/package/package.sh"
'''
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this all be a part of package.sh? Then we wouldnt have inline bash scripts in python.


# Reload and start the service
systemctl daemon-reload
systemctl enable "${SYNAPSE_APP_EXE}" No newline at end of file
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be removed so the app doesnt automatically start

Comment on lines +10 to +20
if ! renice -n -10 $$ > /dev/null 2>&1; then
echo "Failed to set process priority"
exit 1
fi

# Set CPU scheduler to FIFO
# Might drop this down if the system is unstable
if ! chrt -f -p 50 $$ > /dev/null 2>&1; then
echo "Failed to set CPU scheduler to FIFO"
exit 1
fi
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these should all be removed

Copy link
Copy Markdown
Contributor

@gilbert-sci gilbert-sci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we will break this out but this is a good start.

@emmazhou emmazhou merged commit 51f933b into main May 10, 2025
2 checks passed
@emmazhou emmazhou deleted the emma-deploy branch May 10, 2025 02:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants