Created
September 11, 2018 12:19
-
-
Save andscoop/3a30a42b8f977cc8f85cf5c6e0297afd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"log" | |
"os" | |
"strings" | |
dockercompose "github.com/docker/libcompose/docker" | |
"github.com/docker/libcompose/docker/ctx" | |
"github.com/docker/libcompose/project" | |
"github.com/docker/libcompose/project/options" | |
"github.com/sirupsen/logrus" | |
) | |
func main() { | |
yaml := strings.TrimSpace(` | |
version: '2' | |
services: | |
postgres: | |
image: postgres:10.1-alpine`) | |
// logger := logrus.New() | |
logrus.SetFormatter(&logrus.JSONFormatter{}) | |
logrus.SetOutput(os.Stdout) | |
logrus.SetLevel(logrus.WarnLevel) | |
// use logrus for standard log output: | |
// log.SetOutput(logrus.Writer()) | |
dctx := &ctx.Context{ | |
Context: project.Context{ | |
ComposeBytes: [][]byte{[]byte(yaml)}, | |
ProjectName: "test", | |
}, | |
} | |
prj, err := dockercompose.NewProject(dctx, nil) | |
if err != nil { | |
log.Fatal(err) | |
} | |
x := "start" | |
if x == "start" { | |
err = prj.Up(context.Background(), | |
options.Up{ | |
options.Create{ | |
ForceRecreate: true, | |
}, | |
}, | |
) | |
if err != nil { | |
log.Fatal(err) | |
} | |
} else { | |
err = prj.Down(context.Background(), options.Down{}) | |
if err != nil { | |
log.Fatal(err) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment