Compare commits
	
		
			No commits in common. "develop" and "main" have entirely different histories.
		
	
	
		
	
		
							
								
								
									
										6
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								Makefile
									
									
									
									
									
								
							| @ -3,10 +3,10 @@ BIN_INSTALL = $(shell whereis $(BIN_NAME) | cut -d ' ' -f2) | |||||||
| 
 | 
 | ||||||
| VERSION = 0.1.1 | VERSION = 0.1.1 | ||||||
| 
 | 
 | ||||||
| run: check | run: lint | ||||||
| 	@go run main.go | 	@go run main.go | ||||||
| 
 | 
 | ||||||
| build: check | build: lint | ||||||
| 	@echo "building binary..." | 	@echo "building binary..." | ||||||
| 	@CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w -X main.Version=$(VERSION)" -o $(BIN_NAME) main.go && echo "$(BIN_NAME) v$(VERSION) built" | 	@CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w -X main.Version=$(VERSION)" -o $(BIN_NAME) main.go && echo "$(BIN_NAME) v$(VERSION) built" | ||||||
| 
 | 
 | ||||||
| @ -16,7 +16,7 @@ install: build | |||||||
| 	@echo "program installed: $(GOPATH)/bin/hmdeploy" | 	@echo "program installed: $(GOPATH)/bin/hmdeploy" | ||||||
| 	@$(GOPATH)/bin/hmdeploy --version | 	@$(GOPATH)/bin/hmdeploy --version | ||||||
| 
 | 
 | ||||||
| check: | lint: | ||||||
| 	@echo "format and lint..." | 	@echo "format and lint..." | ||||||
| 	@golangci-lint fmt ./... | 	@golangci-lint fmt ./... | ||||||
| 	@golangci-lint run ./... | 	@golangci-lint run ./... | ||||||
							
								
								
									
										28
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										28
									
								
								README.md
									
									
									
									
									
								
							| @ -38,6 +38,14 @@ It has a nice logging and clean all the ressources (succeed or failed). | |||||||
