* 1. user docker remote api instead of docker golang sdk to do stuff 2. remote gRPC code 3. simplify command * fix(dep): remove private import * chore(*): clean up * chore(*): clean up * chore(*): commit source * fix(test): * * fix(env): enable docker remote api * fix(env): enable docker remote api * chore(*): clean up * fix(ci): use machine to do build * fix(ci): use machine to do build * fix(ci): use machine to do build * fix(ci): use machine to do build * fix(ci): use machine to do build * fix(ci): use machine to do build * fix(ci): use machine to do build * fix(ci): use machine to do build * fix(ci): use machine to do build * fix(ci): use machine to do build * fix(ci): use machine to do build * fix(ci): use machine to do build * fix(ci): use machine to do build * fix(ci): use machine to do build * feat(timeout): longger timeout * fix(test): * * fix(typo): flag is name * chore(*): debug * chore(*): debug * chore(*): decrease test time * fix(type): disable call test since not well design yet * fix(typo): remove, * feat(images): pull images * fix(Pkg): using Pkg first * fix(Pkg): using Pkg first * feat(julia): fix version * chore(*): clean up * fix(file): ensure file exist * feat(http): remote http test * fix(circleci): fix deploy job * chore(*): update info * feat(init): update script * doc(architect): update readme * refactor(api): refactor api code * refacot(api): seperate version * refactor(build): service build as single file * feat(concurrent): down concurrent * refactor(api): refactor API * fix(endpoint): valid endpoint * fix(path): path change * feat(release): fix release script * fix(path): correct path * feat(api): seperate service run * fix(release): install goreleaser * fix(cc): fix cc * fix(releaser): install releaser from script outside of circleci config * fix(env): init logic move env * fix(cli): fix init * fix(env): avoid conflict * chore(*): update output * test(stop): add test for stop * feat(label):apply default label * doc(readme): update workflow graph * fix(init): should just start when container exist * feat(state): update container by state
56 lines
1.1 KiB
Go
56 lines
1.1 KiB
Go
package api
|
|
|
|
import (
|
|
"os/exec"
|
|
"sync"
|
|
|
|
"github.com/apex/log"
|
|
)
|
|
|
|
// Init init a host to be a fx running
|
|
func (api *API) Init() error {
|
|
// enable docker remote api
|
|
// docker run -d -v /var/run/docker.sock:/var/run/docker.sock -p 127.0.0.1:1234:1234 bobrik/socat TCP-LISTEN:1234,fork UNIX-CONNECT:/var/run/docker.sock
|
|
cmd := exec.Command(
|
|
"docker",
|
|
"run",
|
|
"-d",
|
|
"-v",
|
|
"/var/run/docker.sock:/var/run/docker.sock",
|
|
"-p",
|
|
"127.0.0.1:1234:1234",
|
|
"bobrik/socat",
|
|
"TCP-LISTEN:1234,fork",
|
|
"UNIX-CONNECT:/var/run/docker.sock",
|
|
)
|
|
stdoutStderr, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
log.Fatalf("Initialize Environment: %v", err)
|
|
return err
|
|
}
|
|
log.Infof("Initialize Environment: \u2713 %s", stdoutStderr)
|
|
|
|
baseImages := []string{
|
|
"metrue/fx-java-base",
|
|
"metrue/fx-julia-base",
|
|
"metrue/fx-python-base",
|
|
"metrue/fx-node-base",
|
|
"metrue/fx-d-base",
|
|
}
|
|
|
|
var wg sync.WaitGroup
|
|
for _, image := range baseImages {
|
|
wg.Add(1)
|
|
go func(img string) {
|
|
if err := api.pull(img); err != nil {
|
|
log.Fatalf("Pulling %s failed", img)
|
|
} else {
|
|
log.Infof("Pull %s ok", img)
|
|
}
|
|
wg.Done()
|
|
}(image)
|
|
}
|
|
|
|
return nil
|
|
}
|