Skip to content

Commit

Permalink
feat: build projects on the target machine
Browse files Browse the repository at this point in the history
BREAKING CHANGE: the provider interface was changed so they will need to be updated by the user

Signed-off-by: Toma Puljak <[email protected]>
  • Loading branch information
Tpuljak committed Jun 26, 2024
1 parent 576c891 commit 9637604
Show file tree
Hide file tree
Showing 42 changed files with 1,644 additions and 348 deletions.
10 changes: 8 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/charmbracelet/bubbletea v0.25.0
github.com/charmbracelet/huh v0.2.3
github.com/charmbracelet/lipgloss v0.9.1
github.com/compose-spec/compose-go/v2 v2.1.3
github.com/creack/pty v1.1.21
github.com/docker/docker v26.0.2+incompatible
github.com/docker/go-connections v0.4.0
Expand Down Expand Up @@ -37,6 +38,7 @@ require (
github.com/swaggo/files v1.0.1
github.com/swaggo/gin-swagger v1.6.0
github.com/swaggo/swag v1.16.3
github.com/tailscale/hujson v0.0.0-20221223112325-20486734a56a
golang.org/x/crypto v0.23.0
golang.org/x/mod v0.17.0
golang.org/x/oauth2 v0.17.0
Expand Down Expand Up @@ -119,6 +121,7 @@ require (
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/go-viper/mapstructure/v2 v2.0.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/godbus/dbus/v5 v5.1.1-0.20230522191255-76236955d466 // indirect
github.com/gofrs/uuid/v5 v5.0.0 // indirect
Expand Down Expand Up @@ -165,6 +168,7 @@ require (
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-shellwords v1.0.12 // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
github.com/mdlayher/genetlink v1.3.2 // indirect
github.com/mdlayher/netlink v1.7.2 // indirect
Expand Down Expand Up @@ -215,7 +219,6 @@ require (
github.com/tailscale/go-winio v0.0.0-20231025203758-c4f33415bf55 // indirect
github.com/tailscale/golang-x-crypto v0.0.0-20240108194725-7ce1f622c780 // indirect
github.com/tailscale/goupnp v1.0.1-0.20210804011211-c64d0f06ea05 // indirect
github.com/tailscale/hujson v0.0.0-20221223112325-20486734a56a // indirect
github.com/tailscale/netlink v1.1.1-0.20211101221916-cabfb018fe85 // indirect
github.com/tailscale/setec v0.0.0-20230926024544-07dde05889e7 // indirect
github.com/tailscale/tailsql v0.0.0-20231216172832-51483e0c711b // indirect
Expand All @@ -234,6 +237,9 @@ require (
github.com/vishvananda/netns v0.0.4 // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.50.0 // indirect
go.opentelemetry.io/otel v1.25.0 // indirect
Expand All @@ -246,7 +252,7 @@ require (
go4.org/mem v0.0.0-20220726221520-4f986261bf13 // indirect
go4.org/netipx v0.0.0-20230824141953-6213f710f925 // indirect
golang.org/x/arch v0.5.0 // indirect
golang.org/x/exp v0.0.0-20231127185646-65229373498e // indirect
golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3 // indirect
golang.org/x/tools v0.21.0 // indirect
golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2 // indirect
golang.zx2c4.com/wireguard/windows v0.5.3 // indirect
Expand Down
17 changes: 15 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,8 @@ github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWH
github.com/cncf/xds/go v0.0.0-20220314180256-7f1daf1720fc/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20230105202645-06c439db220b/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20230310173818-32f1caf87195/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/compose-spec/compose-go/v2 v2.1.3 h1:bD67uqLuL/XgkAK6ir3xZvNLFPxPScEi1KW7R5esrLE=
github.com/compose-spec/compose-go/v2 v2.1.3/go.mod h1:lFN0DrMxIncJGYAXTfWuajfwj5haBJqrBkarHcnjJKc=
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 h1:q2hJAaP1k2wIvVRd/hEHD7lacgqrCPS+k8g1MndzfWY=
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81/go.mod h1:YynlIjWYF8myEu6sdkwKIvGQq+cOckRm6So2avqoYAk=
github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I=
Expand Down Expand Up @@ -906,6 +908,8 @@ github.com/go-playground/validator/v10 v10.18.0/go.mod h1:dbuPbCMFw/DrkbEynArYaC
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls=
github.com/go-viper/mapstructure/v2 v2.0.0 h1:dhn8MZ1gZ0mzeodTG3jt5Vj/o87xZKuNAprG2mQfMfc=
github.com/go-viper/mapstructure/v2 v2.0.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
github.com/goccy/go-json v0.9.11/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
Expand Down Expand Up @@ -1187,6 +1191,8 @@ github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRC
github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mattn/go-shellwords v1.0.12 h1:M2zGm7EW6UQJvDeQxo4T51eKPurbeFbe8WtebGE2xrk=
github.com/mattn/go-shellwords v1.0.12/go.mod h1:EZzvwXDESEeg03EKmM+RmDnNOPKG4lLtQsUlTZDWQ8Y=
github.com/mattn/go-sqlite3 v1.14.14/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvlsiIGKtc+UG6U5vzxaoagmhXfyg=
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0/go.mod h1:QUyp042oQthUoa9bqDv0ER0wrtXnBruoNd7aNjkbP+k=
Expand Down Expand Up @@ -1436,6 +1442,13 @@ github.com/xanzy/go-gitlab v0.97.0 h1:StMqJ1Kvt00X43pYIBBjj52dFlghwSeBhRDRfzaZ7x
github.com/xanzy/go-gitlab v0.97.0/go.mod h1:ETg8tcj4OhrB84UEgeE8dSuV/0h4BBL1uOV/qK0vlyI=
github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM=
github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw=
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb h1:zGWFAtiMcyryUHoUjUJX0/lt1H2+i2Ka2n+D3DImSNo=
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHovont7NscjpAxXsDA8S8BMYve8Y5+7cuRE7R0=
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ=
github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74=
github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
github.com/xtaci/lossyconn v0.0.0-20200209145036-adba10fffc37 h1:EWU6Pktpas0n8lLQwDsRyZfmkPeRbdgPtW609es+/9E=
github.com/xtaci/lossyconn v0.0.0-20200209145036-adba10fffc37/go.mod h1:HpMP7DB2CyokmAh4lp0EQnnWhmycP/TvwBGzvuie+H0=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down Expand Up @@ -1536,8 +1549,8 @@ golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u0
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
golang.org/x/exp v0.0.0-20220827204233-334a2380cb91/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE=
golang.org/x/exp v0.0.0-20231127185646-65229373498e h1:Gvh4YaCaXNs6dKTlfgismwWZKyjVZXwOPfIyUaqU3No=
golang.org/x/exp v0.0.0-20231127185646-65229373498e/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI=
golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3 h1:hNQpMuAJe5CtcUqCXaWga3FHu+kQvCqcsoVaQgSV60o=
golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3/go.mod h1:idGWGoKP1toJGkd5/ig9ZLuPcZBC3ewk7SzmH0uou08=
golang.org/x/exp/typeparams v0.0.0-20230905200255-921286631fa9 h1:j3D9DvWRpUfIyFfDPws7LoIZ2MAI1OJHdQXtTnYtN+k=
golang.org/x/exp/typeparams v0.0.0-20230905200255-921286631fa9/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk=
golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs=
Expand Down
2 changes: 1 addition & 1 deletion hack/project_image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ RUN apt update -y && \

USER daytona

ENTRYPOINT ["tail", "-f", "/dev/null"]
ENTRYPOINT ["sudo", "dockerd"]
6 changes: 6 additions & 0 deletions internal/constants/get_daytona_script.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ err() {
exit 1
}
# Check if daytona is already installed
if [ -x "$(command -v daytona)" ]; then
echo "Daytona already installed. Skipping installation..."
exit 0
fi
# Check machine architecture
ARCH=$(uname -m)
# Check operating system
Expand Down
5 changes: 5 additions & 0 deletions internal/testing/docker/mocks/api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ func (m *MockApiClient) ContainerInspect(ctx context.Context, container string)
return args.Get(0).(types.ContainerJSON), args.Error(1)
}

func (m *MockApiClient) ContainerList(ctx context.Context, options container.ListOptions) ([]types.Container, error) {
args := m.Called(ctx, options)
return args.Get(0).([]types.Container), args.Error(1)
}

func (m *MockApiClient) VolumeRemove(ctx context.Context, volume string, force bool) error {
args := m.Called(ctx, volume, force)
return args.Error(0)
Expand Down
16 changes: 16 additions & 0 deletions internal/util/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ func GetHomeDir(activeProfile config.Profile, workspaceId string, projectName st
}

func GetProjectDir(activeProfile config.Profile, workspaceId string, projectName string) (string, error) {
err := config.EnsureSshConfigEntryAdded(activeProfile.Id, workspaceId, projectName)
if err != nil {
return "", err
}

projectHostname := config.GetProjectHostname(activeProfile.Id, workspaceId, projectName)

daytonaProjectDir, err := exec.Command("ssh", projectHostname, "echo", "$DAYTONA_PROJECT_DIR").Output()
if err != nil {
return "", err
}

if strings.TrimRight(string(daytonaProjectDir), "\n") != "" {
return strings.TrimRight(string(daytonaProjectDir), "\n"), nil
}

homeDir, err := GetHomeDir(activeProfile, workspaceId, projectName)
if err != nil {
return "", err
Expand Down
2 changes: 1 addition & 1 deletion pkg/agent/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func GetLogFilePath() *string {
return nil
}

logFilePath = strings.Replace(logFilePath, "$HOME", os.Getenv("HOME"), 1)
logFilePath = strings.Replace(logFilePath, "(HOME)", os.Getenv("HOME"), 1)

return &logFilePath
}
80 changes: 80 additions & 0 deletions pkg/builder/detect/detect.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Copyright 2024 Daytona Platforms Inc.
// SPDX-License-Identifier: Apache-2.0

package detect

import (
"os"
"path"
"path/filepath"

"github.com/daytonaio/daytona/pkg/ssh"
"github.com/daytonaio/daytona/pkg/workspace"
)

type BuilderType string

var (
BuilderTypeDevcontainer BuilderType = "devcontainer"
BuilderTypeImage BuilderType = "image"
)

func DetectProjectBuilderType(project *workspace.Project, projectDir string, sshClient *ssh.Client) (BuilderType, error) {
if project.Build != nil && project.Build.Devcontainer != nil {
return BuilderTypeDevcontainer, nil
}

if sshClient != nil {
if _, err := sshClient.ReadFile(path.Join(projectDir, ".devcontainer/devcontainer.json")); err == nil {
project.Build.Devcontainer = &workspace.ProjectBuildDevcontainer{
DevContainerFilePath: ".devcontainer/devcontainer.json",
}
return BuilderTypeDevcontainer, nil
}
if _, err := sshClient.ReadFile(path.Join(projectDir, ".devcontainer.json")); err == nil {
project.Build.Devcontainer = &workspace.ProjectBuildDevcontainer{
DevContainerFilePath: ".devcontainer.json",
}
return BuilderTypeDevcontainer, nil
}
} else {
if devcontainerFilePath, pathError := findDevcontainerConfigFilePath(projectDir); pathError == nil {
project.Build.Devcontainer = &workspace.ProjectBuildDevcontainer{
DevContainerFilePath: devcontainerFilePath,
}

return BuilderTypeDevcontainer, nil
}
}

return BuilderTypeImage, nil
}

func findDevcontainerConfigFilePath(projectDir string) (string, error) {
devcontainerPath := ".devcontainer/devcontainer.json"
isDevcontainer, err := fileExists(filepath.Join(projectDir, devcontainerPath))
if err != nil {
devcontainerPath = ".devcontainer.json"
isDevcontainer, err = fileExists(filepath.Join(projectDir, devcontainerPath))
if err != nil {
return devcontainerPath, nil
}
}

if isDevcontainer {
return devcontainerPath, nil
}

return "", os.ErrNotExist
}

func fileExists(filePath string) (bool, error) {
_, err := os.Stat(filePath)
if os.IsNotExist(err) {
return false, nil
} else if err != nil {
// There was an error checking for the file
return false, err
}
return true, nil
}
4 changes: 2 additions & 2 deletions pkg/builder/devcontainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,12 @@ func (b *DevcontainerBuilder) readConfiguration() error {
return err
}

postCreateCommands, err := devcontainer.ConvertCommands(root.MergedConfiguration.PostCreateCommands)
postCreateCommands, err := devcontainer.ConvertToArray(root.MergedConfiguration.PostCreateCommands)
if err != nil {
projectLogger.Write([]byte(fmt.Sprintf("Error converting post create commands: %v\n", err)))
}

postStartCommands, err := devcontainer.ConvertCommands(root.MergedConfiguration.PostStartCommands)
postStartCommands, err := devcontainer.ConvertToArray(root.MergedConfiguration.PostStartCommands)
if err != nil {
projectLogger.Write([]byte(fmt.Sprintf("Error converting post start commands: %v\n", err)))
}
Expand Down
Loading

0 comments on commit 9637604

Please sign in to comment.