Skip to content

Commit

Permalink
AEM home dir
Browse files Browse the repository at this point in the history
  • Loading branch information
krystian-panek-vmltech committed Dec 13, 2022
1 parent ce3125e commit a28238c
Show file tree
Hide file tree
Showing 16 changed files with 139 additions and 84 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,5 @@ $RECYCLE.BIN/
*.iml
/bin
/lib
/aem.yml
aem.log
dist/
/config.yml
aem/home/
22 changes: 19 additions & 3 deletions aem.sample.yml → aem/aem.sample.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# TODO before loaded by viper pre-process by some text/template engine and inject env vars

log:
timestamp_format: "2006-01-02 15:04:05"
full_timestamp: true
Expand All @@ -8,16 +10,23 @@ log:
#
#output:
# format: text
# file: aem.log
# file: aem/home/aem.log

java:
#home_path: /Library/Java/JavaVirtualMachines/jdk-11.0.15.jdk/Contents/Home

instance:

# Processing mode
# 'auto' - for more than 1 local instances - 'serial', otherwise 'parallel'
# 'parallel' - for working with remote instances
# 'serial' - for working with local instances
processing_mode: auto

# Defined by single value (only remote)
config_url: ''

# Defined strictly with full details (local or remote)
config:
local_author:
http_url: http://localhost:4502
Expand Down Expand Up @@ -50,6 +59,13 @@ instance:
license_path: '/Users/krystian.panek/Projects/gat/resource/remote/aem/instance/license.properties'
unpack_path: '/Users/krystian.panek/Projects/aemc/out'

package:
package:
upload:
force: false

osgi:
install:
start: true
start_level: 20
refresh_packages: true

upload_force: true
54 changes: 54 additions & 0 deletions aem/api.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env sh

# print provisioning step header
step () {
DATE=$(date "+%Y-%m-%d %H:%M:%S")
echo "[$DATE]" "$@"
}

# check last command
clc () {
if [ "$?" -ne 0 ]; then
exit "$?"
fi
}

# format seconds to more nice format
duration () {
T=$1
D=$((T/60/60/24))
H=$((T/60/60%24))
M=$((T/60%60))
S=$((T%60))
if [ $D -gt 0 ]; then
printf '%d day(s) ' $D
fi
if [ $H -gt 0 ]; then
printf '%d hour(s) ' $H
fi
if [ $M -gt 0 ]; then
printf '%d minute(s) ' $M
fi
if [ $D -gt 0 ] || [ $H -gt 0 ] || [ $M -gt 0 ]; then
printf 'and '
fi
printf '%d second(s)\n' $S
}

detectOs () {
case "$(uname)" in
'Linux')
echo "linux"
;;
'Darwin')
echo "darwin"
;;
*)
echo "windows"
;;
esac
}

detectArch () {
uname -m
}
4 changes: 0 additions & 4 deletions aem/resetup.sh

This file was deleted.

4 changes: 0 additions & 4 deletions aem/restart.sh

This file was deleted.

2 changes: 1 addition & 1 deletion aem/destroy.sh → aem/script/destroy.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env sh

. aem/down.sh
. aem/script/down.sh

step "destroying instances"
aem instance destroy
Expand Down
File renamed without changes.
4 changes: 4 additions & 0 deletions aem/script/resetup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh

. aem/script/destroy.sh
. aem/script/setup.sh
4 changes: 4 additions & 0 deletions aem/script/restart.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh

. aem/script/down.sh
. aem/script/up.sh
2 changes: 1 addition & 1 deletion aem/setup.sh → aem/script/setup.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env sh

. aem/up.sh
. aem/script/up.sh

step "configuring replication agent on author instance"
PROPS="
Expand Down
File renamed without changes.
77 changes: 27 additions & 50 deletions aemw
Original file line number Diff line number Diff line change
@@ -1,74 +1,51 @@
#!/usr/bin/env sh

# Download tool

VERSION=0.5.2
OS="darwin"
ARCH="arm64"
. aem/api.sh

