Skip to content

Commit 3e210d1

Browse files
committed
Merge branch '403-inside-container' into 'master'
fix(engine): detect if DLE is running in a Docker container (#403) See merge request postgres-ai/database-lab!571
2 parents c15fdbf + dcf5f17 commit 3e210d1

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

engine/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ require (
1414
github.com/dustin/go-humanize v1.0.0
1515
github.com/golang-jwt/jwt/v4 v4.4.2
1616
github.com/google/go-github/v34 v34.0.0
17+
github.com/google/uuid v1.3.0
1718
github.com/gorilla/mux v1.8.0
1819
github.com/gorilla/websocket v1.4.2
1920
github.com/jackc/pgtype v1.5.0
@@ -47,7 +48,6 @@ require (
4748
github.com/gogo/protobuf v1.3.2 // indirect
4849
github.com/golang/protobuf v1.5.2 // indirect
4950
github.com/google/go-querystring v1.0.0 // indirect
50-
github.com/google/uuid v1.3.0 // indirect
5151
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
5252
github.com/jackc/pgconn v1.7.0 // indirect
5353
github.com/jackc/pgio v1.0.0 // indirect

engine/internal/diagnostic/logs.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,9 @@ func extractTar(dir string, reader *tar.Reader, header *tar.Header) error {
249249
}
250250

251251
defer func() {
252-
err = f.Close()
253-
log.Err("Failed to close TAR stream", err)
252+
if err := f.Close(); err != nil {
253+
log.Err("Failed to close TAR stream", err)
254+
}
254255
}()
255256

256257
if _, err := io.Copy(f, reader); err != nil {

engine/internal/retrieval/engine/postgres/tools/tools.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func AddVolumesToHostConfig(ctx context.Context, docker *client.Client, hostConf
134134

135135
log.Dbg("Virtualization system: ", hostInfo.VirtualizationSystem)
136136

137-
if hostInfo.VirtualizationRole == "guest" {
137+
if IsInDocker() {
138138
inspection, err := docker.ContainerInspect(ctx, hostInfo.Hostname)
139139
if err != nil {
140140
return err
@@ -632,3 +632,12 @@ func CopyContainerLogs(ctx context.Context, docker *client.Client, containerName
632632

633633
return nil
634634
}
635+
636+
// IsInDocker checks if the DLE process is running inside Docker container.
637+
func IsInDocker() bool {
638+
if _, err := os.Stat("/.dockerenv"); err == nil {
639+
return true
640+
}
641+
642+
return false
643+
}

0 commit comments

Comments
 (0)