update README.md + few fixes

This commit is contained in:
rmanach 2025-05-02 10:10:50 +02:00
parent 07f096a0a5
commit 45bc90b940
5 changed files with 25 additions and 19 deletions

View File

@ -86,19 +86,24 @@ func (hm *HMMap) GetSwarmNetInfo() *HMNetInfo {
* 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
{ {
"name": "<project-name>", "name": "my-api",
"image": "<project-image-name>:<project-image-tag>",
"dependencies": { "dependencies": {
"env": "<project-dot-env-path>", "swarm": {
"compose": "<project-docker-compose-path>", "env": ".env",
"nginx": "<project-nginx-conf-path>" "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 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. 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 image empty. It is used if you want to push a local image or don't have a docker registry. 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 ## Run
@ -131,7 +136,7 @@ Usage of hmdeploy:
-path string -path string
define the .homeserver project root dir (default ".") define the .homeserver project root dir (default ".")
-version -version
extract swarm details and return show program version and return
# if your are in the project dir with a `.homeserver` # if your are in the project dir with a `.homeserver`
# you can then launch the program directly # you can then launch the program directly

View File

@ -109,8 +109,8 @@ func (sd *SwarmDeployer) Build() error {
log.Info().Msg("building swarm archive for deployment...") log.Info().Msg("building swarm archive for deployment...")
filesToArchive := []string{} filesToArchive := []string{}
for idx := range sd.project.ImageNames { for idx := range sd.project.Deps.Swarm.ImageNames {
tarFile, err := sd.dloc.Save(sd.project.ImageNames[idx], sd.project.Dir) tarFile, err := sd.dloc.Save(sd.project.Deps.Swarm.ImageNames[idx], sd.project.Dir)
if err != nil { if err != nil {
sd.setDone(err) sd.setDone(err)
return err return err
@ -172,7 +172,7 @@ func (sd *SwarmDeployer) Deploy() error {
log.Info().Str("archive", sd.archivePath).Msg("deploying archive to swarm...") 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) sd.setDone(err)
return err return err
} }

View File

@ -3,7 +3,8 @@
"dependencies": { "dependencies": {
"swarm": { "swarm": {
"env": ".env", "env": ".env",
"compose": "docker-compose.deploy.yml" "compose": "docker-compose.deploy.yml",
"images": []
}, },
"nginx": { "nginx": {
"conf": "nginx.conf", "conf": "nginx.conf",

View File

@ -418,7 +418,7 @@ func getSwarmServicesDetails(hm *models.HMMap) error {
return nil return nil
} }
func main() { //nolint: funlen //TODO: to reduce func main() { //nolint: funlen // TODO: to reduce
ctx, fnCancel := signal.NotifyContext( ctx, fnCancel := signal.NotifyContext(
context.Background(), context.Background(),
os.Interrupt, os.Interrupt,
@ -431,7 +431,7 @@ func main() { //nolint: funlen //TODO: to reduce
noSwarm := flag.Bool("no-swarm", false, "no Swarm deployment") noSwarm := flag.Bool("no-swarm", false, "no Swarm deployment")
debug := flag.Bool("debug", false, "show debug logs") debug := flag.Bool("debug", false, "show debug logs")
details := flag.Bool("details", false, "extract swarm details and return") 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 := flag.Bool(
"confirm", "confirm",
false, false,

View File

@ -89,16 +89,16 @@ type Project struct {
Name string `json:"name"` Name string `json:"name"`
Dir string Dir string
Deps struct { Deps struct {
Swarm struct {
EnvFile string `json:"env"`
ComposeFile string `json:"compose"`
} `json:"swarm"`
Nginx struct { Nginx struct {
Conf string `json:"conf"` Conf string `json:"conf"`
Assets string `json:"assets"` Assets string `json:"assets"`
} }
Swarm struct {
EnvFile string `json:"env"`
ComposeFile string `json:"compose"`
ImageNames []string `json:"images"`
} `json:"swarm"`
} `json:"dependencies"` } `json:"dependencies"`
ImageNames []string `json:"images"`
} }
func (p *Project) validate() error { func (p *Project) validate() error {