Skip to content

Commit

Permalink
fix: unmarshall infor and config
Browse files Browse the repository at this point in the history
  • Loading branch information
achettyiitr committed Sep 6, 2023
1 parent 5dd39d3 commit a290fc4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 38 deletions.
36 changes: 24 additions & 12 deletions compose/compose.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package compose

import (
"bufio"
"context"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -219,16 +220,20 @@ func (c *Compose) config(ctx context.Context, id ...string) ([]containerConfig,
return nil, fmt.Errorf("docker inspect: output: %s, err: %w", string(o), err)
}

lines := strings.Split(strings.TrimSpace(string(o)), "\n")
var configs []containerConfig

configs := make([]containerConfig, len(lines))
for i, l := range lines {
err = json.Unmarshal([]byte(l), &configs[i])
if err != nil {
return nil, fmt.Errorf("docker inspect: unmarshal: config: %s, err: %w", l, err)
}
if err = json.Unmarshal(o, &configs); err == nil {
return configs, nil
}

scanner := bufio.NewScanner(strings.NewReader(string(o)))
for scanner.Scan() {
var config containerConfig
if err = json.Unmarshal(scanner.Bytes(), &config); err != nil {
return nil, fmt.Errorf("docker inspect: unmarshal: config: %s, err: %w", scanner.Text(), err)
}
configs = append(configs, config)
}
return configs, nil
}

Expand All @@ -245,11 +250,18 @@ func (c *Compose) ps(ctx context.Context) ([]containerInfo, error) {
return nil, fmt.Errorf("docker compose ps: output: %s, err: %w", string(o), err)
}

var info []containerInfo
err = json.Unmarshal(o, &info)
if err != nil {
return nil, fmt.Errorf("docker compose ps: unmarshal: output: %s, err: %w", string(o), err)
var infos []containerInfo
if err = json.Unmarshal(o, &infos); err == nil {
return infos, nil
}

return info, nil
scanner := bufio.NewScanner(strings.NewReader(string(o)))
for scanner.Scan() {
var info containerInfo
if err = json.Unmarshal(scanner.Bytes(), &info); err != nil {
return nil, fmt.Errorf("docker compose ps: unmarshal: info: %s, err: %w", scanner.Text(), err)
}
infos = append(infos, info)
}
return infos, nil
}
27 changes: 1 addition & 26 deletions compose/testdata/docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "2.1"
version: "3.9"

services:
postgresDB:
Expand All @@ -12,29 +12,4 @@ services:
healthcheck:
test: [ "CMD-SHELL", "pg_isready" ]
interval: 1s
retries: 25
labels:
compose-test-expose.DB_DSN: "postgresql://rudder:password@localhost:{port:5432}/jobsdb"
transformer:
image: rudderlabs/develop-rudder-transformer:master
ports:
- "9090"
minio:
image: minio/minio:latest
ports:
- "9000/tcp"
environment:
- MINIO_ACCESS_KEY=MYACCESSKEY
- MINIO_SECRET_KEY=MYSECRETKEY
command: server /data
healthcheck:
test: curl --fail http://localhost:9000/minio/health/live || exit 1
interval: 1s
retries: 25
zookeeper:
image: zookeeper:3.5
hostname: clickhouse-zookeeper
healthcheck:
test: nc -z localhost 2181 || exit 1
interval: 1s
retries: 25

0 comments on commit a290fc4

Please sign in to comment.