mirror of
https://github.com/aljazceru/nigiri.git
synced 2025-12-17 14:24:20 +01:00
* clean * load datadir with resources and start compose * start --liquid * check if is running already * Add rpc command * Add logs and faucet commands * Add mint command * Add push command * Move state into dedicated pkg * less code for isRunning check * Add --ci flag to start command * Add NIGIRI_DATADIR env var * add update command * Update readme, makefile and goreleaser * update test gh action * skip tests * print endpoint in start command * Add a default network to docker compose file. Containers started through this docker compose file will be in this isolated network. Note: the minimum version for the docker compose file format is 3.5 which introduces `name` for networks. This file format requires a docker engine version of 17.12.0+. * add prerelease: auto * makefile: release commands * go version * use global flag --datadir for the folder * wrap datadir in variable * use single compose file & move state to internal * remove unused state keys * return err in test * docker-compose: use latest version * print endpoint of services based on --liquid flag Co-authored-by: Philipp Hoenisch <philipp@hoenisch.at>
77 lines
1.5 KiB
Go
77 lines
1.5 KiB
Go
package docker
|
|
|
|
import (
|
|
"errors"
|
|
"io/ioutil"
|
|
"strings"
|
|
|
|
"github.com/compose-spec/compose-go/loader"
|
|
)
|
|
|
|
func GetServices(composeFile string) ([][]string, error) {
|
|
|
|
composeBytes, err := ioutil.ReadFile(composeFile)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
parsed, err := loader.ParseYAML(composeBytes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if _, ok := parsed["services"]; !ok {
|
|
return nil, errors.New("missing services in compose")
|
|
}
|
|
|
|
serviceMap := parsed["services"].(map[string]interface{})
|
|
|
|
var services [][]string
|
|
for k, v := range serviceMap {
|
|
m := v.(map[string]interface{})
|
|
i := m["ports"].([]interface{})
|
|
for _, j := range i {
|
|
port := j.(string)
|
|
exposedPorts := strings.Split(port, ":")
|
|
endpoint := "localhost:" + exposedPorts[0]
|
|
services = append(services, []string{k, endpoint})
|
|
}
|
|
|
|
}
|
|
|
|
return services, nil
|
|
}
|
|
|
|
func GetPortsForService(composeFile string, serviceName string) ([]string, error) {
|
|
|
|
composeBytes, err := ioutil.ReadFile(composeFile)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
parsed, err := loader.ParseYAML(composeBytes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if _, ok := parsed["services"]; !ok {
|
|
return nil, errors.New("missing services in compose")
|
|
}
|
|
|
|
serviceMap := parsed["services"].(map[string]interface{})
|
|
|
|
var ports []string
|
|
for k, v := range serviceMap {
|
|
if k == serviceName {
|
|
m := v.(map[string]interface{})
|
|
i := m["ports"].([]interface{})
|
|
for _, j := range i {
|
|
port := j.(string)
|
|
ports = append(ports, port)
|
|
}
|
|
}
|
|
}
|
|
|
|
return ports, nil
|
|
}
|