Skip to content

Commit

Permalink
Add aem-universal-editor-service feature
Browse files Browse the repository at this point in the history
  • Loading branch information
juan-ayala committed Sep 12, 2024
1 parent 06b9819 commit 8a787de
Show file tree
Hide file tree
Showing 12 changed files with 197 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
features:
- aem-sdk
- aem-repo-tool
- aem-universal-editor-service
baseImage:
- mcr.microsoft.com/devcontainers/base:debian
- mcr.microsoft.com/devcontainers/base:ubuntu
Expand All @@ -34,6 +35,7 @@ jobs:
matrix:
features:
- aem-sdk
- aem-universal-editor-service
steps:
- uses: actions/checkout@v3

Expand Down
36 changes: 36 additions & 0 deletions src/aem-universal-editor-service/bin/start-ues
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env bash

source "${AEM_UES_FEATURE_DIR}/options.sh"

function ues_zip_not_found()
{
cat <<EOM
AEM Universal Editor Service zip not found.
uesDownloadsDirectory: '${AEM_UES_DOWNLOADS_DIR:-empty}'
uesVersion: '${AEM_UES_VERSION}'
EOM
exit 42
}

function get_ues_zip()
{
local searchdir="${AEM_UES_DOWNLOADS_DIR}"
[ ! -d ${searchdir} ] && return 1

local zip="${searchdir}/universal-editor-service-vprod-${AEM_UES_VERSION}.zip"
if [ "${AEM_UES_VERSION}" = "automatic" ]; then
zip="$(find ${searchdir} -maxdepth 1 -iname 'universal-editor-service-vprod-*.zip' -type f | sort -V | tail -n1)"
fi

[ ! -f "${zip}" ] && return 1 || echo "${zip}"
}

if [ ! -f "${AEM_UES_FEATURE_DIR}/universal-editor-service.cjs" ]; then
ueszip=$(get_ues_zip) || ues_zip_not_found
sudo unzip -d ${AEM_UES_FEATURE_DIR} ${ueszip}
fi

cd ${AEM_UES_FEATURE_DIR}
nvm install
nvm use
node universal-editor-service.cjs
30 changes: 30 additions & 0 deletions src/aem-universal-editor-service/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"id": "aem-universal-editor-service",
"version": "1.0.0",
"name": "Adobe Experience Manager Universal Editor Service",
"description": "Setup the AEM Universal Editor Service for local development.",
"options": {
"uesDownloadsDirectory": {
"type": "string",
"description": "Path to directory that contains one or more UES zip files downloaded from Adobe's Software Distribution.",
"default": ""
},
"uesVersion": {
"type": "string",
"description": "Universal Editor Service version.",
"default": "automatic"
},
"uesPort": {
"type": "string",
"description": "Universal Editor Service port.",
"default": "8000"
}
},
"containerEnv": {
"AEM_UES_FEATURE_DIR": "/aem-ues",
"PATH": "/aem-ues/bin:${PATH}"
},
"dependsOn": {
"ghcr.io/devcontainers/features/node:1": {}
}
}
29 changes: 29 additions & 0 deletions src/aem-universal-editor-service/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash

# create the feature directory
mkdir -p ${AEM_UES_FEATURE_DIR}

# save feature properties
propertiesFile="${AEM_UES_FEATURE_DIR}/options.sh"
echo "AEM_UES_DOWNLOADS_DIR=\"${UESDOWNLOADSDIRECTORY}\"" >> ${propertiesFile}
echo "AEM_UES_VERSION=\"${UESVERSION:-'automatic'}\"" >> ${propertiesFile}
echo "AEM_UES_PORT=\"${UESPORT:-'8000'}\"" >> ${propertiesFile}
source ${propertiesFile}

# copy custom scripts
cp -r "$(dirname $0)/bin" ${AEM_UES_FEATURE_DIR}

# create .nvmrc file
echo "20" > "${AEM_UES_FEATURE_DIR}/.nvmrc"

