From 6aac57cfc31973e6f7142900434d0600c58ce933 Mon Sep 17 00:00:00 2001 From: Marcelo Ochoa Date: Sun, 21 Jul 2024 19:22:09 -0300 Subject: [PATCH] daytona server and client in separate containers --- Dockerfile | 21 +++++++++++++++++++-- README.md | 20 ++++++++++++++++++++ daytona.sh | 2 +- docker-compose.yml | 18 +++++++++++++++--- startup.sh | 4 +--- vm/main.go | 43 +------------------------------------------ 6 files changed, 57 insertions(+), 51 deletions(-) diff --git a/Dockerfile b/Dockerfile index f5446ec..a253401 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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." @@ -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"] \ No newline at end of file diff --git a/README.md b/README.md index 70692b5..3b82b8e 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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 diff --git a/daytona.sh b/daytona.sh index d832854..97f786f 100755 --- a/daytona.sh +++ b/daytona.sh @@ -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} diff --git a/docker-compose.yml b/docker-compose.yml index e708f58..b0c6924 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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: diff --git a/startup.sh b/startup.sh index 845f1fa..8fc3bb9 100755 --- a/startup.sh +++ b/startup.sh @@ -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" @@ -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 diff --git a/vm/main.go b/vm/main.go index eb69446..975c670 100644 --- a/vm/main.go +++ b/vm/main.go @@ -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 { @@ -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)) @@ -146,16 +135,6 @@ 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 } @@ -163,16 +142,12 @@ 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) @@ -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 -} \ No newline at end of file