| * Create a file inside named: `map.json`. This file will contain all network informations of your instances. | * Create a file inside named: `map.json`. This file will contain all network informations of your instances. | ||||||
| ```json | ```json | ||||||
| { | { | ||||||
|  | 	"ip": "<proxmox-ip>", | ||||||
|  | 	"web_url": "https://<proxmox-ip>:8006", | ||||||
|  | 	"ssh": { | ||||||
|  | 		"user": "<ssh-user>", | ||||||
|  | 		"privkey": "<path-to-ssh-private-key>", | ||||||
|  | 		"port": <proxmox-ssh-port> | ||||||
|  | 	}, | ||||||
|  | 	"vm": { | ||||||
| 		"swarm": { | 		"swarm": { | ||||||
| 			"ip": "<swarm-ip>", | 			"ip": "<swarm-ip>", | ||||||
| 			"ssh": { | 			"ssh": { | ||||||
| @ -45,7 +53,9 @@ It has a nice logging and clean all the ressources (succeed or failed). | |||||||
|                 "privkey": "<path-to-ssh-private-key>", |                 "privkey": "<path-to-ssh-private-key>", | ||||||
|                 "port": <swarm-ssh-port> |                 "port": <swarm-ssh-port> | ||||||
| 			} | 			} | ||||||
|  | 		} | ||||||
| 	}, | 	}, | ||||||
|  | 	"lxc": { | ||||||
| 		"nginx": { | 		"nginx": { | ||||||
| 			"ip": "<nginx-ip>", | 			"ip": "<nginx-ip>", | ||||||
| 			"web_url": "https://<nginx-ip>", | 			"web_url": "https://<nginx-ip>", | ||||||
| @ -56,9 +66,23 @@ It has a nice logging and clean all the ressources (succeed or failed). | |||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  | } | ||||||
| ``` | ``` | ||||||
| Below an example of a configuration. Of course you must ensure that the user public key has been deployed on the `<ssh-user>` server. | Below an example of a configuration. Of course you must ensure that the user public key has been deployed on the `<ssh-user>` server. | ||||||
| 
 | 
 | ||||||
|  | You may notice the configuration has two distincts keys: **vm** and **lxc**. And, obviously, it refers to a virtual machine and a linux container. | ||||||
|  | For convience, **Docker Swarm** is installed on a **vm** to ensure a strong isolated environment. If you decided for an LXC, you have to update this section of the code and rebuild the binary: | ||||||
|  | ```go | ||||||
|  | func (hm *HMMap) GetSwarmNetInfo() *HMNetInfo { | ||||||
|  | 	data, ok := hm.VM["swarm"] // update to hm.LXC["swarm] | ||||||
|  | 	if !ok { | ||||||
|  | 		return nil | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	return data | ||||||
|  | } | ||||||
|  | ``` | ||||||
|  | 
 | ||||||
| * In your project root directory, create a `.homeserver` directory with a configuration file: `hmdeploy.json`: | * In your project root directory, create a `.homeserver` directory with a configuration file: `hmdeploy.json`: | ||||||
| ```json | ```json | ||||||
| { | { | ||||||
| @ -87,7 +111,7 @@ If you have a Docker registry with the target image available, you can thus leav | |||||||
| 
 | 
 | ||||||
| * Clone the repository | * Clone the repository | ||||||
| ```bash | ```bash | ||||||
| git clone https://gitea.sonak.fr/rmanach/hmdeploy | git clone https://gitea.thegux.fr/rmanach/hmdeploy | ||||||
| ``` | ``` | ||||||
| * Install the binary | * Install the binary | ||||||
| ```bash | ```bash | ||||||
| @ -100,7 +124,7 @@ The binary is then installed in your **$GOPATH/bin**. | |||||||
| hmdeploy --help | hmdeploy --help | ||||||
| Usage of hmdeploy: | Usage of hmdeploy: | ||||||
|   -config string |   -config string | ||||||
|         define the configuration directory (default "/home/<user>/.homeserver") |         define the configuration directory (default "/home/romain/.homeserver") | ||||||
|   -confirm |   -confirm | ||||||
|         do not ask for confirmation, you're the best, you don't need confirmation |         do not ask for confirmation, you're the best, you don't need confirmation | ||||||
|   -debug |   -debug | ||||||
|  | |||||||
| @ -9,8 +9,8 @@ import ( | |||||||
| 	"sync/atomic" | 	"sync/atomic" | ||||||
| 	"time" | 	"time" | ||||||
| 
 | 
 | ||||||
| 	"gitea.sonak.fr/hmdeploy/connection" | 	"gitea.thegux.fr/hmdeploy/connection" | ||||||
| 	"gitea.sonak.fr/hmdeploy/models" | 	"gitea.thegux.fr/hmdeploy/models" | ||||||
| 	"github.com/rs/zerolog/log" | 	"github.com/rs/zerolog/log" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -5,8 +5,8 @@ import ( | |||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"path/filepath" | 	"path/filepath" | ||||||
| 
 | 
 | ||||||
| 	"gitea.sonak.fr/hmdeploy/models" | 	"gitea.thegux.fr/hmdeploy/models" | ||||||
| 	"gitea.sonak.fr/hmdeploy/utils" | 	"gitea.thegux.fr/hmdeploy/utils" | ||||||
| 	"github.com/rs/zerolog/log" | 	"github.com/rs/zerolog/log" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -7,10 +7,10 @@ import ( | |||||||
| 	"os" | 	"os" | ||||||
| 	"path/filepath" | 	"path/filepath" | ||||||
| 
 | 
 | ||||||
| 	"gitea.sonak.fr/hmdeploy/connection" | 	"gitea.thegux.fr/hmdeploy/connection" | ||||||
| 	"gitea.sonak.fr/hmdeploy/docker" | 	"gitea.thegux.fr/hmdeploy/docker" | ||||||
| 	"gitea.sonak.fr/hmdeploy/models" | 	"gitea.thegux.fr/hmdeploy/models" | ||||||
| 	"gitea.sonak.fr/hmdeploy/utils" | 	"gitea.thegux.fr/hmdeploy/utils" | ||||||
| 	"github.com/rs/zerolog/log" | 	"github.com/rs/zerolog/log" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -11,8 +11,8 @@ import ( | |||||||
| 	"sync" | 	"sync" | ||||||
| 	"time" | 	"time" | ||||||
| 
 | 
 | ||||||
| 	"gitea.sonak.fr/hmdeploy/connection" | 	"gitea.thegux.fr/hmdeploy/connection" | ||||||
| 	"gitea.sonak.fr/hmdeploy/models" | 	"gitea.thegux.fr/hmdeploy/models" | ||||||
| 	"github.com/rs/zerolog/log" | 	"github.com/rs/zerolog/log" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -188,11 +188,6 @@ func (s *Service) UnmarshalJSON(data []byte) error { | |||||||
| 		imageName = imageNameParts[0] | 		imageName = imageNameParts[0] | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	tag := "..." |  | ||||||
| 	if len(imageNameParts) > 1 { |  | ||||||
| 		tag = imageNameParts[1] |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	appName := ci.Details[0].Spec.Labels.Namespace | 	appName := ci.Details[0].Spec.Labels.Namespace | ||||||
| 
 | 
 | ||||||
| 	*s = Service{ | 	*s = Service{ | ||||||
| @ -204,7 +199,7 @@ func (s *Service) UnmarshalJSON(data []byte) error { | |||||||
| 			Tag  string | 			Tag  string | ||||||
| 		}{ | 		}{ | ||||||
| 			Name: imageName, | 			Name: imageName, | ||||||
| 			Tag:  tag, | 			Tag:  imageNameParts[1], | ||||||
| 		}, | 		}, | ||||||
| 		Networks: networks, | 		Networks: networks, | ||||||
| 		Ports:    ci.Details[0].Endpoint.Ports, | 		Ports:    ci.Details[0].Endpoint.Ports, | ||||||
|  | |||||||
							
								
								
									
										2
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								go.mod
									
									
									
									
									
								
							| @ -1,4 +1,4 @@ | |||||||
| module gitea.sonak.fr/hmdeploy | module gitea.thegux.fr/hmdeploy | ||||||
| 
 | 
 | ||||||
| go 1.23.0 | go 1.23.0 | ||||||
| 
 | 
 | ||||||
|  | |||||||
							
								
								
									
										20
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								main.go
									
									
									
									
									
								
							| @ -13,11 +13,11 @@ import ( | |||||||
| 	"strings" | 	"strings" | ||||||
| 	"sync" | 	"sync" | ||||||
| 
 | 
 | ||||||
| 	"gitea.sonak.fr/hmdeploy/deployers" | 	"gitea.thegux.fr/hmdeploy/deployers" | ||||||
| 	"gitea.sonak.fr/hmdeploy/docker" | 	"gitea.thegux.fr/hmdeploy/docker" | ||||||
| 	"gitea.sonak.fr/hmdeploy/models" | 	"gitea.thegux.fr/hmdeploy/models" | ||||||
| 	"gitea.sonak.fr/hmdeploy/scheduler" | 	"gitea.thegux.fr/hmdeploy/scheduler" | ||||||
| 	"gitea.sonak.fr/hmdeploy/utils" | 	"gitea.thegux.fr/hmdeploy/utils" | ||||||
| 	"github.com/rs/zerolog" | 	"github.com/rs/zerolog" | ||||||
| 	"github.com/rs/zerolog/log" | 	"github.com/rs/zerolog/log" | ||||||
| ) | ) | ||||||
| @ -108,8 +108,8 @@ func (d *Deployers) generateDeployTasks() scheduler.Tasks { | |||||||
| 
 | 
 | ||||||
| 	// only swarm deployer | 	// only swarm deployer | ||||||
| 	if d.sd != nil && d.nd == nil { | 	if d.sd != nil && d.nd == nil { | ||||||
| 		rootTask := scheduler.NewTask("swarm-build", d.sd.Build) | 		rootTask := scheduler.NewTask("swarm-build", d.nd.Build) | ||||||
| 		rootTask.AddNext(scheduler.NewTask("swarm-deploy", d.sd.Deploy)) | 		rootTask.AddNext(scheduler.NewTask("swarm-deploy", d.nd.Deploy)) | ||||||
| 
 | 
 | ||||||
| 		tasks = append(tasks, rootTask) | 		tasks = append(tasks, rootTask) | ||||||
| 		return tasks | 		return tasks | ||||||
| @ -293,7 +293,7 @@ func initDeployers( | |||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if !opt.noSwarm && project.GetComposePath() != "" { | 	if !opt.noSwarm && project.GetComposePath() != "" { | ||||||
| 		swarmNet := hmmap.Swarm | 		swarmNet := hmmap.GetSwarmNetInfo() | ||||||
| 		if swarmNet == nil { | 		if swarmNet == nil { | ||||||
| 			return deps, fmt.Errorf("%w, swarm net info does not exist", ErrNetInfoNotFound) | 			return deps, fmt.Errorf("%w, swarm net info does not exist", ErrNetInfoNotFound) | ||||||
| 		} | 		} | ||||||
| @ -307,7 +307,7 @@ func initDeployers( | |||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if !opt.noNginx && project.GetNginxConfPath() != "" { | 	if !opt.noNginx && project.GetNginxConfPath() != "" { | ||||||
| 		nginxNet := hmmap.Nginx | 		nginxNet := hmmap.GetNginxNetInfo() | ||||||
| 		if nginxNet == nil { | 		if nginxNet == nil { | ||||||
| 			return deps, fmt.Errorf("%w, nginx net info does not exist", ErrNetInfoNotFound) | 			return deps, fmt.Errorf("%w, nginx net info does not exist", ErrNetInfoNotFound) | ||||||
| 		} | 		} | ||||||
| @ -332,7 +332,7 @@ func initDeployers( | |||||||
| 
 | 
 | ||||||
| //nolint:funlen,mnd // TODO(rmanach): could be splitted | //nolint:funlen,mnd // TODO(rmanach): could be splitted | ||||||
| func getSwarmServicesDetails(hm *models.HMMap) error { | func getSwarmServicesDetails(hm *models.HMMap) error { | ||||||
| 	swarmNet := hm.Swarm | 	swarmNet := hm.GetSwarmNetInfo() | ||||||
| 	if swarmNet == nil { | 	if swarmNet == nil { | ||||||
| 		return fmt.Errorf("%w, swarm net info does not exist", ErrNetInfoNotFound) | 		return fmt.Errorf("%w, swarm net info does not exist", ErrNetInfoNotFound) | ||||||
| 	} | 	} | ||||||
|  | |||||||
							
								
								
									
										28
									
								
								models/hm.go
									
									
									
									
									
								
							
							
						
						
									
										28
									
								
								models/hm.go
									
									
									
									
									
								
							| @ -14,8 +14,32 @@ type HMNetInfo struct { | |||||||
| 	} `json:"ssh,omitempty"` | 	} `json:"ssh,omitempty"` | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | type ( | ||||||
|  | 	HMVM  map[string]*HMNetInfo | ||||||
|  | 	HMLXC map[string]*HMNetInfo | ||||||
|  | ) | ||||||
|  | 
 | ||||||
| // HMMap handles all the informations of your home server instances. | // HMMap handles all the informations of your home server instances. | ||||||
| type HMMap struct { | type HMMap struct { | ||||||
| 	Nginx *HMNetInfo `json:"nginx,omitempty"` | 	*HMNetInfo | ||||||
| 	Swarm *HMNetInfo `json:"swarm,omitempty"` | 	VM  HMVM  `json:"vm,omitempty"` | ||||||
|  | 	LXC HMLXC `json:"lxc,omitempty"` | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func (hm *HMMap) GetSwarmNetInfo() *HMNetInfo { | ||||||
|  | 	data, ok := hm.VM["swarm"] | ||||||
|  | 	if !ok { | ||||||
|  | 		return nil | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	return data | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func (hm *HMMap) GetNginxNetInfo() *HMNetInfo { | ||||||
|  | 	data, ok := hm.LXC["nginx"] | ||||||
|  | 	if !ok { | ||||||
|  | 		return nil | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	return data | ||||||
| } | } | ||||||
|  | |||||||
| @ -339,7 +339,7 @@ func (t *Table) Render() { | |||||||
| 			) | 			) | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		if idx < len(t.rows) { | 		if idx+1 < len(t.rows) { | ||||||
| 			if t.rows[idx].next != nil { | 			if t.rows[idx].next != nil { | ||||||
| 				table = append(table, strings.Join(lineParts, t.colSeparator)) | 				table = append(table, strings.Join(lineParts, t.colSeparator)) | ||||||
| 			} else { | 			} else { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user