docker / libcompose

*Unmaintained/Deprecated* An experimental go library providing Compose-like functionality
https://godoc.org/github.com/docker/libcompose
Apache License 2.0
584 stars 191 forks source link

Could not parse config for project which was created by the same lib #486

Closed mindaugasrukas closed 6 years ago

mindaugasrukas commented 7 years ago

Errors:

Demo code:

package main

import (
    "github.com/docker/libcompose/config"
    "github.com/docker/libcompose/docker"
    "github.com/docker/libcompose/docker/ctx"
    "github.com/docker/libcompose/project"
    "github.com/docker/libcompose/project/options"
    "golang.org/x/net/context"
)

func DemoUp() error {
    dcProject, err := docker.NewProject(&ctx.Context{
        Context: project.Context{
            ProjectName:  "demo",
        },
    }, nil)
    if err != nil {
        return err
    }

    dcProject.AddConfig("my-service", &config.ServiceConfig{
        Image: "busybox",
        Command: []string{"top"},
    })

    data, err := dcProject.Config()
    if err != nil {
        return err
    }
    err = fs.WriteFile("/tmp/docker-compose.yaml", []byte(data), 0644)
    if err != nil {
        return err
    }

    err = dcProject.Up(context.Background(), options.Up{})
    if err != nil {
        return err
    }

    return nil
}

func DemoDown() error {
    dcProject, err := docker.NewProject(&ctx.Context{
        Context: project.Context{
            ComposeFiles: []string{"/tmp/docker-compose.yaml"},
            ProjectName:  "demo",
        },
    }, nil)
    if err != nil {
        return err
    }

    err = dcProject.Down(context.Background(), options.Down{})
    if err != nil {
        return err
    }

    return nil
}
$ go run main.go demo-up
INFO[0000] [0/1] [my-service]: Starting
INFO[0001] [1/1] [my-service]: Started

$ docker ps
CONTAINER ID        IMAGE                           COMMAND                  CREATED             STATUS              PORTS                  NAMES
db37410074fe        busybox                         "top"                    7 seconds ago       Up 6 seconds                               demo_my-service_1

$ docker network ls
NETWORK ID          NAME                DRIVER              SCOPE
60b7ddafe95e        bridge              bridge              local
aeba63d58e84        host                host                local
cd2ddef376a8        none                null                local

$ cat /tmp/docker-compose.yaml
version: "2.0"
services:
  my-service:
    command: [top]
    image: busybox
volumes: {}
networks: {}

$ go run main.go demo-down
ERRO[0000] Could not parse config for project demo : yaml: unmarshal errors:
  line 1: cannot unmarshal !!str `2.0` into config.RawService
FATA[0000] yaml: unmarshal errors:
  line 1: cannot unmarshal !!str `2.0` into config.RawService
exit status 1

$ sed -i "" "s/2\.0/2/" /tmp/docker-compose.yaml

$ cat /tmp/docker-compose.yaml
version: "2"
services:
  my-service:
    command: [top]
    image: busybox
volumes: {}
networks: {}

$ go run main.go demo-down
INFO[0000] [0/1] [my-service]: Stopping
INFO[0000] [0/1] [my-service]: Stopped
INFO[0000] [0/1] [my-service]: Deleting
INFO[0000] [0/1] [my-service]: Deleted
Removing network "demo_default"
FATA[0000] Error response from daemon: network demo_default not found
exit status 1
$ docker version
Client:
 Version:      17.06.0-ce
 API version:  1.30
 Go version:   go1.8.3
 Git commit:   02c1d87
 Built:        Fri Jun 23 21:31:53 2017
 OS/Arch:      darwin/amd64

Server:
 Version:      17.06.0-ce
 API version:  1.30 (minimum version 1.12)
 Go version:   go1.8.3
 Git commit:   02c1d87
 Built:        Fri Jun 23 21:51:55 2017
 OS/Arch:      linux/amd64
 Experimental: true
$ docker info
Containers: 6
 Running: 2
 Paused: 0
 Stopped: 4
Images: 25
Server Version: 17.06.0-ce
Storage Driver: aufs
 Root Dir: /var/lib/docker/aufs
 Backing Filesystem: extfs
 Dirs: 103
 Dirperm1 Supported: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host ipvlan macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: cfb82a876ecc11b5ca0977d1733adbe58599088a
runc version: 2d41c047c83e09a6d61d464906feb2a2f3c52aa4
init version: 949e6fa
Security Options:
 seccomp
  Profile: default
Kernel Version: 4.9.36-moby
Operating System: Alpine Linux v3.5
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 1.952GiB
Name: moby
ID: BJGS:7EF7:7EAU:73SZ:6WKS:ALLX:IBH5:LHDY:TNCD:DNY3:BW2F:FPBO
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): true
 File Descriptors: 35
 Goroutines: 54
 System Time: 2017-08-10T08:43:43.20168146Z
 EventsListeners: 1
Registry: https://index.docker.io/v1/
Experimental: true
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false
$ uname -mprsv
Darwin 16.6.0 Darwin Kernel Version 16.6.0: Fri Apr 14 16:21:16 PDT 2017; root:xnu-3789.60.24~6/RELEASE_X86_64 x86_64 i386
CpuID commented 6 years ago

This can be closed thanks to https://github.com/docker/libcompose/pull/507