From 45bc90b940c9c9939c82dd40f8408497284f5eb0 Mon Sep 17 00:00:00 2001 From: rmanach Date: Fri, 2 May 2025 10:10:50 +0200 Subject: [PATCH] update README.md + few fixes --- README.md | 21 +++++++++++++-------- deployers/swarm.go | 6 +++--- hmdeploy.example.json | 3 ++- main.go | 4 ++-- models/project.go | 10 +++++----- 5 files changed, 25 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 385e338..1b80b1f 100644 --- a/README.md +++ b/README.md @@ -86,19 +86,24 @@ func (hm *HMMap) GetSwarmNetInfo() *HMNetInfo { * In your project root directory, create a `.homeserver` directory with a configuration file: `hmdeploy.json`: ```json { - "name": "", - "image": ":", + "name": "my-api", "dependencies": { - "env": "", - "compose": "", - "nginx": "" + "swarm": { + "env": ".env", + "compose": "docker-compose.deploy.yml", + "images": ["my-local-image:tag"] + }, + "nginx": { + "conf": "nginx.conf", + "assets": "assets/" + } } } ``` The filepaths can be absolute or relative. If the filename is only mentionned, it assumes the corresponding files are inside the `.homeserver` dir of your project. -The **image**, **env** and **nginx** fields are optionals. -If you have a Docker registry with the target image available, you can thus leave image empty. It is used if you want to push a local image or don't have a docker registry. +All **dependencies** fields are optionals. If you don't need swarm skip it, if you don't need .env skip it, if you don't nginx... You see the trick. +If you have a Docker registry with the target image available, you can thus leave **images** field empty. It is used if you want to push a local image or don't have a docker registry. ## Run @@ -131,7 +136,7 @@ Usage of hmdeploy: -path string define the .homeserver project root dir (default ".") -version - extract swarm details and return + show program version and return # if your are in the project dir with a `.homeserver` # you can then launch the program directly diff --git a/deployers/swarm.go b/deployers/swarm.go index 432cf0c..746e212 100644 --- a/deployers/swarm.go +++ b/deployers/swarm.go @@ -109,8 +109,8 @@ func (sd *SwarmDeployer) Build() error { log.Info().Msg("building swarm archive for deployment...") filesToArchive := []string{} - for idx := range sd.project.ImageNames { - tarFile, err := sd.dloc.Save(sd.project.ImageNames[idx], sd.project.Dir) + for idx := range sd.project.Deps.Swarm.ImageNames { + tarFile, err := sd.dloc.Save(sd.project.Deps.Swarm.ImageNames[idx], sd.project.Dir) if err != nil { sd.setDone(err) return err @@ -172,7 +172,7 @@ func (sd *SwarmDeployer) Deploy() error { log.Info().Str("archive", sd.archivePath).Msg("deploying archive to swarm...") - if err := sd.drem.LoadImages(sd.project.ImageNames...); err != nil { + if err := sd.drem.LoadImages(sd.project.Deps.Swarm.ImageNames...); err != nil { sd.setDone(err) return err } diff --git a/hmdeploy.example.json b/hmdeploy.example.json index c4f1133..9349192 100644 --- a/hmdeploy.example.json +++ b/hmdeploy.example.json @@ -3,7 +3,8 @@ "dependencies": { "swarm": { "env": ".env", - "compose": "docker-compose.deploy.yml" + "compose": "docker-compose.deploy.yml", + "images": [] }, "nginx": { "conf": "nginx.conf", diff --git a/main.go b/main.go index d11fe19..7196c5a 100644 --- a/main.go +++ b/main.go @@ -418,7 +418,7 @@ func getSwarmServicesDetails(hm *models.HMMap) error { return nil } -func main() { //nolint: funlen //TODO: to reduce +func main() { //nolint: funlen // TODO: to reduce ctx, fnCancel := signal.NotifyContext( context.Background(), os.Interrupt, @@ -431,7 +431,7 @@ func main() { //nolint: funlen //TODO: to reduce noSwarm := flag.Bool("no-swarm", false, "no Swarm deployment") debug := flag.Bool("debug", false, "show debug logs") details := flag.Bool("details", false, "extract swarm details and return") - version := flag.Bool("version", false, "extract swarm details and return") + version := flag.Bool("version", false, "show program version and return") confirm := flag.Bool( "confirm", false, diff --git a/models/project.go b/models/project.go index 25f3f9f..f6e5f68 100644 --- a/models/project.go +++ b/models/project.go @@ -89,16 +89,16 @@ type Project struct { Name string `json:"name"` Dir string Deps struct { - Swarm struct { - EnvFile string `json:"env"` - ComposeFile string `json:"compose"` - } `json:"swarm"` Nginx struct { Conf string `json:"conf"` Assets string `json:"assets"` } + Swarm struct { + EnvFile string `json:"env"` + ComposeFile string `json:"compose"` + ImageNames []string `json:"images"` + } `json:"swarm"` } `json:"dependencies"` - ImageNames []string `json:"images"` } func (p *Project) validate() error {