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

Commit 73f77e8

Browse files
committed
Add aqua feature
1 parent 9a1d24b commit 73f77e8

File tree

5 files changed

+149
-0
lines changed

5 files changed

+149
-0
lines changed

src/aqua/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
# aqua (aqua)
3+
4+
Declarative CLI Version Manager
5+
6+
## Example Usage
7+
8+
```json
9+
"features": {
10+
"ghcr.io/devcontainers-contrib/features/aqua:1": {}
11+
}
12+
```
13+
14+
## Options
15+
16+
| Options Id | Description | Type | Default Value |
17+
|-----|-----|-----|-----|
18+
| version | Select or enter an aqua version | string | latest |
19+
| installerVersion | Select or enter an aqua installer version | string | latest |
20+
| aquaRootDir | The directory path where aqua install tools | string | /usr/local/share/aquaproj-aqua |

src/aqua/devcontainer-feature.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"id": "aqua",
3+
"name": "aqua",
4+
"version": "1.0.0",
5+
"description": "Declarative CLI Version Manager",
6+
"documentationURL": "https://github.com/C-FO/devcontainer-features/tree/main/src/aqua/README.md",
7+
"options": {
8+
"version": {
9+
"type": "string",
10+
"description": "Select or enter an aqua version",
11+
"proposals": ["latest"],
12+
"default": "latest"
13+
},
14+
"installerVersion": {
15+
"type": "string",
16+
"description": "Select or enter an aqua installer version",
17+
"proposals": ["latest"],
18+
"default": "latest"
19+
},
20+
"aquaRootDir": {
21+
"type": "string",
22+
"description": "The directory path where aqua install tools",
23+
"default": "/usr/local/share/aquaproj-aqua"
24+
}
25+
}
26+
}

src/aqua/intall.sh

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/usr/bin/env bash
2+
3+
set -eu -o pipefail
4+
5+
if [ "$(id -u)" -ne 0 ]; then
6+
echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
7+
exit 1
8+
fi
9+
10+
add_global_run_command() {
11+
local command=$1
12+
13+
if [ -f "/etc/os-release" ] && grep "ID_LIKE=.*alpine.*\|ID=.*alpine.*" /etc/os-release; then
14+
if [ -f "/etc/profile" ] && [[ "$(cat /etc/profile)" != *"${command}"* ]]; then
15+
echo "Add ${command} to /etc/profile"
16+
echo -e "${command}" >>/etc/profile
17+
fi
18+
fi
19+
20+
if [ -f "/etc/bash.bashrc" ] && [[ "$(cat /etc/bash.bashrc)" != *"${command}"* ]]; then
21+
echo "Add ${command} to /etc/bash.bashrc"
22+
echo -e "${command}" >>/etc/bash.bashrc
23+
fi
24+
25+
if [ -f "/etc/zsh/zshrc" ] && [[ "$(cat /etc/zsh/zshrc)" != *"${command}"* ]]; then
26+
echo "Add ${command} to /etc/zsh/zshrc"
27+
echo -e "${command}" >>/etc/zsh/zshrc
28+
fi
29+
}
30+
31+
install_aqua_binary() {
32+
local aquq_root_dir=$1
33+
local aqua_installer_version=$2
34+
local aqua_version=$3
35+
36+
mkdir -p "${aquq_root_dir}"
37+
38+
local aqua_installer_ref='main'
39+
if [ -n "${aqua_installer_version}" ] && [ "${aqua_installer_version}" != 'latest' ]; then
40+
aqua_installer_ref="v${aqua_installer_version##v}"
41+
fi
42+
local aqua_installer_url="https://raw.githubusercontent.com/aquaproj/aqua-installer/${aqua_installer_ref}/aqua-installer"
43+
44+
local command="curl -fsSL \"${aqua_installer_url}\" | AQUA_ROOT_DIR=\"${aquq_root_dir}\" bash -s --"
45+
if [ -n "${aqua_version}" ] && [ "${aqua_version}" != 'latest' ]; then
46+
command="${command} -v v${aqua_version##v}"
47+
fi
48+
49+
bash -c "${command}"
50+
}
51+
52+
make_aqua_user_writable() {
53+
local aquq_root_dir=$1
54+
local aqua_user_name=$2
55+
56+
groupadd aqua
57+
gpasswd -a "${aqua_user_name}" aqua
58+
chgrp -R aqua "${aquq_root_dir}"
59+
chmod -R g+rws "${aquq_root_dir}"
60+
}
61+
62+
add_aqua_environment_variables() {
63+
local aquq_root_dir=$1
64+
65+
add_global_run_command "export AQUA_ROOT_DIR=\"${aquq_root_dir}\""
66+
add_global_run_command "if [[ \"\${PATH}\" != *\"\${AQUA_ROOT_DIR}/bin\"* ]]; then export PATH=\"\${PATH}:\${AQUA_ROOT_DIR}/bin\"; fi"
67+
}
68+
69+
install() {
70+
local aqua_root_dir=$1
71+
local aqua_installer_version=$2
72+
local aqua_version=$3
73+
local aqua_user_name=$4
74+
75+
install_aqua_binary "${aqua_root_dir}" "${aqua_installer_version}" "${aqua_version}"
76+
make_aqua_user_writable "${aqua_root_dir}" "${aqua_user_name}"
77+
add_aqua_environment_variables "${aqua_root_dir}"
78+
}
79+
80+
install "${AQUAROOTDIR:-/usr/local/share/aquaproj-aqua}" "${INSTALLERVERSION:-latest}" "${VERSION:-latest}" "${_REMOTE_USER:-root}"
81+
82+
echo "Done!"

test/aqua/scenarios.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"test": {
3+
"image": "mcr.microsoft.com/devcontainers/base:debian",
4+
"features": {
5+
"aqua": {}
6+
}
7+
}
8+
}

test/aqua/test.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
# Optional: Import test library
6+
# shellcheck disable=SC1091
7+
source dev-container-features-test-lib
8+
9+
# Definition specific tests
10+
check "aqua version" aqua --version
11+
12+
# Report result
13+
reportResults

0 commit comments

Comments
 (0)