feat: [CDE-332]: Update the gitspace setup scripts to support more OSes (#2873)

* 

feat: [CDE-332]: fix lint
* 

feat: [CDE-332]: Update the gitspace setup scripts to support more OSes
devcontainer-setup
Vikyath Harekal 2024-10-27 01:43:58 +00:00 committed by Harness
parent b5955c2da9
commit ad12a5d6f8
6 changed files with 90 additions and 19 deletions

View File

@ -1,7 +1,63 @@
#!/bin/sh
# Source the common OS info script
. ../../common/script/os_info.sh
# Detect OS type
os() {
uname="$(uname)"
case $uname in
Linux) echo linux ;;
Darwin) echo macos ;;
FreeBSD) echo freebsd ;;
*) echo "$uname" ;;
esac
}
# Detect Linux distro type
distro() {
local os_name
os_name=$(os)
if [ "$os_name" = "macos" ] || [ "$os_name" = "freebsd" ]; then
echo "$os_name"
return
fi
if [ -f /etc/os-release ]; then
(
. /etc/os-release
if [ "${ID_LIKE-}" ]; then
for id_like in $ID_LIKE; do
case "$id_like" in debian | fedora | opensuse | arch)
echo "$id_like"
return
;;
esac
done
fi
echo "$ID"
)
return
fi
}
# Print a human-readable name for the OS/distro
distro_name() {
if [ "$(uname)" = "Darwin" ]; then
echo "macOS v$(sw_vers -productVersion)"
return
fi
if [ -f /etc/os-release ]; then
(
. /etc/os-release
echo "$PRETTY_NAME"
)
return
fi
uname -sr
}
# Install Git if not already installed
install_git() {

View File

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

View File

@ -53,15 +53,17 @@ type RunVSCodeWebPayload struct {
}
type SetupUserPayload struct {
Username string
AccessKey string
AccessType enum.GitspaceAccessType
HomeDir string
Username string
AccessKey string
AccessType enum.GitspaceAccessType
HomeDir string
OSInfoScript string
}
type SetupSSHServerPayload struct {
Username string
AccessType enum.GitspaceAccessType
Username string
AccessType enum.GitspaceAccessType
OSInfoScript string
}
type RunSSHServerPayload struct {

View File

@ -1,12 +1,12 @@
#!/bin/sh
# Source the common OS info script
. ../../common/script/os_info.sh
username={{ .Username }}
accessKey="{{ .AccessKey }}"
homeDir={{ .HomeDir }}
accessType={{ .AccessType }}
osInfoScript={{ .OSInfoScript }}
eval "$osInfoScript"
# Check if the user already exists
if id "$username" >/dev/null 2>&1; then

View File

@ -1,7 +1,8 @@
#!/bin/sh
# Source the common OS info script
. ../../common/script/os_info.sh
osInfoScript={{ .OSInfoScript }}
eval "$osInfoScript"
# Install SSH if it's not already installed
if ! command -v sshd >/dev/null 2>&1; then

View File

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