From a44a9c57ed77a00909a1bd361ab4cfec21e2658d Mon Sep 17 00:00:00 2001 From: Krystian Panek Date: Fri, 17 Feb 2023 22:34:09 +0100 Subject: [PATCH 1/9] Task tool instead of pure scripts --- pkg/project/classic/Taskfile.yml | 171 ++++++++++++++++++++ pkg/project/classic/aem/script/deploy.sh | 20 --- pkg/project/classic/aem/script/destroy.sh | 8 - pkg/project/classic/aem/script/down.sh | 5 - pkg/project/classic/aem/script/provision.sh | 35 ---- pkg/project/classic/aem/script/resetup.sh | 4 - pkg/project/classic/aem/script/restart.sh | 4 - pkg/project/classic/aem/script/setup.sh | 5 - pkg/project/classic/aem/script/undeploy.sh | 3 - pkg/project/classic/aem/script/up.sh | 9 -- pkg/project/cloud/Taskfile.yml | 162 +++++++++++++++++++ project/aemw | 81 +--------- project/taskw | 11 ++ 13 files changed, 346 insertions(+), 172 deletions(-) create mode 100644 pkg/project/classic/Taskfile.yml delete mode 100644 pkg/project/classic/aem/script/deploy.sh delete mode 100644 pkg/project/classic/aem/script/destroy.sh delete mode 100644 pkg/project/classic/aem/script/down.sh delete mode 100644 pkg/project/classic/aem/script/provision.sh delete mode 100644 pkg/project/classic/aem/script/resetup.sh delete mode 100644 pkg/project/classic/aem/script/restart.sh delete mode 100644 pkg/project/classic/aem/script/setup.sh delete mode 100644 pkg/project/classic/aem/script/undeploy.sh delete mode 100644 pkg/project/classic/aem/script/up.sh create mode 100644 pkg/project/cloud/Taskfile.yml create mode 100755 project/taskw diff --git a/pkg/project/classic/Taskfile.yml b/pkg/project/classic/Taskfile.yml new file mode 100644 index 00000000..ba2e7dca --- /dev/null +++ b/pkg/project/classic/Taskfile.yml @@ -0,0 +1,171 @@ +# 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: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 APM tool + cmds: + - sh aemw package deploy --file "aem/home/lib/aem-service-pkg-6.5.*.0.zip" + + aem:destroy: + desc: destroy AEM instances + deps: [undeploy, stop] + cmds: [sh aemw instance destroy] + + aem:stop: + desc: stop AEM instances + aliases: [aem:down] + cmds: [sh aemw instance start] + + 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" + - cd dispatcher && sh build.sh + + aem:deploy: + desc: deploy AEM application + cmds: + - sh aemw package deploy --file "all/target/*.all-*.zip" + + docker:start: + desc: start Docker containers + aliases: [docker:up] + 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 diff --git a/pkg/project/classic/aem/script/deploy.sh b/pkg/project/classic/aem/script/deploy.sh deleted file mode 100644 index d3735339..00000000 --- a/pkg/project/classic/aem/script/deploy.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env sh - -step "build AEM application" -aem 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" -clc - -step "deploy AEM application" -aem package deploy --file "all/target/*.all-*.zip" -clc - -step "build AEM dispatcher" -(cd dispatcher && sh build.sh) -clc - -step "deploy AEM dispatcher" -mkdir -p aem/home/var/dispatcher/httpd/logs aem/home/var/dispatcher/httpd/cache aem/home/var/dispatcher/httpd/htdocs && docker compose up -d -clc diff --git a/pkg/project/classic/aem/script/destroy.sh b/pkg/project/classic/aem/script/destroy.sh deleted file mode 100644 index 0161c517..00000000 --- a/pkg/project/classic/aem/script/destroy.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env sh - -. aem/script/undeploy.sh -. aem/script/down.sh - -step "destroying instances" -aem instance destroy - diff --git a/pkg/project/classic/aem/script/down.sh b/pkg/project/classic/aem/script/down.sh deleted file mode 100644 index d63fc0ea..00000000 --- a/pkg/project/classic/aem/script/down.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env sh - -step "stopping instances (it may take a few minutes)" -aem instance stop -clc diff --git a/pkg/project/classic/aem/script/provision.sh b/pkg/project/classic/aem/script/provision.sh deleted file mode 100644 index 53676d3e..00000000 --- a/pkg/project/classic/aem/script/provision.sh +++ /dev/null @@ -1,35 +0,0 @@ -step "configuring replication agent on author instance" -PROPS=" -enabled: true -transportUri: http://localhost:4503/bin/receive?sling:authRequestLogin=1 -transportUser: admin -transportPassword: admin -userId: admin -" -echo "$PROPS" | aem repl agent setup -A --location "author" --name "publish" -clc - -step "configuring replication agent for flushing cached content" -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" | aem repl agent setup -P --location "publish" --name "flush" -clc - -step "enabling CRX/DE" -aem osgi config save --pid "org.apache.sling.jcr.davex.impl.servlets.SlingDavExServlet" --input-string "alias: /crx/server" -clc - -step "deploying APM" -aem package deploy --url "https://github.com/wttech/APM/releases/download/apm-5.5.1/apm-all-5.5.1.zip" -clc - -step "deploying AEM service pack (it may take a several minutes)" -aem package deploy --file "aem/home/lib/aem-service-pkg-6.5.*.0.zip" -clc diff --git a/pkg/project/classic/aem/script/resetup.sh b/pkg/project/classic/aem/script/resetup.sh deleted file mode 100644 index febc3fe0..00000000 --- a/pkg/project/classic/aem/script/resetup.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env sh - -. aem/script/destroy.sh -. aem/script/setup.sh diff --git a/pkg/project/classic/aem/script/restart.sh b/pkg/project/classic/aem/script/restart.sh deleted file mode 100644 index 542be848..00000000 --- a/pkg/project/classic/aem/script/restart.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env sh - -. aem/script/down.sh -. aem/script/up.sh diff --git a/pkg/project/classic/aem/script/setup.sh b/pkg/project/classic/aem/script/setup.sh deleted file mode 100644 index 3fc53bf8..00000000 --- a/pkg/project/classic/aem/script/setup.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env sh - -. aem/script/up.sh -. aem/script/provision.sh -. aem/script/deploy.sh diff --git a/pkg/project/classic/aem/script/undeploy.sh b/pkg/project/classic/aem/script/undeploy.sh deleted file mode 100644 index ef597311..00000000 --- a/pkg/project/classic/aem/script/undeploy.sh +++ /dev/null @@ -1,3 +0,0 @@ -step "undeploy AEM dispatcher" -docker compose down -clc diff --git a/pkg/project/classic/aem/script/up.sh b/pkg/project/classic/aem/script/up.sh deleted file mode 100644 index d16b964b..00000000 --- a/pkg/project/classic/aem/script/up.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env sh - -step "creating instances (it may take a moment)" -aem instance create -clc - -step "starting instances (it may take a few minutes)" -aem instance start -clc diff --git a/pkg/project/cloud/Taskfile.yml b/pkg/project/cloud/Taskfile.yml new file mode 100644 index 00000000..5b8b9fec --- /dev/null +++ b/pkg/project/cloud/Taskfile.yml @@ -0,0 +1,162 @@ +# 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: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 + + 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:destroy: + desc: destroy AEM instances + deps: [undeploy, stop] + cmds: [sh aemw instance destroy] + + aem:stop: + desc: stop AEM instances + aliases: [aem:down] + cmds: [sh aemw instance start] + + 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" + - cd dispatcher && sh build.sh + + aem:deploy: + desc: deploy AEM application + cmds: + - sh aemw package deploy --file "all/target/*.all-*.zip" + + docker:start: + desc: start Docker containers + aliases: [docker:up] + cmds: + # - sh aem/home/opt/sdk/dispatcher/bin/validate.sh dispatcher/src > aem/home/var/log/dispatcher-validate.log # uncomment if possible, see: https://github.com/adobe/aem-project-archetype/issues/1043 + - docker tag "$(docker load --input "aem/home/opt/sdk/dispatcher/lib/dispatcher-publish-${ARCH}.tar.gz" | awk -v 'FS= ' '{print $3}')" "adobe/aem-ethos/dispatcher-publish:latest" + - 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 diff --git a/project/aemw b/project/aemw index 7548d8c2..4659ffe0 100755 --- a/project/aemw +++ b/project/aemw @@ -5,62 +5,6 @@ VERSION=${AEM_CLI_VERSION:-"1.0.5"} # Define API # ========== -# pretend AEM CLI logger but in bash -info () { - DATE=$(date "+%Y-%m-%d %H:%M:%S") - if [ -z "$NO_COLOR" ]; then - CL='\033[0;36m' - NC='\033[0m' - echo "${CL}INFO${NC}[$DATE]" "$@" - else - echo "INFO[$DATE]" "$@" - fi -} - -# print provisioning step header -step () { - DATE=$(date "+%Y-%m-%d %H:%M:%S") - if [ -z "$NO_COLOR" ]; then - CL='\033[0;35m' - CY='\033[0;35m' - NC='\033[0m' - echo "" - echo "${CL}STEP${NC}[$DATE]${CY}" "$@" "${NC}" - else - echo "" - echo "STEP[$DATE]" "$@" - fi -} - -# 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 -} - detect_os () { case "$(uname)" in 'Linux') @@ -118,28 +62,7 @@ if [ "${VERSION}" != "installed" ] ; then } fi -# Execute script if found or fallback to CLI +# Execute AEM Compose CLI # ========================================== -COMMAND_DEFAULT=${AEM_CLI_COMMAND_DEFAULT:-"setup"} -COMMAND="${1:-${COMMAND_DEFAULT}}" -SCRIPT="aem/script/${COMMAND}.sh" - -if [ -f "$SCRIPT" ]; then - export AEM_INSTANCE_PROCESSING_MODE=${AEM_INSTANCE_PROCESSING_MODE:-serial} - export AEM_OUTPUT_VALUE=${AEM_OUTPUT_VALUE:-"NONE"} - - STARTED_TIMESTAMP=$(date +%s) - - info "script '${COMMAND}' started; to customize its behavior see: https://github.com/wttech/aemc#scripts" - - # shellcheck source=aem/*.sh - . "${SCRIPT}" - - ENDED_TIMESTAMP=$(date +%s) - ELAPSED=$((ENDED_TIMESTAMP - STARTED_TIMESTAMP)) - - info "script '${COMMAND}' ended in $(duration $ELAPSED)" -else - aem "$@" -fi +aem "$@" diff --git a/project/taskw b/project/taskw new file mode 100755 index 00000000..44308d6c --- /dev/null +++ b/project/taskw @@ -0,0 +1,11 @@ +#!/usr/bin/env sh + +# Execute AEM Compose CLI +# ========================================== + +# TODO auto-download like in 'aemw' + +# https://taskfile.dev/api/#env +export TASK_COLOR_GREEN=35 + +task "$@" From ce0f8482480ebe33de308beb8d06647bb4b7df86 Mon Sep 17 00:00:00 2001 From: Krystian Panek Date: Fri, 17 Feb 2023 22:39:34 +0100 Subject: [PATCH 2/9] Minor --- pkg/project/classic/Taskfile.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/project/classic/Taskfile.yml b/pkg/project/classic/Taskfile.yml index ba2e7dca..61205c9f 100644 --- a/pkg/project/classic/Taskfile.yml +++ b/pkg/project/classic/Taskfile.yml @@ -119,7 +119,7 @@ tasks: - 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 APM tool + desc: deploy AEM Service Pack cmds: - sh aemw package deploy --file "aem/home/lib/aem-service-pkg-6.5.*.0.zip" From 90da4c64bd601de9ba69358d822a5fda91e7d14f Mon Sep 17 00:00:00 2001 From: Krystian Panek Date: Fri, 17 Feb 2023 22:51:29 +0100 Subject: [PATCH 3/9] Status task --- pkg/project/classic/Taskfile.yml | 11 +++++++++-- pkg/project/cloud/Taskfile.yml | 11 +++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/pkg/project/classic/Taskfile.yml b/pkg/project/classic/Taskfile.yml index 61205c9f..3431b020 100644 --- a/pkg/project/classic/Taskfile.yml +++ b/pkg/project/classic/Taskfile.yml @@ -67,6 +67,13 @@ tasks: - sh aemw instance create - sh aemw instance up + 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] @@ -125,13 +132,13 @@ tasks: aem:destroy: desc: destroy AEM instances - deps: [undeploy, stop] + deps: [aem:stop] cmds: [sh aemw instance destroy] aem:stop: desc: stop AEM instances aliases: [aem:down] - cmds: [sh aemw instance start] + cmds: [sh aemw instance stop] aem:build: desc: build AEM application diff --git a/pkg/project/cloud/Taskfile.yml b/pkg/project/cloud/Taskfile.yml index 5b8b9fec..81d42387 100644 --- a/pkg/project/cloud/Taskfile.yml +++ b/pkg/project/cloud/Taskfile.yml @@ -67,6 +67,13 @@ tasks: - sh aemw instance create - sh aemw instance up + 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] @@ -119,13 +126,13 @@ tasks: aem:destroy: desc: destroy AEM instances - deps: [undeploy, stop] + deps: [aem:stop] cmds: [sh aemw instance destroy] aem:stop: desc: stop AEM instances aliases: [aem:down] - cmds: [sh aemw instance start] + cmds: [sh aemw instance stop] aem:build: desc: build AEM application From 3da8a157c29a66e4a564029cbba46f87192b7c3a Mon Sep 17 00:00:00 2001 From: Krystian Panek Date: Fri, 17 Feb 2023 23:47:08 +0100 Subject: [PATCH 4/9] Task wrapper installation --- project/aemw | 65 ++++++++++++++++++++++-------- project/init.sh | 9 ++++- project/taskw | 102 ++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 154 insertions(+), 22 deletions(-) diff --git a/project/aemw b/project/aemw index 4659ffe0..da1dab88 100755 --- a/project/aemw +++ b/project/aemw @@ -5,30 +5,61 @@ VERSION=${AEM_CLI_VERSION:-"1.0.5"} # Define API # ========== -detect_os () { - case "$(uname)" in - 'Linux') - echo "linux" - ;; - 'Darwin') - echo "darwin" - ;; - *) - echo "windows" - ;; - esac +# https://github.com/client9/shlib/blob/master/uname_os.sh +detect_os() { + os=$(uname -s | tr '[:upper:]' '[:lower:]') + + # fixed up for https://github.com/client9/shlib/issues/3 + case "$os" in + msys*) os="windows" ;; + mingw*) os="windows" ;; + cygwin*) os="windows" ;; + win*) os="windows" ;; # for windows busybox and like # https://frippery.org/busybox/ + esac + + # other fixups here + echo "$os" +} + +# https://github.com/client9/shlib/blob/master/uname_arch.sh +detect_arch() { + arch=$(uname -m) + case $arch in + x86_64) arch="amd64" ;; + x86) arch="386" ;; + i686) arch="386" ;; + i386) arch="386" ;; + aarch64) arch="arm64" ;; + armv5*) arch="armv5" ;; + armv6*) arch="armv6" ;; + armv7*) arch="armv7" ;; + esac + echo ${arch} } -detect_arch () { - uname -m +# https://github.com/client9/shlib/blob/master/http_download.sh +download_file() { + local_file=$1 + source_url=$2 + header=$3 + if [ -z "$header" ]; then + code=$(curl -w '%{http_code}' -sL -o "$local_file" "$source_url") + else + code=$(curl -w '%{http_code}' -sL -H "$header" -o "$local_file" "$source_url") + fi + if [ "$code" != "200" ]; then + echo "Error! Downloading file from URL '$source_url' received HTTP status '$code'" + return 1 + fi + return 0 } -download_file () { +download_file_once () { URL=$1 FILE=$2 if [ ! -f "${FILE}" ]; then mkdir -p "$(dirname "$FILE")" - curl -o "$FILE" -OJL "$URL" + download_file "$FILE" "$URL" fi } @@ -53,7 +84,7 @@ BIN_EXEC_FILE="${BIN_ARCHIVE_DIR}/${BIN_NAME}" if [ "${VERSION}" != "installed" ] ; then if [ ! -f "${BIN_EXEC_FILE}" ]; then mkdir -p "${BIN_ARCHIVE_DIR}" - download_file "${BIN_DOWNLOAD_URL}" "${BIN_ARCHIVE_FILE}" + download_file_once "${BIN_DOWNLOAD_URL}" "${BIN_ARCHIVE_FILE}" tar -xf "${BIN_ARCHIVE_FILE}" -C "${BIN_ARCHIVE_DIR}" chmod +x "${BIN_EXEC_FILE}" fi diff --git a/project/init.sh b/project/init.sh index 2a2e08e2..9af3b8d0 100644 --- a/project/init.sh +++ b/project/init.sh @@ -1,6 +1,7 @@ #!/usr/bin/env sh AEM_WRAPPER="aemw" +TASK_WRAPPER="taskw" if [ -f "$AEM_WRAPPER" ]; then echo "The project contains already AEM Compose!" @@ -9,14 +10,20 @@ fi SOURCE_URL="https://raw.githubusercontent.com/wttech/aemc/main/project" curl -s "${SOURCE_URL}/${AEM_WRAPPER}" -o "${AEM_WRAPPER}" +curl -s "${SOURCE_URL}/${TASK_WRAPPER}" -o "${TASK_WRAPPER}" echo "Downloading & Testing AEM Compose CLI" echo "" -chmod +x "${AEM_WRAPPER}" +chmod +x "${AEM_WRAPPER}" "${TASK_WRAPPER}" sh ${AEM_WRAPPER} version echo "Success! Now initialize AEM Compose by running the command:" echo "" echo "sh ${AEM_WRAPPER} project init --kind [auto|cloud|classic]" + +echo "After initialization review available project tasks by running the command:" +echo "" + +echo "sh ${TASK_WRAPPER} --list" diff --git a/project/taskw b/project/taskw index 44308d6c..c08aae01 100755 --- a/project/taskw +++ b/project/taskw @@ -1,11 +1,105 @@ #!/usr/bin/env sh -# Execute AEM Compose CLI -# ========================================== +VERSION=${TASK_VERSION:-"3.20.0"} -# TODO auto-download like in 'aemw' +# Define API +# ========== + +# https://github.com/client9/shlib/blob/master/uname_os.sh +detect_os() { + os=$(uname -s | tr '[:upper:]' '[:lower:]') + + # fixed up for https://github.com/client9/shlib/issues/3 + case "$os" in + msys*) os="windows" ;; + mingw*) os="windows" ;; + cygwin*) os="windows" ;; + win*) os="windows" ;; # for windows busybox and like # https://frippery.org/busybox/ + esac + + # other fixups here + echo "$os" +} + +# https://github.com/client9/shlib/blob/master/uname_arch.sh +detect_arch() { + arch=$(uname -m) + case $arch in + x86_64) arch="amd64" ;; + x86) arch="386" ;; + i686) arch="386" ;; + i386) arch="386" ;; + aarch64) arch="arm64" ;; + armv5*) arch="armv5" ;; + armv6*) arch="armv6" ;; + armv7*) arch="armv7" ;; + esac + echo ${arch} +} + +# https://github.com/client9/shlib/blob/master/http_download.sh +download_file() { + local_file=$1 + source_url=$2 + header=$3 + if [ -z "$header" ]; then + code=$(curl -w '%{http_code}' -sL -o "$local_file" "$source_url") + else + code=$(curl -w '%{http_code}' -sL -H "$header" -o "$local_file" "$source_url") + fi + if [ "$code" != "200" ]; then + echo "Error! Downloading file from URL '$source_url' received HTTP status '$code'" + return 1 + fi + return 0 +} + +download_file_once () { + URL=$1 + FILE=$2 + if [ ! -f "${FILE}" ]; then + mkdir -p "$(dirname "$FILE")" + download_file "$FILE" "$URL" + fi +} + +# Download tool +# ============= + +OS=$(detect_os) +ARCH=$(detect_arch) + +AEM_DIR="aem" +HOME_DIR="${AEM_DIR}/home" +DOWNLOAD_DIR="${HOME_DIR}/opt" + +BIN_DOWNLOAD_NAME="task" +BIN_ARCHIVE_EXT="tar.gz" +if [ "$OS" = "windows" ] ; then + BIN_ARCHIVE_EXT="zip" +fi +BIN_DOWNLOAD_URL="https://github.com/go-task/task/releases/download/v${VERSION}/${BIN_DOWNLOAD_NAME}_${OS}_${ARCH}.${BIN_ARCHIVE_EXT}" +BIN_ROOT="${DOWNLOAD_DIR}/${BIN_DOWNLOAD_NAME}/${VERSION}" +BIN_ARCHIVE_FILE="${BIN_ROOT}/${BIN_DOWNLOAD_NAME}.${BIN_ARCHIVE_EXT}" +BIN_ARCHIVE_DIR="${BIN_ROOT}/${BIN_DOWNLOAD_NAME}" +BIN_NAME="task" +BIN_EXEC_FILE="${BIN_ARCHIVE_DIR}/${BIN_NAME}" + +if [ ! -f "${BIN_EXEC_FILE}" ]; then + mkdir -p "${BIN_ARCHIVE_DIR}" + download_file_once "${BIN_DOWNLOAD_URL}" "${BIN_ARCHIVE_FILE}" + if [ "$BIN_ARCHIVE_EXT" = "tar.gz" ] ; then + tar -xf "${BIN_ARCHIVE_FILE}" -C "${BIN_ARCHIVE_DIR}" + else + unzip "${BIN_ARCHIVE_FILE}" -d "${BIN_ARCHIVE_DIR}" + fi + chmod +x "${BIN_EXEC_FILE}" +fi + +# Execute Task Tool +# ================= # https://taskfile.dev/api/#env export TASK_COLOR_GREEN=35 -task "$@" +"./${BIN_EXEC_FILE}" "$@" From c9739dfa2564a6e894557fc350dcb9a445eb2dd8 Mon Sep 17 00:00:00 2001 From: Krystian Panek Date: Fri, 17 Feb 2023 23:49:58 +0100 Subject: [PATCH 5/9] Docker status task --- pkg/project/classic/Taskfile.yml | 5 +++++ pkg/project/cloud/Taskfile.yml | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/pkg/project/classic/Taskfile.yml b/pkg/project/classic/Taskfile.yml index 3431b020..5e608948 100644 --- a/pkg/project/classic/Taskfile.yml +++ b/pkg/project/classic/Taskfile.yml @@ -176,3 +176,8 @@ tasks: cmds: - task: docker-stop - task: docker-start + + docker:status: + desc: list Docker containers + cmds: + - docker compose ps diff --git a/pkg/project/cloud/Taskfile.yml b/pkg/project/cloud/Taskfile.yml index 81d42387..666ff6e8 100644 --- a/pkg/project/cloud/Taskfile.yml +++ b/pkg/project/cloud/Taskfile.yml @@ -167,3 +167,8 @@ tasks: cmds: - task: docker-stop - task: docker-start + + docker:status: + desc: list Docker containers + cmds: + - docker compose ps From 69e6e83a8785720dd1726f8734bf4268753adebf Mon Sep 17 00:00:00 2001 From: Krystian Panek Date: Sat, 18 Feb 2023 00:44:08 +0100 Subject: [PATCH 6/9] No color output setting --- cmd/aem/cli.go | 8 +++++++- pkg/cfg/config.go | 1 + pkg/cfg/defaults.go | 2 ++ pkg/cfg/values.go | 7 ++++--- pkg/project/classic/Taskfile.yml | 5 +---- pkg/project/cloud/Taskfile.yml | 5 +---- 6 files changed, 16 insertions(+), 12 deletions(-) diff --git a/cmd/aem/cli.go b/cmd/aem/cli.go index 08ed43ef..3c648cfe 100644 --- a/cmd/aem/cli.go +++ b/cmd/aem/cli.go @@ -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 { @@ -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 @@ -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 @@ -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) diff --git a/pkg/cfg/config.go b/pkg/cfg/config.go index cb6f5382..37353a53 100644 --- a/pkg/cfg/config.go +++ b/pkg/cfg/config.go @@ -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 { diff --git a/pkg/cfg/defaults.go b/pkg/cfg/defaults.go index 5e0e13f5..cddcded3 100644 --- a/pkg/cfg/defaults.go +++ b/pkg/cfg/defaults.go @@ -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" @@ -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) diff --git a/pkg/cfg/values.go b/pkg/cfg/values.go index 61bdb75a..602266eb 100644 --- a/pkg/cfg/values.go +++ b/pkg/cfg/values.go @@ -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"` diff --git a/pkg/project/classic/Taskfile.yml b/pkg/project/classic/Taskfile.yml index 5e608948..313baddb 100644 --- a/pkg/project/classic/Taskfile.yml +++ b/pkg/project/classic/Taskfile.yml @@ -115,10 +115,7 @@ tasks: 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" + - '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 diff --git a/pkg/project/cloud/Taskfile.yml b/pkg/project/cloud/Taskfile.yml index 666ff6e8..ff065834 100644 --- a/pkg/project/cloud/Taskfile.yml +++ b/pkg/project/cloud/Taskfile.yml @@ -114,10 +114,7 @@ tasks: 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" + - '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 From ebcddfc189080c52f8c4011a41605da5606938e5 Mon Sep 17 00:00:00 2001 From: Krystian Panek Date: Sat, 18 Feb 2023 00:50:32 +0100 Subject: [PATCH 7/9] Missing dep --- pkg/project/classic/Taskfile.yml | 4 +++- pkg/project/cloud/Taskfile.yml | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/project/classic/Taskfile.yml b/pkg/project/classic/Taskfile.yml index 313baddb..17daeb78 100644 --- a/pkg/project/classic/Taskfile.yml +++ b/pkg/project/classic/Taskfile.yml @@ -12,6 +12,7 @@ vars: APM_VERSION: 5.5.1 tasks: + setup: desc: setup AEM environment cmds: @@ -149,6 +150,7 @@ tasks: aem:deploy: desc: deploy AEM application + deps: [aem:build] cmds: - sh aemw package deploy --file "all/target/*.all-*.zip" @@ -156,7 +158,7 @@ tasks: desc: start Docker containers aliases: [docker:up] cmds: - - > + - > mkdir -p aem/home/var/dispatcher/httpd/logs aem/home/var/dispatcher/httpd/cache diff --git a/pkg/project/cloud/Taskfile.yml b/pkg/project/cloud/Taskfile.yml index ff065834..a60279c3 100644 --- a/pkg/project/cloud/Taskfile.yml +++ b/pkg/project/cloud/Taskfile.yml @@ -143,6 +143,7 @@ tasks: aem:deploy: desc: deploy AEM application + deps: [aem:build] cmds: - sh aemw package deploy --file "all/target/*.all-*.zip" From d8c15e7831c3d893af17326c1cc44cb83a59df88 Mon Sep 17 00:00:00 2001 From: Krystian Panek Date: Sat, 18 Feb 2023 00:57:39 +0100 Subject: [PATCH 8/9] Tmp task dir --- project/taskw | 1 + 1 file changed, 1 insertion(+) diff --git a/project/taskw b/project/taskw index c08aae01..659f29b7 100755 --- a/project/taskw +++ b/project/taskw @@ -101,5 +101,6 @@ fi # https://taskfile.dev/api/#env export TASK_COLOR_GREEN=35 +export TASK_TEMP_DIR="${AEM_DIR}/tmp/task" "./${BIN_EXEC_FILE}" "$@" From c50828abbb09d574eb0fd9c4c649dc481c8d569b Mon Sep 17 00:00:00 2001 From: Krystian Panek Date: Sat, 18 Feb 2023 13:55:36 +0100 Subject: [PATCH 9/9] Classic tasks clean up --- pkg/project/classic/Taskfile.yml | 20 ++++++++++++++------ pkg/project/classic/dispatcher/build.sh | 3 --- pkg/project/cloud/Taskfile.yml | 6 ++++++ 3 files changed, 20 insertions(+), 9 deletions(-) delete mode 100755 pkg/project/classic/dispatcher/build.sh diff --git a/pkg/project/classic/Taskfile.yml b/pkg/project/classic/Taskfile.yml index 17daeb78..03e33bda 100644 --- a/pkg/project/classic/Taskfile.yml +++ b/pkg/project/classic/Taskfile.yml @@ -68,6 +68,12 @@ tasks: - 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: @@ -146,7 +152,6 @@ tasks: --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" - - cd dispatcher && sh build.sh aem:deploy: desc: deploy AEM application @@ -154,15 +159,18 @@ tasks: 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 + - 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: diff --git a/pkg/project/classic/dispatcher/build.sh b/pkg/project/classic/dispatcher/build.sh deleted file mode 100755 index 2cfc73a7..00000000 --- a/pkg/project/classic/dispatcher/build.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env sh - -docker build -t acme/aem-ams/dispatcher-publish . diff --git a/pkg/project/cloud/Taskfile.yml b/pkg/project/cloud/Taskfile.yml index a60279c3..4847059a 100644 --- a/pkg/project/cloud/Taskfile.yml +++ b/pkg/project/cloud/Taskfile.yml @@ -67,6 +67,12 @@ tasks: - 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: