Skip to content

Commit 637dbf0

Browse files
committed
Merge branch 'master' of https://github.com/raghavyuva/nixopus
2 parents 51aeee3 + df7fac8 commit 637dbf0

File tree

23 files changed

+933
-72
lines changed

23 files changed

+933
-72
lines changed

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
# [0.1.0-alpha.67](https://github.com/raghavyuva/nixopus/compare/v0.1.0-alpha.66...v0.1.0-alpha.67) (2025-11-21)
2+
3+
4+
### Features
5+
6+
* compose as extensions ([#555](https://github.com/raghavyuva/nixopus/issues/555)) ([741aa6a](https://github.com/raghavyuva/nixopus/commit/741aa6ab30520f46cc796c6510ea9c2551c4fd8e))
7+
8+
9+
10+
# [0.1.0-alpha.66](https://github.com/raghavyuva/nixopus/compare/v0.1.0-alpha.65...v0.1.0-alpha.66) (2025-11-21)
11+
12+
13+
### Bug Fixes
14+
15+
* allow custom ports on install setup optionally ([#580](https://github.com/raghavyuva/nixopus/issues/580)) ([972c7ac](https://github.com/raghavyuva/nixopus/commit/972c7ac4ea2aedd7810954772c4d16d7226182d6))
16+
17+
18+
119
# [0.1.0-alpha.65](https://github.com/raghavyuva/nixopus/compare/v0.1.0-alpha.64...v0.1.0-alpha.65) (2025-11-09)
220

321

api/internal/features/deploy/docker/init.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,8 @@ func (s *DockerService) ComposeUp(composeFilePath string, envVars map[string]str
331331
for k, v := range envVars {
332332
envVarsStr += fmt.Sprintf("export %s=%s && ", k, v)
333333
}
334-
command := fmt.Sprintf("%sdocker compose -f %s up -d", envVarsStr, composeFilePath)
334+
// Use --force-recreate to handle existing containers and --remove-orphans to clean up old containers
335+
command := fmt.Sprintf("%sdocker compose -f %s up -d --force-recreate --remove-orphans 2>&1", envVarsStr, composeFilePath)
335336
output, err := client.RunCommand(command)
336337
if err != nil {
337338
return fmt.Errorf("failed to start docker compose services: %v, output: %s", err, output)

api/internal/features/extension/engine/docker_compose.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ type dockerComposeModule struct{}
1414
func (dockerComposeModule) Type() string { return "docker_compose" }
1515

1616
func (dockerComposeModule) Execute(_ *ssh.SSH, step types.SpecStep, vars map[string]interface{}) (string, func(), error) {
17-
file, _ := step.Properties["file"].(string)
17+
fileRaw, _ := step.Properties["file"].(string)
1818
action, _ := step.Properties["action"].(string) // up, down, pull, build, restart
1919
_, _ = step.Properties["project"].(string)
2020
_, _ = step.Properties["args"].(string)
2121
revertCmdRaw, _ := step.Properties["revert_cmd"].(string)
2222
_, _ = step.Properties["user"].(string)
2323

24+
file := replaceVars(fileRaw, vars)
25+
2426
if action == "" {
2527
return "", nil, fmt.Errorf("docker_compose action is required")
2628
}

api/internal/features/extension/engine/file.go

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"io"
66
"os"
77
"path/filepath"
8+
"strings"
89

910
"github.com/pkg/sftp"
1011
"github.com/raghavyuva/nixopus-api/internal/features/ssh"
@@ -108,10 +109,36 @@ var actionHandlers = map[string]fileAction{
108109
"mkdir": handleMkdir,
109110
}
110111

112+
// expandTilde expands ~ to the actual home directory path for SFTP compatibility
113+
func expandTilde(path string, sshClient *ssh.SSH) string {
114+
if len(path) > 0 && path[0] == '~' {
115+
if len(path) == 1 || path[1] == '/' {
116+
// Get home directory via command
117+
homeOutput, err := sshClient.RunCommand("echo $HOME")
118+
if err == nil && len(homeOutput) > 0 {
119+
home := strings.TrimSpace(homeOutput)
120+
if len(path) == 1 {
121+
return home
122+
}
123+
return home + path[1:]
124+
}
125+
}
126+
}
127+
return path
128+
}
129+
111130
func (fileModule) Execute(sshClient *ssh.SSH, step types.SpecStep, vars map[string]interface{}) (string, func(), error) {
112131
action, _ := step.Properties["action"].(string)
113-
src, _ := step.Properties["src"].(string)
114-
dest, _ := step.Properties["dest"].(string)
132+
srcRaw, _ := step.Properties["src"].(string)
133+
destRaw, _ := step.Properties["dest"].(string)
134+
135+
// Replace variables in src and dest paths
136+
src := replaceVars(srcRaw, vars)
137+
dest := replaceVars(destRaw, vars)
138+
139+
// Expand tilde to $HOME for SFTP compatibility
140+
src = expandTilde(src, sshClient)
141+
dest = expandTilde(dest, sshClient)
115142

116143
if action == "mkdir" && dest == "" {
117144
return "", nil, fmt.Errorf("dest is required for mkdir action")

api/internal/features/extension/engine/package.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@ type packageModule struct{}
1313
func (packageModule) Type() string { return "package" }
1414

1515
func (packageModule) Execute(sshClient *ssh.SSH, step types.SpecStep, vars map[string]interface{}) (string, func(), error) {
16-
name, _ := step.Properties["name"].(string)
17-
state, _ := step.Properties["state"].(string)
16+
nameRaw, _ := step.Properties["name"].(string)
17+
stateRaw, _ := step.Properties["state"].(string)
18+
19+
name := replaceVars(nameRaw, vars)
20+
state := replaceVars(stateRaw, vars)
21+
1822
if name == "" {
1923
return "", nil, fmt.Errorf("package name is required")
2024
}

api/internal/features/extension/engine/service.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@ type serviceModule struct{}
1212
func (serviceModule) Type() string { return "service" }
1313

1414
func (serviceModule) Execute(sshClient *ssh.SSH, step types.SpecStep, vars map[string]interface{}) (string, func(), error) {
15-
name, _ := step.Properties["name"].(string)
15+
nameRaw, _ := step.Properties["name"].(string)
1616
action, _ := step.Properties["action"].(string)
1717
revertAction, _ := step.Properties["revert_action"].(string)
18-
runAsUser, _ := step.Properties["user"].(string)
18+
runAsUserRaw, _ := step.Properties["user"].(string)
19+
20+
name := replaceVars(nameRaw, vars)
21+
runAsUser := replaceVars(runAsUserRaw, vars)
22+
1923
if name == "" {
2024
return "", nil, fmt.Errorf("service name is required for service step")
2125
}

api/internal/features/extension/engine/user.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,18 @@ type userModule struct{}
1313
func (userModule) Type() string { return "user" }
1414

1515
func (userModule) Execute(sshClient *ssh.SSH, step types.SpecStep, vars map[string]interface{}) (string, func(), error) {
16-
username, _ := step.Properties["username"].(string)
16+
usernameRaw, _ := step.Properties["username"].(string)
1717
action, _ := step.Properties["action"].(string)
18-
shell, _ := step.Properties["shell"].(string)
19-
home, _ := step.Properties["home"].(string)
20-
groups, _ := step.Properties["groups"].(string)
18+
shellRaw, _ := step.Properties["shell"].(string)
19+
homeRaw, _ := step.Properties["home"].(string)
20+
groupsRaw, _ := step.Properties["groups"].(string)
2121
revertAction, _ := step.Properties["revert_action"].(string)
2222

23+
username := replaceVars(usernameRaw, vars)
24+
shell := replaceVars(shellRaw, vars)
25+
home := replaceVars(homeRaw, vars)
26+
groups := replaceVars(groupsRaw, vars)
27+
2328
if username == "" {
2429
return "", nil, fmt.Errorf("username is required for user operations")
2530
}

api/internal/features/ssh/init.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,11 @@ func (s *SSH) RunCommand(cmd string) (string, error) {
135135
if err != nil {
136136
return "", err
137137
}
138-
output, err := client.Run(cmd)
138+
defer client.Close()
139139

140+
output, err := client.Run(cmd)
140141
if err != nil {
141-
return "", err
142+
return string(output), err
142143
}
143144

144145
return string(output), nil

0 commit comments

Comments
 (0)