This repository was archived by the owner on Sep 26, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathdocker.go
More file actions
76 lines (64 loc) · 1.34 KB
/
docker.go
File metadata and controls
76 lines (64 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package dockercompose
import (
"context"
"errors"
"fmt"
"io"
"io/fs"
"os"
"os/exec"
"path/filepath"
"github.com/creack/pty"
)
type Docker struct{}
func NewDocker() *Docker {
return &Docker{}
}
func (d *Docker) HasuraWrapper(
ctx context.Context,
subdomain,
nhostfolder,
hasuraVersion string,
exrtaArgs ...string,
) error {
absPath, err := filepath.Abs(nhostfolder)
if err != nil {
return fmt.Errorf("failed to get absolute path: %w", err)
}
args := []string{
"run",
"-v", absPath + ":/app",
"-e", "HASURA_GRAPHQL_ENABLE_TELEMETRY=false",
"-w", "/app",
"-it", "--rm",
"--entrypoint", "hasura-cli",
}
for _, host := range extraHosts(subdomain) {
args = append(args, "--add-host", host)
}
args = append(
args,
fmt.Sprintf("nhost/graphql-engine:%s.cli-migrations-v3", hasuraVersion),
)
cmd := exec.CommandContext( //nolint:gosec
ctx,
"docker",
append(args, exrtaArgs...)...,
)
f, err := pty.Start(cmd)
if err != nil {
return fmt.Errorf("failed to start pty: %w", err)
}
defer f.Close()
if n, err := io.Copy(os.Stdout, f); err != nil {
var pathError *fs.PathError
switch {
case errors.As(err, &pathError) && n > 0 && pathError.Op == op:
// linux pty returns an error when the process exits
return nil
default:
return fmt.Errorf("failed to copy pty output: %w", err)
}
}
return nil
}