Skip to content

Commit

Permalink
linux
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanleung committed Sep 9, 2024
1 parent 7b4e1f4 commit b435ce8
Show file tree
Hide file tree
Showing 6 changed files with 357 additions and 6 deletions.
121 changes: 121 additions & 0 deletions .github/workflows/mor-agents-build-linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
name: MOR Agents Build Linux

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
submodules: 'recursive'

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pyinstaller
- name: Build with PyInstaller
run: |
pyinstaller --name="MORagents" --add-data "images/moragents.png:images" main.py
- name: Create Debian package
run: |
mkdir -p debian/DEBIAN
mkdir -p debian/usr/bin
mkdir -p debian/usr/share/applications
mkdir -p debian/usr/share/icons/hicolor/256x256/apps
cp -r dist/MORagents/* debian/usr/bin/
cp images/moragents.png debian/usr/share/icons/hicolor/256x256/apps/moragents.png
echo "[Desktop Entry]
Name=MORagents
Exec=/usr/bin/MORagents
Icon=moragents
Type=Application
Categories=Utility;" > debian/usr/share/applications/moragents.desktop
echo "Package: moragents
Version: 1.0
Section: utils
Priority: optional
Architecture: amd64
Maintainer: LachsBagel
Description: MORagents application
MORagents is a desktop application for AI agents." > debian/DEBIAN/control
# Create postinst script
cat << EOF > debian/DEBIAN/postinst
#!/bin/bash
set -e
# Function to wait for apt lock to be released
wait_for_apt_lock() {
while fuser /var/lib/dpkg/lock >/dev/null 2>&1 || fuser /var/lib/apt/lists/lock >/dev/null 2>&1 || fuser /var/cache/apt/archives/lock >/dev/null 2>&1
do
echo "Waiting for other software managers to finish..."
sleep 5
done
}
# Function to install a package
install_package() {
package_name=$1
if ! dpkg -s $package_name >/dev/null 2>&1; then
echo "Installing $package_name..."
wait_for_apt_lock
apt-get update
apt-get install -y $package_name
else
echo "$package_name is already installed."
fi
}
# Install curl
install_package curl
# Install Docker if not present
if ! command -v docker &> /dev/null; then
echo "Installing Docker..."
curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh
usermod -aG docker $SUDO_USER
systemctl enable docker
systemctl start docker
else
echo "Docker is already installed."
fi
# Pull necessary Docker images
echo "Pulling Docker images..."
docker pull morpheusai/nginx-agent:latest
docker pull morpheusai/agents:latest
# Start Docker containers
echo "Starting Docker containers..."
docker run -d --name agents -p 8080:5000 --restart always -v /var/lib/agents -v /app/src morpheusai/agents:latest
docker run -d --name nginx -p 3333:80 morpheusai/nginx-agent:latest
echo "Installation complete!"
echo "You can now start MORagents from your application menu or by running 'MORagents' in the terminal."
EOF
chmod 755 debian/DEBIAN/postinst
dpkg-deb --build debian moragents.deb
- name: Upload Debian Package
uses: actions/upload-artifact@v4
with:
name: MORagentsSetup-Linux
path: moragents.deb
58 changes: 58 additions & 0 deletions build_assets/linux/install_moragents.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/bash

# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color

# Function to check if a command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}

# Check if script is run as root
if [ "$EUID" -ne 0 ]; then
echo -e "${RED}Please run as root${NC}"
exit 1
fi

echo "Welcome to the MORagents installer for Linux"

# Check and install Docker if not present
if ! command_exists docker; then
echo "Docker not found. Installing Docker..."
curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh
usermod -aG docker $SUDO_USER
systemctl enable docker
systemctl start docker
else
echo "Docker is already installed."
fi

# Check and install Python if not present
if ! command_exists python3; then
echo "Python3 not found. Installing Python3..."
apt update
apt install -y python3 python3-pip
else
echo "Python3 is already installed."
fi

# Install the .deb package
echo "Installing MORagents..."
dpkg -i moragents.deb
apt-get install -f -y

# Pull necessary Docker images
echo "Pulling Docker images..."
docker pull morpheusai/nginx-agent:latest
docker pull morpheusai/agents:latest

# Start Docker containers
echo "Starting Docker containers..."
docker run -d --name agents -p 8080:5000 --restart always -v /var/lib/agents -v /app/src morpheusai/agents:latest
docker run -d --name nginx -p 3333:80 morpheusai/nginx-agent:latest

echo -e "${GREEN}Installation complete!${NC}"
echo "You can now start MORagents from your application menu or by running 'MORagents' in the terminal."
12 changes: 9 additions & 3 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
# Run as bundled executable if condition is met, else run as regular Python script
repo_root = sys._MEIPASS if getattr(sys, 'frozen', False) else os.path.dirname(__file__)
elif os_name == "Linux":
raise RuntimeError(
f"MORagents needs Linux support! Would you like to help?\n"
f"https://github.com/MorpheusAIs/moragents/issues/27")
repo_root = os.path.dirname(__file__)
else:
raise RuntimeError(f"Unsupported OS: {os_name}")

class AgentDockerConfig:
MACOS_IMAGE_NAMES = [
Expand All @@ -23,13 +23,19 @@ class AgentDockerConfig:
"lachsbagel/moragents_dockers-nginx:amd64-0.0.9",
"lachsbagel/moragents_dockers-agents:amd64-0.0.9"
]
LINUX_IMAGE_NAMES = [
"lachsbagel/moragents_dockers-nginx:amd64-0.0.9",
"lachsbagel/moragents_dockers-agents:amd64-0.0.9"
]

@staticmethod
def get_current_image_names():
if os_name == "macOS":
return AgentDockerConfig.MACOS_IMAGE_NAMES
elif os_name == "Windows":
return AgentDockerConfig.WINDOWS_IMAGE_NAMES
elif os_name == "Linux":
return AgentDockerConfig.LINUX_IMAGE_NAMES
else:
raise RuntimeError(f"Unsupported OS: {os_name}")

Expand Down
Binary file added images/moragents.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 2 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from runtime_setup_macos import main as macos_setup
from runtime_setup_windows import main as windows_setup
from runtime_setup_linux import main as linux_setup
from utils.logger_config import setup_logger
from utils.host_utils import get_os_and_arch

Expand All @@ -21,9 +22,7 @@
elif os_name == "Windows":
windows_setup()
elif os_name == "Linux":
raise RuntimeError(
f"MORagents needs Linux support! Would you like to help?\n"
f"https://github.com/MorpheusAIs/moragents/issues/27")
linux_setup()

except Exception as e:
logging.critical(f"Error during Docker setup: {str(e)}")
Expand Down
Loading

0 comments on commit b435ce8

Please sign in to comment.