Skip to content

Commit 9c84998

Browse files
dploegerDennis Ploeger
authored andcommitted
feat: Optimized documentation and feature utils
Added template for new features
1 parent c355007 commit 9c84998

6 files changed

Lines changed: 109 additions & 5 deletions

File tree

README.md.gotmpl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,14 +283,24 @@ environment variable in the docker-compose file. Then you can debug with the run
283283

284284
## Development
285285

286-
*CloudControl* supports a decoupled development of features and flavours. If you're missing something, just fork this
287-
repository, create a subfolder for your new feature under "features" and add these files:
286+
*CloudControl* supports a decoupled development of features and flavours.
287+
288+
### Features
289+
290+
If you're missing a feature, just fork this repository, copy the feature template from features/.template into a
291+
new subfolder, check out the comments in the example files, and modify them to your needs.
292+
293+
These files make up a feature:
288294

289295
* `feature.yaml`: A descriptor for your feature with a title, a description and configuration notes
290296
* `install.sh`: A shell script that is run by CloudControlCenter and should install everything you need
291297
for your new feature
292298
* `motd.sh`: (optional) If you want to show some information to the users upon login, put them here.
293299

300+
And an optional, but recommended `.goss` folder for [integration testing](#integration-testing).
301+
302+
### Flavours
303+
294304
If you need another flavour (aka cloud provider), add a new subdirectory under "flavour" and add a flavour.yaml describing
295305
your flavour the same way as a feature. For the rest of the files, please check out existing flavours for details. Please,
296306
include a sample configuration for your flavour to make it easier for other people to work with it.

assets/feature-installer-utils.sh

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,31 @@
1-
# Execute a command and if it fails, return its output and exit
1+
# Set some informative variables
2+
3+
# The flavour we're running on
4+
FLAVOUR="$(cat /home/cloudcontrol/flavour)"
5+
export FLAVOUR
6+
7+
# The path to install software binaries to
8+
BINPATH="/home/cloudcontrol/bin"
9+
export BINPATH
10+
11+
TEMPDIR=""
12+
export TEMPDIR
13+
14+
# Prepare feature installation. Will create a temporary directory and change to it
15+
function prepare {
16+
TEMPDIR=$(mktemp -d)
17+
cd "${TEMPDIR}" || exit
18+
}
19+
20+
# Cleanup the previously generated temporary directory
21+
function cleanup {
22+
cd - &>/dev/null || exit
23+
rm -rf "${TEMPDIR}"
24+
}
25+
26+
# Usage: execHandle MESSAGE COMMAND...
27+
#
28+
# Output MESSAGE and then execute COMMAND. If it fails, return its output and exit
229
function execHandle {
330
TITLE=$1
431
shift
@@ -38,6 +65,7 @@ function waitForMfaCode {
3865
echo "[VALID_CODE] Valid code entered. Thank you."
3966
}
4067

68+
# Get the hardware platform we're on and translate it to the usual platform names used in most software
4169
function getPlatform {
4270
if [ "$(uname -m)" == 'aarch64' ]
4371
then
@@ -50,18 +78,32 @@ function getPlatform {
5078
fi
5179
}
5280

81+
# Usage: checkAndCleanVersion VERSION
82+
#
83+
# Includes checks for version numbers and removes the "v" prefix from it to have a homogeneous version scheme
84+
# throughout CloudControl.
5385
function checkAndCleanVersion {
5486
VERSION=$1
5587
if [ "${VERSION:0:1}" == "v" ]
5688
then
57-
echo "[DEPRECATION WARNING] Versions with a \"v\" prefix are deprecated and will be removed in CloudControl 4.0. Please only use versions without the \"v\" prefix. (Got \"${VERSION}\")" >&2
89+
echo "[DEPRECATION WARNING] Versions with a \"v\" prefix are deprecated and will be removed in CloudControl 6.0.0 Please only use versions without the \"v\" prefix. (Got \"${VERSION}\")" >&2
5890
echo "${VERSION/#v/}"
5991
else
6092
echo "${VERSION}"
6193
fi
6294
}
6395

96+
# Usage: download URL FILENAME
97+
#
98+
# Downloads the given URL into the provided FILENAME
99+
function download {
100+
URL=$1
101+
FILENAME=$2
102+
execHandle "Downloading ${FILENAME} from ${URL}" curl -f -s -L "${URL}" -o "${FILENAME}"
103+
}
104+
64105
# Usage: downloadFromGithub USER REPO VERSION PACKAGE_PREFIX PACKAGE_SUFFIX TARGET
106+
#
65107
# Downloads a release package from github using the common architecture names
66108
# The package will be downloaded from github.com/USER/REPO/releases/VERSION/download/PACKAGE to the given TARGET file
67109
# where PACKAGE consists of PACKAGE_PREFIXARCHITECTURE.PACKAGE_SUFFIX.
@@ -77,4 +119,4 @@ function downloadFromGithub {
77119
ARCH="$(uname -m | sed -e 's/x86_64/amd64/' -e 's/\(arm\)\(64\)\?.*/\1\2/' -e 's/aarch64$/arm64/')"
78120
PACKAGE="${PACKAGE_PREFIX}${ARCH}.${PACKAGE_SUFFIX}"
79121
execHandle "Downloading ${USER}/${REPO}@${VERSION}" curl -f -s -L "https://github.com/${USER}/${REPO}/releases/${VERSION}/download/${PACKAGE}" --output "${TARGET}"
80-
}
122+
}

feature/.template/feature.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# This is the metadata manifest for a feature. Configure it for the feature to be included in CloudControl
2+
# In your new feature, please remove all descriptive comments from the template.
3+
4+
# Please use an emoji character as a meaningful logo for your feature
5+
icon: "⚙️"
6+
7+
# Set the title for this feature
8+
title: "Direnv"
9+
10+
# Set the description of the feature in Markdown. Be sure to include links to websites of the software the feature
11+
# installs or configures
12+
description: "Installs [Direnv](https://direnv.net/)"
13+
14+
# Use the configuration key to list additional configuration options that you're providing in your feature
15+
configuration:
16+
#- |
17+
# Environment EXAMPLE_ENVIRONMENT: This environment variable is used in the feature to do xyz (optional)
18+
# Defaults to `abc`

feature/.template/goss/.envrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Setup required environment for test
2+
export EXAMPLE_ENVIRONMENT=something

feature/.template/goss/goss.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
command:
2+
test:
3+
# Run ls / after installing the feature and if that returns successfully, the test is successful
4+
exec: "ls /"
5+
exit-status: 0

feature/.template/install.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# The installer script for your feature, which is called in the init phase of CloudControl
2+
3+
# Include the feature installer utils which include helpers for the installation of your feature
4+
# See /assets/feature-installer-utils.sh
5+
6+
. /feature-installer-utils.sh
7+
8+
# Create a temporary directory to work in
9+
prepare
10+
11+
if [ "X${FLAVOUR}X" == "XsimpleX" ]
12+
then
13+
# Do specific things for the simple flavour
14+
download "https://example.com/my-tool-for-simple.tar.gz" tool.tar.gz
15+
elif [[ "X${FLAVOR}X" =~ X(azure|gcloud)X ]]
16+
then
17+
# Do specific things for other flavours
18+
download "https://example.com/my-tool-for-others.tar.gz" tool.tar.gz
19+
fi
20+
21+
# Do other things
22+
execHandle "Extracting tool" tar xzf tool.tar.gz
23+
execHandle "Making tool executable" chmod +x tool
24+
execHandle "Copying tool to ${BINPATH}" cp tool "${BINPATH}"
25+
26+
# Cleanup what we did
27+
cleanup

0 commit comments

Comments
 (0)