Skip to content

Commit

Permalink
feat: adding air live reload command
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie authored Oct 12, 2024
1 parent 416d26e commit d8dfefc
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ jobs:
matrix:
features:
- clusterctl

- air

steps:
- uses: actions/checkout@v4

Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
24 changes: 24 additions & 0 deletions src/air/README.md
Original file line number Diff line number Diff line change
@@ -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`._
19 changes: 19 additions & 0 deletions src/air/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
62 changes: 62 additions & 0 deletions src/air/install.sh
Original file line number Diff line number Diff line change
@@ -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!"
46 changes: 46 additions & 0 deletions test/air/test.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d8dfefc

Please sign in to comment.