TOOL_DOWNLOAD_URL="https://github.com/wttech/aemc/releases/download/v${VERSION}/aemc-cli_${OS}_${ARCH}.tar.gz"
TOOL_BIN_ROOT="bin/aemw/$VERSION"
TOOL_BIN_ARCHIVE_FILE="$TOOL_BIN_ROOT/aemc-cli.tar.gz"
TOOL_BIN_ARCHIVE_DIR="$TOOL_BIN_ROOT/aemc-cli"
TOOL_BIN_EXEC_FILE="$TOOL_BIN_ARCHIVE_DIR/aemc-cli"
# Download tool

if [ ! -f "$TOOL_BIN_EXEC_FILE" ]; then
mkdir -p "$TOOL_BIN_ARCHIVE_DIR"
curl -o "$TOOL_BIN_ARCHIVE_FILE" -OJL "$TOOL_DOWNLOAD_URL"
tar -xvf "$TOOL_BIN_ARCHIVE_FILE" -C "$TOOL_BIN_ARCHIVE_DIR"
chmod +x "$TOOL_BIN_EXEC_FILE"
VERSION=${AEMC_VERSION:-"0.5.2"}
COMMAND_DEFAULT=${AEMC_COMMAND_DEFAULT:-"setup"}

OS=$(detectOs)
ARCH=$(detectArch)
DOWNLOAD_URL="https://github.com/wttech/aemc/releases/download/v${VERSION}/aemc-cli_${OS}_${ARCH}.tar.gz"
BIN_ROOT="bin/aemw/$VERSION"
BIN_ARCHIVE_FILE="$BIN_ROOT/aemc-cli.tar.gz"
BIN_ARCHIVE_DIR="$BIN_ROOT/aemc-cli"
BIN_EXEC_FILE="$BIN_ARCHIVE_DIR/aemc-cli"

if [ "$VERSION" = "dev" ]; then
make build
BIN_EXEC_FILE="bin/aemc-cli"
elif [ ! -f "$BIN_EXEC_FILE" ]; then
mkdir -p "$BIN_ARCHIVE_DIR"
curl -o "$BIN_ARCHIVE_FILE" -OJL "$DOWNLOAD_URL"
tar -xvf "$BIN_ARCHIVE_FILE" -C "$BIN_ARCHIVE_DIR"
chmod +x "$BIN_EXEC_FILE"
fi

# Declare provisioning API

# shellcheck disable=SC2139
alias aem="./$TOOL_BIN_EXEC_FILE"

# print provisioning step header
step () {
DATE=$(date "+%Y-%m-%d %H:%M:%S")
echo "[$DATE] $@"
}

# check last command
clc () {
if [ "$?" -ne 0 ]; then
exit "$?"
fi
}

# format seconds to more nice format
duration () {
T=$1
D=$((T/60/60/24))
H=$((T/60/60%24))
M=$((T/60%60))
S=$((T%60))
(( $D > 0 )) && printf '%d day(s) ' $D
(( $H > 0 )) && printf '%d hour(s) ' $H
(( $M > 0 )) && printf '%d minute(s) ' $M
(( $D > 0 || $H > 0 || $M > 0 )) && printf 'and '
printf '%d second(s)\n' $S
}
alias aem="./$BIN_EXEC_FILE"

# Include provisioning script that uses API

COMMAND_DEFAULT="setup"
COMMAND="${1:-$COMMAND_DEFAULT}"
SCRIPT="aem/$COMMAND.sh"
SCRIPT="aem/script/$COMMAND.sh"

if [ -f "$SCRIPT" ]; then
export AEM_OUTPUT_FORMAT=${AEM_OUTPUT_FORMAT:-none}
export AEM_INSTANCE_PROCESSING_MODE=${AEM_INSTANCE_PROCESSING_MODE:-parallel}

STARTED_TIMESTAMP=$SECONDS
STARTED_TIMESTAMP=$(date +%s)
step "script '$COMMAND' started"
step "check progress using command 'tail -f aem/home/aem.log'"

# shellcheck source=aem/*.sh
. "$SCRIPT"

