Skip to content

Commit

Permalink
fix: resolve missing dependencies in some custom project images (#1428)
Browse files Browse the repository at this point in the history
Signed-off-by: hunnywar <h3815273@gmail.com>
  • Loading branch information
hunnywar authored Dec 20, 2024
1 parent 991ede7 commit 844454c
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/docker/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (d *DockerClient) startDaytonaAgent(p *project.Project, containerUser, dayt

go func() {
result, err := d.ExecSync(d.GetProjectContainerName(p), container.ExecOptions{
Cmd: []string{"bash", "-c", util.GetProjectStartScript(daytonaDownloadUrl, p.ApiKey)},
Cmd: []string{"sh", "-c", util.GetProjectStartScript(daytonaDownloadUrl, p.ApiKey)},
AttachStdout: true,
AttachStderr: true,
User: containerUser,
Expand Down
2 changes: 1 addition & 1 deletion pkg/docker/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (s *DockerClientTestSuite) TestStartProject() {
},
}, nil)

s.setupExecTest([]string{"bash", "-c", util.GetProjectStartScript("", project1.ApiKey)}, containerName, project1.User, []string{}, "Daytona Agent started")
s.setupExecTest([]string{"sh", "-c", util.GetProjectStartScript("", project1.ApiKey)}, containerName, project1.User, []string{}, "Daytona Agent started")

err := s.dockerClient.StartProject(&docker.CreateProjectOptions{
Project: project1,
Expand Down
97 changes: 96 additions & 1 deletion pkg/provider/util/project_start_script.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,101 @@ package util

import "fmt"

const INSTALL_DEPENDENCIES_SCRIPT = `
# List of supported package managers
PACKAGE_MANAGERS="apt-get yum dnf apk brew pacman"
# Check if sudo exists
if ! command -v sudo >/dev/null 2>&1; then
echo "Sudo not found."
for pm in $PACKAGE_MANAGERS; do
if command -v "$pm" >/dev/null 2>&1; then
echo "Trying to install sudo using $pm..."
case "$pm" in
apt-get)
apt-get update >/dev/null 2>&1
apt-get install -y sudo >/dev/null 2>&1
;;
yum)
yum install -y sudo >/dev/null 2>&1
;;
dnf)
dnf install -y sudo >/dev/null 2>&1
;;
apk)
apk add --no-cache sudo >/dev/null 2>&1
;;
brew)
brew install sudo >/dev/null 2>&1
;;
pacman)
pacman -Sy --noconfirm sudo >/dev/null 2>&1
;;
esac
if command -v sudo >/dev/null 2>&1; then
break
fi
fi
done
fi
# Verify sudo is working
if ! sudo -v; then
echo "Failed to configure sudo. Check system permissions."
exit 1
fi
# Check for missing dependencies
DEPENDENCIES="curl bash git"
MISSING_DEPS=""
for dep in $DEPENDENCIES; do
if ! command -v "$dep" >/dev/null 2>&1; then
MISSING_DEPS="$MISSING_DEPS $dep"
fi
done
# Install missing dependencies
if test -n "$MISSING_DEPS"; then
echo "Missing dependencies:$MISSING_DEPS"
for pm in $PACKAGE_MANAGERS; do
if command -v "$pm" >/dev/null 2>&1; then
case "$pm" in
apt-get)
sudo apt-get update >/dev/null 2>&1
sudo apt-get install -y $MISSING_DEPS >/dev/null 2>&1
;;
yum)
sudo yum install -y $MISSING_DEPS >/dev/null 2>&1
;;
dnf)
sudo dnf install -y $MISSING_DEPS >/dev/null 2>&1
;;
apk)
sudo apk add --no-cache $MISSING_DEPS libc6-compat >/dev/null 2>&1
;;
brew)
sudo brew install $MISSING_DEPS >/dev/null 2>&1
;;
pacman)
sudo pacman -Sy --noconfirm $MISSING_DEPS >/dev/null 2>&1
;;
esac
break
fi
done
fi
`

func GetProjectStartScript(daytonaDownloadUrl string, apiKey string) string {
return fmt.Sprintf(`curl -sfL -H "Authorization: Bearer %s" %s | sudo -E bash && daytona agent`, apiKey, daytonaDownloadUrl)
return fmt.Sprintf(`
%s
# Download and install Daytona agent
curl -sfL -H "Authorization: Bearer %s" %s | sudo -E bash && daytona agent
`, INSTALL_DEPENDENCIES_SCRIPT, apiKey, daytonaDownloadUrl)
}

0 comments on commit 844454c

Please sign in to comment.