Skip to content
This repository was archived by the owner on Jan 12, 2025. It is now read-only.

Add aqua feature #619

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/aqua/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

# aqua (aqua)

Declarative CLI Version Manager

## Example Usage

```json
"features": {
"ghcr.io/devcontainers-contrib/features/aqua:1": {}
}
```

## Options

| Options Id | Description | Type | Default Value |
|-----|-----|-----|-----|
| version | Select or enter an aqua version | string | latest |
| installerVersion | Select or enter an aqua installer version | string | latest |
| aquaRootDir | The directory path where aqua install tools | string | /usr/local/share/aquaproj-aqua |
26 changes: 26 additions & 0 deletions src/aqua/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"id": "aqua",
"name": "aqua",
"version": "1.0.0",
"description": "Declarative CLI Version Manager",
"documentationURL": "https://github.com/C-FO/devcontainer-features/tree/main/src/aqua/README.md",
"options": {
"version": {
"type": "string",
"description": "Select or enter an aqua version",
"proposals": ["latest"],
"default": "latest"
},
"installerVersion": {
"type": "string",
"description": "Select or enter an aqua installer version",
"proposals": ["latest"],
"default": "latest"
},
"aquaRootDir": {
"type": "string",
"description": "The directory path where aqua install tools",
"default": "/usr/local/share/aquaproj-aqua"
}
}
}
82 changes: 82 additions & 0 deletions src/aqua/intall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/usr/bin/env bash

set -eu -o pipefail

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

add_global_run_command() {
local command=$1

if [ -f "/etc/os-release" ] && grep "ID_LIKE=.*alpine.*\|ID=.*alpine.*" /etc/os-release; then
if [ -f "/etc/profile" ] && [[ "$(cat /etc/profile)" != *"${command}"* ]]; then
echo "Add ${command} to /etc/profile"
echo -e "${command}" >>/etc/profile
fi
fi

if [ -f "/etc/bash.bashrc" ] && [[ "$(cat /etc/bash.bashrc)" != *"${command}"* ]]; then
echo "Add ${command} to /etc/bash.bashrc"
echo -e "${command}" >>/etc/bash.bashrc
fi

if [ -f "/etc/zsh/zshrc" ] && [[ "$(cat /etc/zsh/zshrc)" != *"${command}"* ]]; then
echo "Add ${command} to /etc/zsh/zshrc"
echo -e "${command}" >>/etc/zsh/zshrc
fi
}

install_aqua_binary() {
local aquq_root_dir=$1
local aqua_installer_version=$2
local aqua_version=$3

mkdir -p "${aquq_root_dir}"

local aqua_installer_ref='main'
if [ -n "${aqua_installer_version}" ] && [ "${aqua_installer_version}" != 'latest' ]; then
aqua_installer_ref="v${aqua_installer_version##v}"
fi
local aqua_installer_url="https://raw.githubusercontent.com/aquaproj/aqua-installer/${aqua_installer_ref}/aqua-installer"

local command="curl -fsSL \"${aqua_installer_url}\" | AQUA_ROOT_DIR=\"${aquq_root_dir}\" bash -s --"
if [ -n "${aqua_version}" ] && [ "${aqua_version}" != 'latest' ]; then
command="${command} -v v${aqua_version##v}"
fi

bash -c "${command}"
}

make_aqua_user_writable() {
local aquq_root_dir=$1
local aqua_user_name=$2

groupadd aqua
gpasswd -a "${aqua_user_name}" aqua
chgrp -R aqua "${aquq_root_dir}"
chmod -R g+rws "${aquq_root_dir}"
}

add_aqua_environment_variables() {
local aquq_root_dir=$1

add_global_run_command "export AQUA_ROOT_DIR=\"${aquq_root_dir}\""
add_global_run_command "if [[ \"\${PATH}\" != *\"\${AQUA_ROOT_DIR}/bin\"* ]]; then export PATH=\"\${PATH}:\${AQUA_ROOT_DIR}/bin\"; fi"
}

install() {
local aqua_root_dir=$1
local aqua_installer_version=$2
local aqua_version=$3
local aqua_user_name=$4

install_aqua_binary "${aqua_root_dir}" "${aqua_installer_version}" "${aqua_version}"
make_aqua_user_writable "${aqua_root_dir}" "${aqua_user_name}"
add_aqua_environment_variables "${aqua_root_dir}"
}

install "${AQUAROOTDIR:-/usr/local/share/aquaproj-aqua}" "${INSTALLERVERSION:-latest}" "${VERSION:-latest}" "${_REMOTE_USER:-root}"

echo "Done!"
8 changes: 8 additions & 0 deletions test/aqua/scenarios.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"test": {
"image": "mcr.microsoft.com/devcontainers/base:debian",
"features": {
"aqua": {}
}
}
}
13 changes: 13 additions & 0 deletions test/aqua/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

set -e

# Optional: Import test library
# shellcheck disable=SC1091
source dev-container-features-test-lib

# Definition specific tests
check "aqua version" aqua --version

# Report result
reportResults