Skip to content

Commit

Permalink
fix: devcontainer compose creation
Browse files Browse the repository at this point in the history
Signed-off-by: Toma Puljak <[email protected]>
  • Loading branch information
Tpuljak committed Sep 27, 2024
1 parent 0c2ccb5 commit f1432e7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
5 changes: 2 additions & 3 deletions internal/apikeys/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@
package apikeys

import (
"crypto/sha256"
"encoding/base64"
"encoding/json"

"github.com/daytonaio/daytona/internal/util"
"github.com/google/uuid"
)

// returns the SHA-256 hash of a given key as a hexadecimal string.
func HashKey(key string) string {
keyHash := sha256.Sum256([]byte(key))
return string(keyHash[:])
return util.Hash(key)
}

func GenerateRandomKey() string {
Expand Down
11 changes: 11 additions & 0 deletions internal/util/hash.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright 2024 Daytona Platforms Inc.
// SPDX-License-Identifier: Apache-2.0

package util

import "crypto/sha256"

func Hash(value string) string {
hash := sha256.Sum256([]byte(value))
return string(hash[:])
}
3 changes: 2 additions & 1 deletion pkg/docker/create_devcontainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"strings"

"github.com/compose-spec/compose-go/v2/cli"
"github.com/daytonaio/daytona/internal/util"
"github.com/daytonaio/daytona/pkg/build/devcontainer"
"github.com/daytonaio/daytona/pkg/containerregistry"
"github.com/daytonaio/daytona/pkg/ssh"
Expand Down Expand Up @@ -150,7 +151,7 @@ func (d *DockerClient) CreateFromDevcontainer(opts CreateDevcontainerOptions) (s
return "", "", err
}

project.Name = fmt.Sprintf("%s-%s", opts.ProjectName, uuid.NewString())
project.Name = fmt.Sprintf("%s-%s", opts.ProjectName, util.Hash(opts.ProjectDir))

for _, service := range project.Services {
if service.Build != nil {
Expand Down

0 comments on commit f1432e7

Please sign in to comment.