Skip to content

Commit

Permalink
Merge branch 'main' into push-command
Browse files Browse the repository at this point in the history
# Conflicts:
#	pkg/content/content.go
#	pkg/content_manager.go
#	pkg/package_manager.go
  • Loading branch information
dominik-przybyl-wttech committed May 7, 2024
2 parents bc0d52f + 8f98e09 commit 99124e4
Show file tree
Hide file tree
Showing 21 changed files with 284 additions and 119 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ Supported project types:

| AEM Compose (init) | AEM Project Archetype (tested) |
|--------------------|--------------------------------|
| >= 1.2.0 | 41, 42, 43, ?, 47 |
| >= 1.2.0 | 41, 42, 43, 47, 48 |

- with any type of structure, however afterwards only a little customizations in *Taskfile.yml* need to be done to reflect configuration related to built AEM application artifact path and AEM dispatcher files location
- empty folder; the project kind will be needed to be specified explicitly during initialization
Expand Down Expand Up @@ -201,16 +201,19 @@ import aemc "github.com/wttech/aemc/pkg"

func main() {
aem := aemc.DefaultAEM()
instance, _ := aem.InstanceManager().NewByURL("http://admin:admin@192.168.1.2:4502")
instance, _ := aem.InstanceManager().NewByIDAndURL("remote_author", "http://admin:admin@192.168.1.2:4502")
changed, err := instance.PackageManager().DeployWithChanged("/tmp/my-package.zip")
if err != nil {
fmt.Printf("cannot deploy package: %s\n", err)
os.Exit(1)
}
if changed {
aem.InstanceManager().AwaitStartedOne(*instance)
if err := aem.InstanceManager().AwaitStartedOne(*instance); err != nil {
fmt.Printf("instance not stable after deploying package: %s\n", err)
os.Exit(1)
}
}
fmt.Printf("package deployed properly\n")
fmt.Println("package deployed properly")
os.Exit(0)
}
```
Expand Down
6 changes: 6 additions & 0 deletions examples/docker/src/aem/default/etc/aem.yml
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@ instance:
start_level: 20
refresh_packages: true

# Force re-installing of snapshot OSGi bundles (just built / unreleased)
snapshot_patterns: [ "**/*-SNAPSHOT.jar" ]
snapshot_ignored: false
# Use checksums to avoid re-installations when snapshot OSGi bundles are unchanged
snapshot_install_skipping: true

# Crypto Support
crypto:
key_bundle_symbolic_name: com.adobe.granite.crypto.file
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ require (
github.com/ulikunitz/xz v0.5.11 // indirect
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.19.0 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
)
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN8
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo=
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
golang.org/x/exp v0.0.0-20231226003508-02704c960a9b h1:kLiC65FbiHWFAOu+lxwNPujcsl8VYyTYYEZnsOO1WK4=
golang.org/x/exp v0.0.0-20231226003508-02704c960a9b/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
Expand All @@ -181,8 +181,8 @@ golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand All @@ -200,8 +200,8 @@ golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
Expand Down
4 changes: 4 additions & 0 deletions pkg/cfg/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ func (c *Config) setDefaults() {
v.SetDefault("instance.osgi.bundle.install.start_level", 20)
v.SetDefault("instance.osgi.bundle.install.refresh_packages", true)

v.SetDefault("instance.osgi.bundle.snapshot_install_skipping", true)
v.SetDefault("instance.osgi.bundle.snapshot_ignored", false)
v.SetDefault("instance.osgi.bundle.snapshot_patterns", []string{"**/*-SNAPSHOT.jar"})

v.SetDefault("instance.ssl.setup_timeout", time.Second*30)

v.SetDefault("instance.crypto.key_bundle_symbolic_name", "com.adobe.granite.crypto.file")
Expand Down
7 changes: 4 additions & 3 deletions pkg/common/osx/osx.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import (
)

var (
EnvFileExt = "env"
EnvVar = "AEM_ENV"
EnvLocal = "local"
EnvFileExt = "env"
EnvVar = "AEM_ENV"
EnvLocal = "local"
EnvLocalFile = EnvLocal + "." + EnvFileExt
)

func IsWindows() bool {
Expand Down
68 changes: 37 additions & 31 deletions pkg/content/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,8 @@ var (
)

func init() {
var err error
propPatternRegex, err = regexp.Compile(PropPattern)
if err != nil {
log.Fatalf("Failed to compile regex: %v", err)
}

namespacePatternRegex, err = regexp.Compile(NamespacePattern)
if err != nil {
log.Fatalf("Failed to compile regex: %v", err)
}
propPatternRegex = regexp.MustCompile(PropPattern)
namespacePatternRegex = regexp.MustCompile(NamespacePattern)
}

type Manager struct {
Expand Down Expand Up @@ -95,6 +87,10 @@ func (c Manager) AfterPullFile(path string) error {
}

func (c Manager) CleanDir(root string) error {
if !pathx.Exists(root) {
return fmt.Errorf("cannot clean directory as it does not exist '%s'", root)
}
log.Infof("cleaning directory '%s'", root)
if err := c.cleanDotContents(root); err != nil {
return err
}
Expand All @@ -107,13 +103,15 @@ func (c Manager) CleanDir(root string) error {
if err := deleteEmptyDirs(root); err != nil {
return err
}
log.Infof("cleaned directory '%s'", root)
return nil
}

func (c Manager) CleanFile(path string) error {
if !pathx.Exists(path) {
return fmt.Errorf("file does not exist: %s", path)
return fmt.Errorf("cannot clean file as it does not exist '%s'", path)
}
log.Infof("cleaning file '%s'", path)
if err := c.cleanDotContentFile(path); err != nil {
return err
}
Expand All @@ -123,6 +121,7 @@ func (c Manager) CleanFile(path string) error {
if err := deleteEmptyDirs(filepath.Dir(path)); err != nil {
return err
}
log.Infof("cleaned file '%s'", path)
return nil
}

Expand Down Expand Up @@ -161,7 +160,7 @@ func (c Manager) cleanDotContentFile(path string) error {
return nil
}

log.Infof("cleaning file %s", path)
log.Infof("cleaning dot content file '%s'", path)
inputLines, err := readLines(path)
if err != nil {
return err
Expand Down Expand Up @@ -223,7 +222,9 @@ func (c Manager) cleanNamespaces(lines []string) []string {

func (c Manager) lineProcess(path string, line string) (bool, string) {
groups := propPatternRegex.FindStringSubmatch(line)
if groups == nil {
if strings.TrimSpace(line) == "" {
return true, ""
} else if groups == nil {
return false, line
} else if groups[1] == JCRMixinTypesProp {
return c.normalizeMixins(path, line, groups[2], groups[3])
Expand Down Expand Up @@ -260,9 +261,9 @@ func (c Manager) flattenFile(path string) error {

dest := filepath.Dir(path) + ".xml"
if pathx.Exists(dest) {
log.Infof("flattening file (override): %s", path)
log.Infof("flattening file (override) '%s'", path)
} else {
log.Infof("flattening file: %s", path)
log.Infof("flattening file '%s'", path)
}
return os.Rename(path, dest)
}
Expand Down Expand Up @@ -291,15 +292,15 @@ func deleteDir(dir string) error {
if !pathx.Exists(dir) {
return nil
}
log.Infof("deleting dir %s", dir)
log.Infof("deleting dir '%s'", dir)
return os.RemoveAll(dir)
}

func deleteFile(path string, allowedFunc func() bool) error {
if !pathx.Exists(path) || allowedFunc != nil && !allowedFunc() {
return nil
}
log.Infof("deleting file %s", path)
log.Infof("deleting file '%s'", path)
return os.Remove(path)
}

Expand All @@ -320,20 +321,23 @@ func deleteEmptyDirs(root string) error {
return err
}
if len(entries) == 0 {
log.Infof("deleting empty directory '%s'", root)
if err = os.Remove(root); err != nil {
return err
}
log.Infof("deleting empty directory %s", root)

}
return nil
}

func (c Manager) doParentsBackup(root string) error {
return eachParentFiles(root, func(parent string) error {
if err := createBackupIndicator(parent); err != nil {
return err
}
return eachFilesInDir(parent, func(path string) error {
if !strings.HasSuffix(path, ParentsBackupSuffix) {
if err := c.backupFile(path, "doing backup of parent file: %s"); err != nil {
if !strings.HasSuffix(path, ParentsBackupSuffix) && !strings.HasSuffix(path, ParentsBackupDirIndicator) {
log.Infof("doing backup of parent file '%s'", path)
if err := c.backupFile(path); err != nil {
return err
}
}
Expand All @@ -344,9 +348,13 @@ func (c Manager) doParentsBackup(root string) error {

func (c Manager) doSiblingsBackup(file string) error {
dir := filepath.Dir(file)
if err := createBackupIndicator(dir); err != nil {
return err
}
return eachFilesInDir(dir, func(path string) error {
if path != file && !strings.HasSuffix(path, ParentsBackupSuffix) {
if err := c.backupFile(path, "doing backup of file: %s"); err != nil {
if path != file && !strings.HasSuffix(path, ParentsBackupSuffix) && !strings.HasSuffix(path, ParentsBackupDirIndicator) {
log.Infof("doing backup of file '%s'", path)
if err := c.backupFile(path); err != nil {
return err
}
}
Expand Down Expand Up @@ -378,7 +386,7 @@ func (c Manager) undoParentsBackup(root string) error {
return eachFilesInDir(parent, func(path string) error {
if strings.HasSuffix(path, ParentsBackupSuffix) {
origin := strings.TrimSuffix(path, ParentsBackupSuffix)
log.Infof("undoing backup of parent file: %s", path)
log.Infof("undoing backup of parent file '%s'", path)
return os.Rename(path, origin)
}
return nil
Expand All @@ -391,7 +399,7 @@ func (c Manager) undoSiblingBackup(path string) error {
return eachFilesInDir(dir, func(path string) error {
if strings.HasSuffix(path, ParentsBackupSuffix) {
origin := strings.TrimSuffix(path, ParentsBackupSuffix)
log.Infof("undoing backup of file: %s", path)
log.Infof("undoing backup of file '%s'", path)
return os.Rename(path, origin)
} else if strings.HasSuffix(path, ParentsBackupDirIndicator) {
return deleteFile(path, nil)
Expand Down Expand Up @@ -452,14 +460,13 @@ func writeLines(path string, lines []string) error {
return err
}

func (c Manager) backupFile(path string, format string) error {
dir := filepath.Dir(path)
func createBackupIndicator(dir string) error {
indicator, err := os.Create(filepath.Join(dir, ParentsBackupDirIndicator))
if err != nil {
return err
}
defer func() { _ = indicator.Close() }()
return err
}

func (c Manager) backupFile(path string) error {
source, err := os.Open(path)
if err != nil {
return err
Expand All @@ -476,7 +483,6 @@ func (c Manager) backupFile(path string, format string) error {
if err != nil {
return err
}
log.Infof(format, path)
return nil
}

Expand Down
9 changes: 2 additions & 7 deletions pkg/content_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package pkg

import (
"fmt"
log "github.com/sirupsen/logrus"
"github.com/wttech/aemc/pkg/common/filex"
"github.com/wttech/aemc/pkg/common/pathx"
"github.com/wttech/aemc/pkg/common/timex"
Expand All @@ -13,19 +12,15 @@ import (
)

const (
NamespacePattern = "_([a-z]+)_"
NamespacePattern = "^_([a-z]+)_"
)

var (
namespacePatternRegex *regexp.Regexp
)

func init() {
var err error
namespacePatternRegex, err = regexp.Compile(NamespacePattern)
if err != nil {
log.Fatalf("Failed to compile regex: %v", err)
}
namespacePatternRegex = regexp.MustCompile(NamespacePattern)
}

type ContentManager struct {
Expand Down
13 changes: 4 additions & 9 deletions pkg/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"github.com/fatih/color"
"github.com/samber/lo"
log "github.com/sirupsen/logrus"
"github.com/wttech/aemc/pkg/common/fmtx"
"github.com/wttech/aemc/pkg/instance"
Expand Down Expand Up @@ -181,13 +180,6 @@ func (i Instance) IsAdHoc() bool {
return i.IDInfo().Role == instance.RoleAdHoc
}

func locationByURL(config *nurl.URL) string {
if lo.Contains(localHosts(), config.Hostname()) {
return instance.LocationLocal
}
return instance.LocationRemote
}

func roleByURL(config *nurl.URL) instance.Role {
if strings.HasSuffix(config.Port(), instance.RoleAuthorPortSuffix) {
return instance.RoleAuthor
Expand Down Expand Up @@ -292,10 +284,13 @@ func (i Instance) HealthChecks() []string {
continue
}
result := check.Check(i.manager.CheckContext().Value(checkContextKey{}).(CheckContext), i)
resultText := result.Text()
resultText := InstanceTrim(i, result.Text())
if resultText != "" {
messages = append(messages, resultText)
}
if !result.ok && check.Spec().Mandatory {
break
}
}
}
return messages
Expand Down
Loading

0 comments on commit 99124e4

Please sign in to comment.