Skip to content

Commit 844454c

Browse files
authored
fix: resolve missing dependencies in some custom project images (#1428)
Signed-off-by: hunnywar <h3815273@gmail.com>
1 parent 991ede7 commit 844454c

File tree

3 files changed

+98
-3
lines changed

3 files changed

+98
-3
lines changed

pkg/docker/start.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (d *DockerClient) startDaytonaAgent(p *project.Project, containerUser, dayt
5151

5252
go func() {
5353
result, err := d.ExecSync(d.GetProjectContainerName(p), container.ExecOptions{
54-
Cmd: []string{"bash", "-c", util.GetProjectStartScript(daytonaDownloadUrl, p.ApiKey)},
54+
Cmd: []string{"sh", "-c", util.GetProjectStartScript(daytonaDownloadUrl, p.ApiKey)},
5555
AttachStdout: true,
5656
AttachStderr: true,
5757
User: containerUser,

pkg/docker/start_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (s *DockerClientTestSuite) TestStartProject() {
4141
},
4242
}, nil)
4343

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

4646
err := s.dockerClient.StartProject(&docker.CreateProjectOptions{
4747
Project: project1,

pkg/provider/util/project_start_script.go

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,101 @@ package util
55

66
import "fmt"
77

8+
const INSTALL_DEPENDENCIES_SCRIPT = `
9+
# List of supported package managers
10+
PACKAGE_MANAGERS="apt-get yum dnf apk brew pacman"
11+
12+
# Check if sudo exists
13+
if ! command -v sudo >/dev/null 2>&1; then
14+
echo "Sudo not found."
15+
16+
for pm in $PACKAGE_MANAGERS; do
17+
if command -v "$pm" >/dev/null 2>&1; then
18+
echo "Trying to install sudo using $pm..."
19+
20+
case "$pm" in
21+
apt-get)
22+
apt-get update >/dev/null 2>&1
23+
apt-get install -y sudo >/dev/null 2>&1
24+
;;
25+
yum)
26+
yum install -y sudo >/dev/null 2>&1
27+
;;
28+
dnf)
29+
dnf install -y sudo >/dev/null 2>&1
30+
;;
31+
apk)
32+
apk add --no-cache sudo >/dev/null 2>&1
33+
;;
34+
brew)
35+
brew install sudo >/dev/null 2>&1
36+
;;
37+
pacman)
38+
pacman -Sy --noconfirm sudo >/dev/null 2>&1
39+
;;
40+
esac
41+
42+
if command -v sudo >/dev/null 2>&1; then
43+
break
44+
fi
45+
fi
46+
done
47+
fi
48+
49+
# Verify sudo is working
50+
if ! sudo -v; then
51+
echo "Failed to configure sudo. Check system permissions."
52+
exit 1
53+
fi
54+
55+
# Check for missing dependencies
56+
DEPENDENCIES="curl bash git"
57+
MISSING_DEPS=""
58+
59+
for dep in $DEPENDENCIES; do
60+
if ! command -v "$dep" >/dev/null 2>&1; then
61+
MISSING_DEPS="$MISSING_DEPS $dep"
62+
fi
63+
done
64+
65+
# Install missing dependencies
66+
if test -n "$MISSING_DEPS"; then
67+
echo "Missing dependencies:$MISSING_DEPS"
68+
69+
for pm in $PACKAGE_MANAGERS; do
70+
if command -v "$pm" >/dev/null 2>&1; then
71+
case "$pm" in
72+
apt-get)
73+
sudo apt-get update >/dev/null 2>&1
74+
sudo apt-get install -y $MISSING_DEPS >/dev/null 2>&1
75+
;;
76+
yum)
77+
sudo yum install -y $MISSING_DEPS >/dev/null 2>&1
78+
;;
79+
dnf)
80+
sudo dnf install -y $MISSING_DEPS >/dev/null 2>&1
81+
;;
82+
apk)
83+
sudo apk add --no-cache $MISSING_DEPS libc6-compat >/dev/null 2>&1
84+
;;
85+
brew)
86+
sudo brew install $MISSING_DEPS >/dev/null 2>&1
87+
;;
88+
pacman)
89+
sudo pacman -Sy --noconfirm $MISSING_DEPS >/dev/null 2>&1
90+
;;
91+
esac
92+
93+
break
94+
fi
95+
done
96+
fi
97+
`
98+
899
func GetProjectStartScript(daytonaDownloadUrl string, apiKey string) string {
9-
return fmt.Sprintf(`curl -sfL -H "Authorization: Bearer %s" %s | sudo -E bash && daytona agent`, apiKey, daytonaDownloadUrl)
100+
return fmt.Sprintf(`
101+
%s
102+
# Download and install Daytona agent
103+
curl -sfL -H "Authorization: Bearer %s" %s | sudo -E bash && daytona agent
104+
`, INSTALL_DEPENDENCIES_SCRIPT, apiKey, daytonaDownloadUrl)
10105
}

0 commit comments

Comments
 (0)