rework hm netinfo map model
This commit is contained in:
parent
c7dc3d4402
commit
9918c0c363
6
Makefile
6
Makefile
@ -3,10 +3,10 @@ BIN_INSTALL = $(shell whereis $(BIN_NAME) | cut -d ' ' -f2)
|
||||
|
||||
VERSION = 0.1.1
|
||||
|
||||
run: lint
|
||||
run: check
|
||||
@go run main.go
|
||||
|
||||
build: lint
|
||||
build: check
|
||||
@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"
|
||||
|
||||
@ -16,7 +16,7 @@ install: build
|
||||
@echo "program installed: $(GOPATH)/bin/hmdeploy"
|
||||
@$(GOPATH)/bin/hmdeploy --version
|
||||
|
||||
lint:
|
||||
check:
|
||||
@echo "format and lint..."
|
||||
@golangci-lint fmt ./...
|
||||
@golangci-lint run ./...
|
||||
58
README.md
58
README.md
@ -38,51 +38,27 @@ 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.
|
||||
```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": {
|
||||
"ip": "<swarm-ip>",
|
||||
"ssh": {
|
||||
"user": "<ssh-user>",
|
||||
"privkey": "<path-to-ssh-private-key>",
|
||||
"port": <swarm-ssh-port>
|
||||
}
|
||||
"swarm": {
|
||||
"ip": "<swarm-ip>",
|
||||
"ssh": {
|
||||
"user": "<ssh-user>",
|
||||
"privkey": "<path-to-ssh-private-key>",
|
||||
"port": <swarm-ssh-port>
|
||||
}
|
||||
},
|
||||
"lxc": {
|
||||
"nginx": {
|
||||
"ip": "<nginx-ip>",
|
||||
"web_url": "https://<nginx-ip>",
|
||||
"ssh": {
|
||||
"user": "<ssh-user>",
|
||||
"privkey": "<path-to-ssh-private-key>",
|
||||
"port": <nginx-ssh-port>
|
||||
}
|
||||
}
|
||||
}
|
||||
"nginx": {
|
||||
"ip": "<nginx-ip>",
|
||||
"web_url": "https://<nginx-ip>",
|
||||
"ssh": {
|
||||
"user": "<ssh-user>",
|
||||
"privkey": "<path-to-ssh-private-key>",
|
||||
"port": <nginx-ssh-port>
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
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`:
|
||||
```json
|
||||
{
|
||||
@ -111,7 +87,7 @@ If you have a Docker registry with the target image available, you can thus leav
|
||||
|
||||
* Clone the repository
|
||||
```bash
|
||||
git clone https://gitea.thegux.fr/rmanach/hmdeploy
|
||||
git clone https://gitea.sonak.fr/rmanach/hmdeploy
|
||||
```
|
||||
* Install the binary
|
||||
```bash
|
||||
@ -124,7 +100,7 @@ The binary is then installed in your **$GOPATH/bin**.
|
||||
hmdeploy --help
|
||||
Usage of hmdeploy:
|
||||
-config string
|
||||
define the configuration directory (default "/home/romain/.homeserver")
|
||||
define the configuration directory (default "/home/<user>/.homeserver")
|
||||
-confirm
|
||||
do not ask for confirmation, you're the best, you don't need confirmation
|
||||
-debug
|
||||
|
||||
6
main.go
6
main.go
@ -293,7 +293,7 @@ func initDeployers(
|
||||
}
|
||||
|
||||
if !opt.noSwarm && project.GetComposePath() != "" {
|
||||
swarmNet := hmmap.GetSwarmNetInfo()
|
||||
swarmNet := hmmap.Swarm
|
||||
if swarmNet == nil {
|
||||
return deps, fmt.Errorf("%w, swarm net info does not exist", ErrNetInfoNotFound)
|
||||
}
|
||||
@ -307,7 +307,7 @@ func initDeployers(
|
||||
}
|
||||
|
||||
if !opt.noNginx && project.GetNginxConfPath() != "" {
|
||||
nginxNet := hmmap.GetNginxNetInfo()
|
||||
nginxNet := hmmap.Nginx
|
||||
if nginxNet == nil {
|
||||
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
|
||||
func getSwarmServicesDetails(hm *models.HMMap) error {
|
||||
swarmNet := hm.GetSwarmNetInfo()
|
||||
swarmNet := hm.Swarm
|
||||
if swarmNet == nil {
|
||||
return fmt.Errorf("%w, swarm net info does not exist", ErrNetInfoNotFound)
|
||||
}
|
||||
|
||||
28
models/hm.go
28
models/hm.go
@ -14,32 +14,8 @@ type HMNetInfo struct {
|
||||
} `json:"ssh,omitempty"`
|
||||
}
|
||||
|
||||
type (
|
||||
HMVM map[string]*HMNetInfo
|
||||
HMLXC map[string]*HMNetInfo
|
||||
)
|
||||
|
||||
// HMMap handles all the informations of your home server instances.
|
||||
type HMMap struct {
|
||||
*HMNetInfo
|
||||
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
|
||||
Nginx *HMNetInfo `json:"nginx,omitempty"`
|
||||
Swarm *HMNetInfo `json:"swarm,omitempty"`
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user