# create ssl cert and private key
openssl req -newkey rsa:2048 -nodes -keyout "${AEM_UES_FEATURE_DIR}/key.pem" \
-x509 -days 365 -out "${AEM_UES_FEATURE_DIR}/certificate.pem" -subj '/CN=localhost'

# create .env file
envfile="${AEM_UES_FEATURE_DIR}/.env"
echo "UES_PORT=${AEM_UES_PORT}" >> "${envfile}"
echo "UES_PRIVATE_KEY=./key.pem" >> "${envfile}"
echo "UES_CERT=./certificate.pem" >> "${envfile}"
echo "UES_TLS_REJECT_UNAUTHORIZED=false" >> "${envfile}"

20 changes: 20 additions & 0 deletions test/aem-universal-editor-service/defaults-with-zip.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

set -e

source dev-container-features-test-lib

# Check options file created with defaults
source ${AEM_UES_FEATURE_DIR}/options.sh
check "downloads directory set" \
echo "${AEM_UES_DOWNLOADS_DIR}" | grep -E "^/workspaces/[0-9]+/.devcontainer$"
check "ues version default" \
[ "${AEM_UES_VERSION}" = "automatic" ]
check "ues port default" \
[ "${AEM_UES_PORT}" = "8000" ]

# Check that ues installs and starts
check "can install & run ues" \
start-ues | grep "hello, world"

reportResults
Binary file not shown.
20 changes: 20 additions & 0 deletions test/aem-universal-editor-service/options-with-zip.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

set -e

source dev-container-features-test-lib

# Check options file created with defaults
source ${AEM_UES_FEATURE_DIR}/options.sh
check "downloads directory set" \
echo "${AEM_UES_DOWNLOADS_DIR}" | grep -E "^/workspaces/[0-9]+/.devcontainer$"
check "ues version default" \
[ "${AEM_UES_VERSION}" = "mock-2024.02.01" ]
check "ues port default" \
[ "${AEM_UES_PORT}" = "9090" ]

# Check that ues installs and starts
check "can install & run ues" \
start-ues | grep "hello, world"

reportResults
Binary file not shown.
20 changes: 20 additions & 0 deletions test/aem-universal-editor-service/scenarios.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"defaults-with-zip": {
"image": "mcr.microsoft.com/devcontainers/base:debian",
"features": {
"aem-universal-editor-service": {
"uesDownloadsDirectory": "${containerWorkspaceFolder}/.devcontainer"
}
}
},
"options-with-zip": {
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
"features": {
"aem-universal-editor-service": {
"uesDownloadsDirectory": "${containerWorkspaceFolder}/.devcontainer",
"uesVersion": "mock-2024.02.01",
"uesPort": "9090"
}
}
}
}
40 changes: 40 additions & 0 deletions test/aem-universal-editor-service/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash
#
# To run this test only, add the --skip-scenarios flag.
#
# devcontainer features test \
# --features aem-universal-editor-service \
# --skip-scenarios \
# --base-image mcr.microsoft.com/devcontainers/base
#

set -e

# Optional: Import test library bundled with the devcontainer CLI
source dev-container-features-test-lib

# Feature-specific tests
# The 'check' command comes from the dev-container-features-test-lib.

# Check options file created with defaults
source ${AEM_UES_FEATURE_DIR}/options.sh
check "downloads directory default" \
[ -z "${AEM_UES_DOWNLOADS_DIR}" ]
check "sdk version default" \
[ "${AEM_UES_VERSION}" = "automatic" ]
# Check start-ues in PATH is executable
check "start-ues is +x" \
stat -c '%A' $(which start-ues) | grep 'x.*x.*x'
# Check config files created
check "created .nvmrc" \
[ -f "${AEM_UES_FEATURE_DIR}/.nvmrc" ]
check "created key" \
[ -f "${AEM_UES_FEATURE_DIR}/key.pem" ]
check "created certificate" \
[ -f "${AEM_UES_FEATURE_DIR}/certificate.pem" ]
check "created .env" \
[ -f "${AEM_UES_FEATURE_DIR}/.env" ]

# Report result
# If any of the checks above exited with a non-zero exit code, the test will fail.
reportResults

0 comments on commit 8a787de

Please sign in to comment.