fix hmdeploy.json with relative path

This commit is contained in:
rmanach 2025-04-04 15:50:02 +02:00
parent a70030c747
commit 43a78573f5
6 changed files with 40 additions and 30 deletions

View File

@ -127,7 +127,9 @@ hmdeploy --path /path/my-project
## Next steps
* Improve the CLI arguments
* We'll see...
* Destroy
* post-install script
* Deals with bugs
## Contact
For issues, questions or anything contact me at: admin@thegux.fr

View File

@ -6,9 +6,8 @@ import (
"sync/atomic"
"time"
"github.com/rs/zerolog/log"
"gitea.thegux.fr/hmdeploy/models"
"github.com/rs/zerolog/log"
)
var ErrContextDone = errors.New("unable to execute, context done")

View File

@ -3,12 +3,10 @@ package deployers
import (
"context"
"fmt"
"path/filepath"
"github.com/rs/zerolog/log"
"gitea.thegux.fr/hmdeploy/connection"
"gitea.thegux.fr/hmdeploy/models"
"github.com/rs/zerolog/log"
)
// NginxDeployer handles the deployment of an Nginx configuration.
@ -77,12 +75,11 @@ func (nd *NginxDeployer) Build() error {
default:
}
nginxPath := filepath.Join(nd.project.Dir, filepath.Base(nd.project.Deps.NginxFile))
nginxConf := nd.project.Name + ".conf"
log.Info().Str("nginx", nginxConf).Msg("transferring nginx conf...")
if err := nd.conn.CopyFile(nginxPath, nginxConf); err != nil {
if err := nd.conn.CopyFile(nd.project.Deps.NginxFile, nginxConf); err != nil {
nd.setDone(err)
return err
}

View File

@ -7,12 +7,11 @@ import (
"os"
"path/filepath"
"github.com/rs/zerolog/log"
"gitea.thegux.fr/hmdeploy/connection"
"gitea.thegux.fr/hmdeploy/docker"
"gitea.thegux.fr/hmdeploy/models"
"gitea.thegux.fr/hmdeploy/utils"
"github.com/rs/zerolog/log"
)
var ErrSwarmDeployerNoArchive = errors.New("no archive found to be deployed")
@ -107,7 +106,10 @@ func (sd *SwarmDeployer) Build() error {
defer os.Remove(tarFile) //nolint: errcheck // defered
filesToArchive = append(filesToArchive, tarFile)
// copy the file directly instead of adding it in the tar archive
if err := sd.conn.CopyFile(tarFile, filepath.Base(tarFile)); err != nil {
return err
}
log.Info().Str("image", imageName).Msg("image added to archive")
}
@ -115,13 +117,15 @@ func (sd *SwarmDeployer) Build() error {
if envFilePath := sd.project.Deps.EnvFile; envFilePath != "" {
filesToArchive = append(
filesToArchive,
filepath.Join(sd.project.Dir, filepath.Base(envFilePath)),
envFilePath,
)
log.Info().Msg(".env file added to the archive for deployment")
}
composeFileBase := filepath.Base(sd.project.Deps.ComposeFile)
filesToArchive = append(filesToArchive, filepath.Join(sd.project.Dir, composeFileBase))
filesToArchive = append(
filesToArchive,
sd.project.Deps.ComposeFile,
)
archivePath, err := utils.CreateArchive(
sd.project.Dir,

View File

@ -11,13 +11,12 @@ import (
"path"
"sync"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"gitea.thegux.fr/hmdeploy/deployers"
"gitea.thegux.fr/hmdeploy/docker"
"gitea.thegux.fr/hmdeploy/models"
"gitea.thegux.fr/hmdeploy/scheduler"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)
const (

View File

@ -23,28 +23,34 @@ const (
var ErrProjectConfFile = errors.New("project error")
func getFileInfo(baseDir, filePath string) (fs.FileInfo, error) {
func getFileInfo(baseDir, filePath string) (string, fs.FileInfo, error) {
var fInf fs.FileInfo
filePath = filepath.Clean(filePath)
if !filepath.IsAbs(filePath) {
filePath = filepath.Join(baseDir, filePath)
fileAbsPath, err := filepath.Abs(filePath)
filePath, err := filepath.Abs(filePath)
if err != nil {
return fInf, fmt.Errorf("%w, file=%s, err=%v", ErrProjectConfFile, fileAbsPath, err)
return filePath, fInf, fmt.Errorf(
"%w, file=%s, err=%v",
ErrProjectConfFile,
filePath,
err,
)
}
}
fInf, err = os.Stat(fileAbsPath)
fInf, err := os.Stat(filePath)
if err != nil {
return fInf, fmt.Errorf(
return filePath, fInf, fmt.Errorf(
"%w, unable to stat file=%s, err=%v",
ErrProjectConfFile,
fileAbsPath,
filePath,
err,
)
}
return fInf, nil
return filePath, fInf, nil
}
// Project handles the details and file informations of your project.
@ -65,27 +71,30 @@ type Project struct {
}
func (p *Project) validate() error {
cfs, err := getFileInfo(p.Dir, p.Deps.ComposeFile)
cpath, cfs, err := getFileInfo(p.Dir, p.Deps.ComposeFile)
if err != nil {
return err
}
p.Deps.ComposeFileInfo = cfs
p.Deps.ComposeFile = cpath
if p.Deps.EnvFile != "" {
efs, err := getFileInfo(p.Dir, p.Deps.EnvFile)
epath, efs, err := getFileInfo(p.Dir, p.Deps.EnvFile)
if err != nil {
return err
}
p.Deps.EnvFileInfo = efs
p.Deps.EnvFile = epath
} else {
log.Warn().Msg("no .env file provided, hoping one it's set elsewhere...")
}
nfs, err := getFileInfo(p.Dir, p.Deps.NginxFile)
npath, nfs, err := getFileInfo(p.Dir, p.Deps.NginxFile)
if err != nil {
return err
}
p.Deps.NginxFileInfo = nfs
p.Deps.NginxFile = npath
return nil
}