ENDED_TIMESTAMP=$SECONDS
ELAPSED=$((ENDED_TIMESTAMP - $STARTED_TIMESTAMP))
ENDED_TIMESTAMP=$(date +%s)
ELAPSED=$((ENDED_TIMESTAMP - STARTED_TIMESTAMP))
step "script '$COMMAND' ended in $(duration $ELAPSED)"
else
aem "$@"
Expand Down
6 changes: 6 additions & 0 deletions cmd/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import (
"github.com/wttech/aemc/pkg"
"github.com/wttech/aemc/pkg/cfg"
"github.com/wttech/aemc/pkg/common/fmtx"
"github.com/wttech/aemc/pkg/common/osx"
"github.com/wttech/aemc/pkg/common/stringsx"
"io"
"os"
"path"
"reflect"
"sort"
"strings"
Expand Down Expand Up @@ -104,6 +106,10 @@ func (c *CLI) configureOutput() {
}

func (c *CLI) openOutputFile() *os.File {
err := osx.PathEnsure(path.Dir(c.outputFile))
if err != nil {
return nil
}
file, err := os.OpenFile(c.outputFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.Fatalf(fmt.Sprintf("cannot open/create AEM output file properly at path '%s': %s", c.outputFile, err))
Expand Down
2 changes: 1 addition & 1 deletion pkg/cfg/aem.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ instance:
quickstart:
dist_path: "aem-sdk-quickstart.jar"
license_path: "license.properties"
unpack_path: "out"
unpack_path: "aem/home/instance"

package:
upload:
Expand Down
26 changes: 12 additions & 14 deletions pkg/cfg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ import (
)

const (
// FileName indicates 'aem.yml' to be in CWD when launching app
FileName = "aem"
FileType = "yml"
FilePath = FileName + "." + FileType

//EnvPrefix is a prefix that need to be added to all env vars to be used by app
EnvPrefix = "AEM"
FileBaseName = "aem"
FileType = "yml"
FileName = FileBaseName + "." + FileType
FilePath = "./aem/home"
EnvPrefix = "AEM"
)

// Config defines a place for managing input configuration from various sources (YML file, env vars, etc)
Expand Down Expand Up @@ -71,7 +69,7 @@ func readFromEnv(v *viper.Viper) {
}

func readFromFile(v *viper.Viper) {
v.SetConfigName(FileName)
v.SetConfigName(FileBaseName)
v.SetConfigType(FileType)
v.AddConfigPath(filePath())

Expand All @@ -83,7 +81,7 @@ func readFromFile(v *viper.Viper) {
func filePath() string {
path := os.Getenv("AEM_CONFIG_PATH")
if len(path) == 0 {
path = "."
path = FilePath
}
return path
}
Expand All @@ -105,19 +103,19 @@ func (c *Config) ConfigureLogger() {
var configYml string

func (c *Config) Init() error {
if osx.PathExists(FilePath) {
return fmt.Errorf("config file already exists: '%s'", FilePath)
if osx.PathExists(FileName) {
return fmt.Errorf("config file already exists: '%s'", FileName)
}
err := osx.FileWrite(FilePath, configYml)
err := osx.FileWrite(FileName, configYml)
if err != nil {
return fmt.Errorf("cannot create initial config file: '%s'", FilePath)
return fmt.Errorf("cannot create initial config file: '%s'", FileName)
}
return nil
}

const (
InputStdin string = "STDIN"
OutputFile string = "aem.log"
OutputFile string = "aem/home/aem.log"
)

func InputFormats() []string {
Expand Down
12 changes: 9 additions & 3 deletions pkg/instance_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ type InstanceManager struct {
ProcessingMode instance.ProcessingMode
}

const (
RootPath = "aem/home/instance"
DistPath = "aem/lib/aem-sdk-quickstart.jar"
LicensePath = "aem/lib/license.properties"
)

func NewInstanceManager(aem *Aem) *InstanceManager {
result := new(InstanceManager)
result.aem = aem
Expand Down Expand Up @@ -376,11 +382,11 @@ type LocalOpts struct {
func (im *InstanceManager) NewLocalOpts() *LocalOpts {
pathCurrent := osx.PathCurrent()
return &LocalOpts{
RootPath: pathCurrent + "/out/local_instance",
RootPath: pathCurrent + "/" + RootPath,
JavaOpts: im.aem.javaOpts,
QuickstartOpts: QuickstartOpts{
DistPath: pathCurrent + "/lib/aem-sdk-quickstart.jar",
LicensePath: pathCurrent + "/lib/license.properties",
DistPath: pathCurrent + "/" + DistPath,
LicensePath: pathCurrent + "/" + LicensePath,
},
}
}
Expand Down

0 comments on commit a28238c

Please sign in to comment.