Skip to content

Commit

Permalink
Merge pull request #72 from wttech/task-tool
Browse files Browse the repository at this point in the history
Task tool instead of pure scripts
  • Loading branch information
krystian-panek-vmltech authored Feb 18, 2023
2 parents 0f95c7b + c50828a commit 3d419bf
Show file tree
Hide file tree
Showing 19 changed files with 542 additions and 193 deletions.
8 changes: 7 additions & 1 deletion cmd/aem/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type CLI struct {
outputLogConsole bool
outputResponse *OutputResponse
outputWriter io.Writer
outputNoColor bool
}

func NewCLI(aem *pkg.Aem, config *cfg.Config) *CLI {
Expand All @@ -62,6 +63,7 @@ func NewCLI(aem *pkg.Aem, config *cfg.Config) *CLI {
result.outputFormat = fmtx.Text
result.outputBuffer = bytes.NewBufferString("")
result.outputResponse = outputResponseDefault()
result.outputNoColor = color.NoColor
result.cmd = result.rootCmd()

return result
Expand Down Expand Up @@ -102,6 +104,9 @@ func (c *CLI) configure() {
func (c *CLI) configureOutput() {
opts := c.config.Values().Output

c.outputNoColor = opts.NoColor
color.NoColor = opts.NoColor

c.outputValue = opts.Value
c.outputFormat = strings.ReplaceAll(opts.Format, "yaml", "yml")
c.outputLogFile = opts.Log.File
Expand Down Expand Up @@ -180,7 +185,8 @@ func (c *CLI) printOutputText() {
func (c *CLI) printCommandResult() {
r := c.outputResponse
msg := fmt.Sprintf("%s", r.Msg)
if color.NoColor || !c.outputLogConsole {

if c.outputNoColor {
entry := log.WithField("changed", r.Changed).WithField("elapsed", r.Elapsed)
if r.Failed {
entry.Errorf(msg)
Expand Down
1 change: 1 addition & 0 deletions pkg/cfg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ func (c *Config) ConfigureLogger() {
log.SetFormatter(&log.TextFormatter{
TimestampFormat: c.values.Log.TimestampFormat,
FullTimestamp: c.values.Log.FullTimestamp,
ForceColors: !c.values.Output.NoColor,
})
level, err := log.ParseLevel(c.values.Log.Level)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions pkg/cfg/defaults.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cfg

import (
"github.com/fatih/color"
"github.com/spf13/viper"
"github.com/wttech/aemc/pkg/common"
"github.com/wttech/aemc/pkg/common/fmtx"
Expand All @@ -17,6 +18,7 @@ func setDefaults(v *viper.Viper) {
v.SetDefault("input.format", fmtx.YML)
v.SetDefault("input.file", common.STDIn)
v.SetDefault("output.format", fmtx.Text)
v.SetDefault("output.no_color", color.NoColor)
v.SetDefault("output.value", common.OutputValueAll)
v.SetDefault("output.log.file", common.LogFile)
v.SetDefault("output.log.console", true)
Expand Down
7 changes: 4 additions & 3 deletions pkg/cfg/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ type ConfigValues struct {
} `mapstructure:"input" yaml:"input"`

Output struct {
Format string `mapstructure:"format" yaml:"format"`
Value string `mapstructure:"value" yaml:"value"`
Log struct {
Format string `mapstructure:"format" yaml:"format"`
NoColor bool `mapstructure:"no_color" yaml:"no_color"`
Value string `mapstructure:"value" yaml:"value"`
Log struct {
File string `mapstructure:"file" yaml:"file"`
Console bool `mapstructure:"console" yaml:"console"`
} `mapstructure:"log" yaml:"log"`
Expand Down
190 changes: 190 additions & 0 deletions pkg/project/classic/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
# Task tool documentation:
# 1) Basics: https://taskfile.dev/usage
# 2) Naming conventions: https://taskfile.dev/styleguide

version: '3'

env:
AEM_INSTANCE_PROCESSING_MODE: auto
AEM_OUTPUT_VALUE: NONE

vars:
APM_VERSION: 5.5.1

tasks:

setup:
desc: setup AEM environment
cmds:
- task: aem:setup
- task: docker:up

resetup:
desc: destroy and setup again AEM environment
cmds:
- task: destroy
- task: setup

start:
desc: start AEM environment
aliases: [up]
cmds:
- task: aem:up
- task: docker:up

stop:
desc: stop AEM environment
aliases: [down]
cmds:
- task: docker:down
- task: aem:down

restart:
cmds:
- task: aem:down
- task: aem:up

destroy:
desc: destroy AEM environment
cmds:
- task: stop
- task: aem:destroy

aem:setup:
desc: setup AEM instances
cmds:
- task: aem:start
- task: aem:provision
- task: aem:deploy

aem:create:
desc: create AEM instances
cmds: [sh aemw instance create]

aem:start:
desc: start AEM instances
aliases: [aem:up]
cmds:
- sh aemw instance create
- sh aemw instance up

aem:await:
desc: await stable AEM instances
aliases: [aem:check]
cmds:
- sh aemw instance await

aem:status:
desc: check AEM instances status
env:
AEM_OUTPUT_VALUE: ALL
cmds:
- sh aemw instance status

aem:provision:
desc: provision AEM instances
aliases: [aem:configure]
cmds:
- task: aem:provision:repl-agent-publish
- task: aem:provision:repl-agent-flush
- task: aem:provision:crx
- task: aem:provision:apm
- task: aem:provision:service-pack

aem:provision:repl-agent-publish:
desc: configure replication agent on author instance
cmds:
- |
PROPS="
enabled: true
transportUri: http://localhost:4503/bin/receive?sling:authRequestLogin=1
transportUser: admin
transportPassword: admin
userId: admin
"
echo "$PROPS" | sh aemw repl agent setup -A --location "author" --name "publish"
aem:provision:repl-agent-flush:
desc: configure replication agent on publish instance
cmds:
- |
PROPS="
enabled: true
transportUri: http://127.0.0.1/dispatcher/invalidate.cache
protocolHTTPHeaders:
- CQ-Action: {action}
- CQ-Handle: {path}
- CQ-Path: {path}
- Host: publish
"
echo "$PROPS" | sh aemw repl agent setup -P --location "publish" --name "flush"
aem:provision:crx:
desc: enable CRX/DE
cmds:
- 'sh aemw osgi config save --pid "org.apache.sling.jcr.davex.impl.servlets.SlingDavExServlet" --input-string "alias: /crx/server"'

aem:provision:apm:
desc: deploy APM tool
cmds:
- sh aemw package deploy --url "https://github.com/wttech/APM/releases/download/apm-{{.APM_VERSION}}/apm-all-{{.APM_VERSION}}.zip"

aem:provision:service-pack:
desc: deploy AEM Service Pack
cmds:
- sh aemw package deploy --file "aem/home/lib/aem-service-pkg-6.5.*.0.zip"

aem:destroy:
desc: destroy AEM instances
deps: [aem:stop]
cmds: [sh aemw instance destroy]

aem:stop:
desc: stop AEM instances
aliases: [aem:down]
cmds: [sh aemw instance stop]

aem:build:
desc: build AEM application
cmds:
- >
sh aemw app build
--command "mvn clean package"
--sources "pom.xml,all,core,ui.apps,ui.apps.structure,ui.config,ui.content,ui.frontend,ui.tests"
--file "all/target/*.all-*.zip"
aem:deploy:
desc: deploy AEM application
deps: [aem:build]
cmds:
- sh aemw package deploy --file "all/target/*.all-*.zip"

docker:build:dispatcher:
desc: build AEM dispatcher image
dir: dispatcher
cmds:
- docker build -t acme/aem-ams/dispatcher-publish .

docker:start:
desc: start Docker containers
aliases: [docker:up]
deps: [docker:build:dispatcher]
cmds:
- mkdir -p aem/home/var/dispatcher/httpd/logs aem/home/var/dispatcher/httpd/cache aem/home/var/dispatcher/httpd/htdocs
- docker compose up -d

docker:stop:
desc: stop Docker containers
aliases: [docker:down]
cmds: [docker compose down]

docker:restart:
desc: restart Docker containers
cmds:
- task: docker-stop
- task: docker-start

docker:status:
desc: list Docker containers
cmds:
- docker compose ps
20 changes: 0 additions & 20 deletions pkg/project/classic/aem/script/deploy.sh

This file was deleted.

8 changes: 0 additions & 8 deletions pkg/project/classic/aem/script/destroy.sh

This file was deleted.

5 changes: 0 additions & 5 deletions pkg/project/classic/aem/script/down.sh

This file was deleted.

35 changes: 0 additions & 35 deletions pkg/project/classic/aem/script/provision.sh

This file was deleted.

4 changes: 0 additions & 4 deletions pkg/project/classic/aem/script/resetup.sh

This file was deleted.

4 changes: 0 additions & 4 deletions pkg/project/classic/aem/script/restart.sh

This file was deleted.

5 changes: 0 additions & 5 deletions pkg/project/classic/aem/script/setup.sh

This file was deleted.

3 changes: 0 additions & 3 deletions pkg/project/classic/aem/script/undeploy.sh

This file was deleted.

9 changes: 0 additions & 9 deletions pkg/project/classic/aem/script/up.sh

This file was deleted.

3 changes: 0 additions & 3 deletions pkg/project/classic/dispatcher/build.sh

This file was deleted.

Loading

0 comments on commit 3d419bf

Please sign in to comment.