feat: [CDE-332]: updated script for gitspace tools installation (#2874)

* feat: [CDE-332]: updated script for containers
* feat: [CDE-332]: updated scrpt for containers
This commit is contained in:
Ansuman Satapathy 2024-10-28 04:02:38 +00:00 committed by Harness
parent ad12a5d6f8
commit 1cb0e477f0
3 changed files with 32 additions and 12 deletions

View File

@ -0,0 +1,26 @@
// Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package common
import (
_ "embed"
)
//go:embed script/os_info.sh
var osDetectScript string
func GetOSInfoScript() (script string) {
return osDetectScript
}

View File

@ -17,9 +17,9 @@ package ide
import ( import (
"context" "context"
"fmt" "fmt"
"os"
"strconv" "strconv"
"github.com/harness/gitness/app/gitspace/orchestrator/common"
"github.com/harness/gitness/app/gitspace/orchestrator/devcontainer" "github.com/harness/gitness/app/gitspace/orchestrator/devcontainer"
"github.com/harness/gitness/app/gitspace/orchestrator/template" "github.com/harness/gitness/app/gitspace/orchestrator/template"
"github.com/harness/gitness/types" "github.com/harness/gitness/types"
@ -48,15 +48,12 @@ func (v *VSCode) Setup(
ctx context.Context, ctx context.Context,
exec *devcontainer.Exec, exec *devcontainer.Exec,
) ([]byte, error) { ) ([]byte, error) {
osInfoScript, err := os.ReadFile("app/gitspace/orchestrator/common/script/os_info.sh") osInfoScript := common.GetOSInfoScript()
if err != nil {
return nil, fmt.Errorf("failed to read os_info.sh: %w", err)
}
sshServerScript, err := template.GenerateScriptFromTemplate( sshServerScript, err := template.GenerateScriptFromTemplate(
templateSetupSSHServer, &template.SetupSSHServerPayload{ templateSetupSSHServer, &template.SetupSSHServerPayload{
Username: exec.UserIdentifier, Username: exec.UserIdentifier,
AccessType: exec.AccessType, AccessType: exec.AccessType,
OSInfoScript: string(osInfoScript), OSInfoScript: osInfoScript,
}) })
if err != nil { if err != nil {
return nil, fmt.Errorf( return nil, fmt.Errorf(

View File

@ -17,8 +17,8 @@ package user
import ( import (
"context" "context"
"fmt" "fmt"
"os"
"github.com/harness/gitness/app/gitspace/orchestrator/common"
"github.com/harness/gitness/app/gitspace/orchestrator/devcontainer" "github.com/harness/gitness/app/gitspace/orchestrator/devcontainer"
"github.com/harness/gitness/app/gitspace/orchestrator/template" "github.com/harness/gitness/app/gitspace/orchestrator/template"
) )
@ -35,17 +35,14 @@ func NewUserServiceImpl() Service {
} }
func (u *ServiceImpl) Manage(ctx context.Context, exec *devcontainer.Exec) ([]byte, error) { func (u *ServiceImpl) Manage(ctx context.Context, exec *devcontainer.Exec) ([]byte, error) {
osInfoScript, err := os.ReadFile("app/gitspace/orchestrator/common/script/os_info.sh") osInfoScript := common.GetOSInfoScript()
if err != nil {
return nil, fmt.Errorf("failed to read os_info.sh: %w", err)
}
script, err := template.GenerateScriptFromTemplate( script, err := template.GenerateScriptFromTemplate(
templateManagerUser, &template.SetupUserPayload{ templateManagerUser, &template.SetupUserPayload{
Username: exec.UserIdentifier, Username: exec.UserIdentifier,
AccessKey: exec.AccessKey, AccessKey: exec.AccessKey,
AccessType: exec.AccessType, AccessType: exec.AccessType,
HomeDir: exec.HomeDir, HomeDir: exec.HomeDir,
OSInfoScript: string(osInfoScript), OSInfoScript: osInfoScript,
}) })
if err != nil { if err != nil {
return nil, fmt.Errorf( return nil, fmt.Errorf(