Skip to content

Commit

Permalink
daytona server and client in separate containers
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelo-ochoa committed Jul 21, 2024
1 parent 1e57eae commit 6aac57c
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 51 deletions.
21 changes: 19 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,24 @@ RUN --mount=type=cache,target=/go/pkg/mod \

FROM alpine:3.15
ARG DAYTONA_SERVER_VERSION
ENV HOME=/home/daytona
ENV TERM=ansi
ENV PS1="\e[0;32m[\h \W]\$ \e[m "
RUN apk update && apk add --no-cache curl openssh-client ncurses bash ttyd tini sudo bash-completion && \
(curl -sf -L https://download.daytona.io/daytona/install.sh | bash) && \
echo "daytona:x:1000:1000:Daytona:/home/daytona:/bin/bash" >> /etc/passwd && \
echo "daytona:x:1000:" >> /etc/group
echo "daytona:x:1000:1000:Daytona:$HOME:/bin/bash" >> /etc/passwd && \
echo "daytona:x:1000:" >> /etc/group && \
mkdir $HOME && \
mkdir -p "$HOME/.ssh" && \
chmod go-rwx "$HOME/.ssh" && \
daytona autocomplete bash && \
echo "source /etc/profile.d/bash_completion.sh" > $HOME/.bashrc && \
echo "source $HOME/.daytona.completion_script.bash" >> $HOME/.bashrc && \
echo "export TERM=$TERM" >> $HOME/.bashrc && \
echo "export PS1=\"$PS1\"" >> $HOME/.bashrc && \
echo "cd $HOME" >> $HOME/.bashrc && \
echo "daytona whoami" >> $HOME/.bashrc && \
chown -R 1000:1000 $HOME

LABEL org.opencontainers.image.title="Daytona client tool"
LABEL org.opencontainers.image.description="Docker Extension for using an embedded version of Daytona client/server tools."
Expand All @@ -51,4 +65,7 @@ COPY --from=client-builder /app/client/dist /ui
COPY --from=builder /backend/bin/service /
COPY --chown=1000:1000 startup.sh daytona.sh /sbin/

WORKDIR /home/daytona
VOLUME [ "/home/daytona" ]

ENTRYPOINT ["/sbin/tini", "--", "/service", "-socket", "/run/guest-services/daytona-docker-extension.sock"]
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,25 @@ By clicking at Daytona icon the extension main window will display a progress ba

![Daytona CLI Welcome Page](docs/images/screenshot2.png?raw=true)

## First login

Daytona Server is running in a separate container from Docker Extension UI, you should have to setup a default profile to connect the backend, use:

```bash
$ docker exec -ti daytona_embedded_dd_vm cat $HOME/daytona/.config/daytona/config.json | jq .profiles -c
[{"id":"default","name":"default","api":{"url":"http://localhost:3986","key":"OGI0MmQyODctODJiMS00Yzk3LTg3OWEtYTA1MDFiODhjZjY2"}}]
```

With above output using you Extension Pane put:

```bash
[daytona-docker-extension ~]$ daytona profile add -n default -a http://backend:3986 -k OGI0MmQyODctODJiMS00Yzk3LTg3OWEtYTA1MDFiODhjZjY2
Profile default added and set as active
Server URL: http://backend:3986
```

**Note** that We replaced locahost by backend and the key is extracted from output of the first command executed on backend container.

## Daytona Server logs

Using CLI Pane is posible to see Daytona Serrver logs using:
Expand Down Expand Up @@ -80,6 +99,7 @@ To uninstall the extension just execute:
```bash
$ docker extension uninstall daytonaio/daytona-docker-extension:0.22.1
Extension "Daytona client tool" uninstalled successfully
rm -rf $HOME/daytona/
```

## Source Code
Expand Down
2 changes: 1 addition & 1 deletion daytona.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

# Define the URL to check
url="http://localhost:3986/health"
url="http://backend:3986/health"

# Set the maximum number of retries (optional, default 10)
retries=${1:-10}
Expand Down
18 changes: 15 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,29 @@ services:
daytona-docker-extension:
environment:
- LOG_LEVEL=debug
- HOME=$HOME/daytona
- HOME=/home/daytona
image: ${DESKTOP_PLUGIN_IMAGE}
hostname: daytona-docker-extension
ports:
- 57681:7681
volumes:
- daytona_home:/home/daytona

backend:
container_name: daytona_embedded_dd_vm
entrypoint: /sbin/startup.sh
environment:
- LOG_LEVEL=debug
- HOME=$HOME/daytona
image: ${DESKTOP_PLUGIN_IMAGE}
hostname: daytona-docker-backend
ports:
- 3986:3986
- 3987:3987
- 57681:7681
volumes:
- $HOME/daytona:$HOME/daytona
- headscale:$HOME/daytona/.config/daytona/server/headscale
- /var/run/docker.sock.raw:/var/run/docker.sock

volumes:
headscale:
daytona_home:
4 changes: 1 addition & 3 deletions startup.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#!/bin/bash
export TERM=ansi
export PS1="\e[0;32m[\h \W]\$ \e[m "
sed -i "s|/home/daytona:|$HOME:|g" /etc/passwd
mkdir -p "$HOME/.ssh"
chmod go-rwx "$HOME/.ssh"
Expand All @@ -14,4 +12,4 @@ echo "cd $HOME" >> $HOME/.bashrc
echo "daytona whoami" >> $HOME/.bashrc
chown -R 1000:1000 "$HOME"
chown 1000 /var/run/docker.sock
sudo -u daytona -i daytona serve > /tmp/serve.out 2> /tmp/serve.log &
sudo -u daytona -i daytona serve > /tmp/serve.out 2> /tmp/serve.log
43 changes: 1 addition & 42 deletions vm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ func (t Theme) String() string {

type TTYD struct {
process *os.Process
serve *os.Process
}

func (t *TTYD) Start(theme Theme) error {
Expand All @@ -106,16 +105,6 @@ func (t *TTYD) Start(theme Theme) error {
}
globaltheme = theme
}
if !t.IsServed() {

cmd := exec.Command("/sbin/startup.sh")
if err := cmd.Start(); err != nil {
return err
}

t.serve = cmd.Process
log.Println("started daytona serve...")
}
if !t.IsStarted() {
args := []string{"-W", "-u", "1000", "-g", "1000", "-t", "titleFixed='daytona'"}
args = append(args, "-t", fmt.Sprintf("theme=%s", theme))
Expand Down Expand Up @@ -146,33 +135,19 @@ func (t *TTYD) Stop() error {
t.process.Wait()
t.process = nil

if !t.IsServed() {
return nil
}

if err := t.serve.Kill(); err != nil {
log.Printf("failed to stop serve: %s\n", err)
return err
}
t.serve.Wait()
t.serve = nil
return nil
}

func (t TTYD) IsStarted() bool {
return t.process != nil
}

func (t TTYD) IsServed() bool {
return t.serve != nil
}

func (t *TTYD) IsRunning() bool {
if !t.IsStarted() {
return false
}

url := "http://localhost:3986/health" // "daytona" is the name of the service defined in docker-compose.yml
url := "http://backend:3986/health" // "daytona" is the name of the service defined in docker-compose.yml
resp, err := http.Get(url)
if err != nil {
log.Println(err)
Expand All @@ -182,19 +157,3 @@ func (t *TTYD) IsRunning() bool {

return resp.StatusCode == http.StatusOK
}

func (t *TTYD) IsDaemon() bool {
if !t.IsServed() {
return false
}

url := "http://localhost:3986/health" // "daytona" is the name of the service defined in docker-compose.yml
resp, err := http.Get(url)
if err != nil {
log.Println(err)
return false

}

return resp.StatusCode == http.StatusOK
}

0 comments on commit 6aac57c

Please sign in to comment.