78 lines
1.7 KiB
Go
78 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
|
|
"localenv/client"
|
|
"localenv/collector"
|
|
"localenv/deployer"
|
|
"localenv/watchers"
|
|
|
|
"github.com/alecthomas/kingpin/v2"
|
|
"github.com/joho/godotenv"
|
|
"github.com/rs/zerolog"
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
var (
|
|
watch = kingpin.Flag("watch", "Enable docker local build watcher").Short('w').Bool()
|
|
)
|
|
|
|
func initLogger() {
|
|
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
|
|
log.Logger = log.With().Caller().Logger().Output(zerolog.ConsoleWriter{Out: os.Stderr})
|
|
}
|
|
|
|
func main() {
|
|
initLogger()
|
|
ctx := context.Background()
|
|
|
|
kingpin.Parse()
|
|
|
|
if err := godotenv.Load(".env"); err != nil {
|
|
log.Fatal().AnErr("err", err).Msg("unable to load .env file")
|
|
}
|
|
|
|
hostCLI, err := client.GetHostClient()
|
|
if err != nil {
|
|
log.Fatal().AnErr("err", err).Msg("unable to connect to the host dockerd")
|
|
}
|
|
|
|
d, err := deployer.NewDeployer(ctx, hostCLI)
|
|
if err != nil {
|
|
log.Fatal().AnErr("err", err).Msg("unable to initialize the deployer")
|
|
}
|
|
|
|
swarmCLI, err := d.GetSwarmCLI()
|
|
if err != nil {
|
|
log.Fatal().AnErr("err", err).Msg("unable to get the swarm client")
|
|
}
|
|
|
|
log.Info().Msg("you can now access the swarm ! `make enter`")
|
|
|
|
images := []string{}
|
|
images = append(images, deployer.ImagesDeps...)
|
|
|
|
c := collector.NewCollector(hostCLI, swarmCLI)
|
|
if err := c.DeployImages(ctx, images); err != nil {
|
|
log.Fatal().AnErr("err", err).Msg("unable to load/save IO images")
|
|
}
|
|
|
|
if err := d.Deploy(ctx); err != nil {
|
|
log.Fatal().AnErr("err", err).Msg("unable to deploy the environment")
|
|
}
|
|
|
|
log.Info().Msg("environment deployed")
|
|
|
|
watcher, errWatch := watchers.NewWatcher(ctx, hostCLI, swarmCLI)
|
|
if errWatch != nil {
|
|
log.Fatal().AnErr("err", errWatch).Msg("unable to initialize the watchers")
|
|
return
|
|
}
|
|
|
|
if *watch {
|
|
watcher.Watch()
|
|
}
|
|
}
|