diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 3b57b9b..8a080cd 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -34,7 +34,8 @@ jobs: matrix: features: - clusterctl - + - air + steps: - uses: actions/checkout@v4 diff --git a/README.md b/README.md index 26c5dc3..09394c5 100644 --- a/README.md +++ b/README.md @@ -10,3 +10,11 @@ It contains development features following the [Development Containers](https:// ### [`clusterctl`](src/clusterctl/README.md) Install the `clusterctl` CLI for the Cluster API. + +### [`air`](src/air/README.md) + +Install the `air` CLI for live-reloading Go applications. + +## License + +[MIT](/LICENSE) diff --git a/src/air/README.md b/src/air/README.md new file mode 100644 index 0000000..3d5f71a --- /dev/null +++ b/src/air/README.md @@ -0,0 +1,24 @@ + +# clusterctl CLI (clusterctl) + +The clusterctl CLI tool handles the lifecycle of a Cluster API management cluster. + +## Example Usage + +```json +"features": { + "ghcr.io/ZEISS/devcontainer-features/clusterctl:1": {} +} +``` + +## Options + +| Options Id | Description | Type | Default Value | +|-----|-----|-----|-----| +| version | Select or enter clusterctl version to install. | string | v1.8.3 | + + + +--- + +_Note: This file was auto-generated from the [devcontainer-feature.json](https://github.com/ZEISS/devcontainer-features/blob/main/src/clusterctl/devcontainer-feature.json). Add additional notes to a `NOTES.md`._ diff --git a/src/air/devcontainer-feature.json b/src/air/devcontainer-feature.json new file mode 100644 index 0000000..1dfe054 --- /dev/null +++ b/src/air/devcontainer-feature.json @@ -0,0 +1,19 @@ +{ + "name": "Air - Live reload for Go apps", + "id": "air", + "version": "1.0.0", + "description": "Air - Live reload for Go apps", + "options": { + "version": { + "type": "string", + "proposals": [ + "1.61.0" + ], + "default": "1.61.0", + "description": "Select or enter air version to install." + } + }, + "installsAfter": [ + "ghcr.io/devcontainers/features/common-utils" + ] +} \ No newline at end of file diff --git a/src/air/install.sh b/src/air/install.sh new file mode 100755 index 0000000..db3ca5d --- /dev/null +++ b/src/air/install.sh @@ -0,0 +1,62 @@ +#!/bin/sh +set -e + +echo "Activating feature 'air'" + +# Default version +VERSION=${VERSION:-"latest"} + +# Defailt install path +BIN=${BIN:-/usr/local/bin} + +echo "Installing air version $VERSION" + +# Clean up +rm -rf /var/lib/apt/lists/* + +echo "Step 1, check if user is root" +if [ "$(id -u)" -ne 0 ]; then + echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.' + exit 1 +fi + +echo "Step 2, check if architecture is supported" +ARCHITECTURE="$(uname -m | sed s/aarch64/arm64/ | sed s/x86_64/amd64/)" +if [ "${ARCHITECTURE}" != "amd64" ] && [ "${ARCHITECTURE}" != "x86_64" ] && [ "${ARCHITECTURE}" != "arm64" ] && [ "${ARCHITECTURE}" != "aarch64" ]; then + echo "(!) Architecture $ARCHITECTURE unsupported" + exit 1 +fi + +echo "Step 3, check the os in small case" +OS="$(uname -s | tr '[:upper:]' '[:lower:]')" + +apt_get_update() +{ + if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then + echo "Running apt-get update..." + apt-get update -y + fi +} + +# Checks if packages are installed and installs them if not +check_packages() { + if ! dpkg -s "$@" > /dev/null 2>&1; then + apt_get_update + apt-get -y install --no-install-recommends "$@" + fi +} + +export DEBIAN_FRONTEND=noninteractive + +# Install dependencies +check_packages ca-certificates curl unzip + +# Install air + +curl -sSL "https://github.com/air-verse/air/releases/download/v${VERSION}/air_${VERSION}_${OS}_${ARCHITECTURE}" -o "${BIN}/air" +chmod +x "${BIN}/air" + +# Clean up +rm -rf /var/lib/apt/lists/* + +echo "Done!" \ No newline at end of file diff --git a/test/air/test.sh b/test/air/test.sh new file mode 100644 index 0000000..a12a6cb --- /dev/null +++ b/test/air/test.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +set -e + +# Clean up +rm -rf /var/lib/apt/lists/* + +if [ "$(id -u)" -ne 0 ]; then + echo -e 'Script must be run as root to be able to installe dependencies, changing to sudo when installing.' +fi + +apt_get_update() { + if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then + echo "Running apt-get update..." + if [ "$(id -u)" -ne 0 ]; then + sudo apt-get update -y + else + apt-get update -y + fi + fi +} + +check_packages() { + if ! dpkg -s "$@" >/dev/null 2>&1; then + apt_get_update + if [ "$(id -u)" -ne 0 ]; then + sudo apt-get -y install --no-install-recommends "$@" + else + apt-get -y install --no-install-recommends "$@" + fi + fi +} +export DEBIAN_FRONTEND=noninteractive + +check_packages ca-certificates curl unzip + +# 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 "version" air -v + +# Report results +# If any of the checks above exited with a non-zero exit code, the test will fail. +reportResults \ No newline at end of file