From caf6bef273b975795c39005e903cfb344a692265 Mon Sep 17 00:00:00 2001 From: Shunsuke Suzuki Date: Thu, 9 May 2024 09:00:07 +0900 Subject: [PATCH] fix: support non root user and install specified aqua version (#16) * fix: add a test of non root user * fix: support non root user * refactor: remove unnecessary redirect * refactor: remove debug codes * fix: specify aqua version * fix: use aqua-installer -v option * chore: update version --- src/aqua-installer/devcontainer-feature.json | 2 +- src/aqua-installer/install.sh | 30 ++++++++++++++----- test/aqua-installer/alpine-nonroot.sh | 5 ++++ test/aqua-installer/alpine-nonroot/Dockerfile | 6 ++++ test/aqua-installer/scenarios.json | 13 ++++++++ 5 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 test/aqua-installer/alpine-nonroot.sh create mode 100644 test/aqua-installer/alpine-nonroot/Dockerfile diff --git a/src/aqua-installer/devcontainer-feature.json b/src/aqua-installer/devcontainer-feature.json index 588d60a..58c3efb 100644 --- a/src/aqua-installer/devcontainer-feature.json +++ b/src/aqua-installer/devcontainer-feature.json @@ -1,7 +1,7 @@ { "name": "aqua-installer", "id": "aqua-installer", - "version": "0.1.0", + "version": "0.1.1", "description": "Install aqua", "options": { "aqua_version": { diff --git a/src/aqua-installer/install.sh b/src/aqua-installer/install.sh index e5edf80..980f96e 100644 --- a/src/aqua-installer/install.sh +++ b/src/aqua-installer/install.sh @@ -30,7 +30,7 @@ if ! has_command curl && ! has_command wget; then if has_command apt-get; then apt-get update -y apt-get install -y curl - elif has_command apk > /dev/null 2>&1; then + elif has_command apk; then apk add curl else log_error "Neither curl nor wget is found. Please install either curl or wget to download aqua" @@ -38,12 +38,13 @@ if ! has_command curl && ! has_command wget; then fi fi -pwd -ls - url=https://raw.githubusercontent.com/aquaproj/aqua-installer/v3.0.0/aqua-installer -tempdir=$(mktemp -d) +if [ "$_REMOTE_USER" = root ]; then + tempdir=$(mktemp -d) +else + tempdir=$(sudo -u "$_REMOTE_USER" mktemp -d) +fi cd "$tempdir" if has_command curl; then @@ -54,7 +55,22 @@ fi echo "8299de6c19a8ff6b2cc6ac69669cf9e12a96cece385658310aea4f4646a5496d aqua-installer" | sha256sum -c -chmod +x aqua-installer -./aqua-installer +chmod a+x aqua-installer +if [ "$_REMOTE_USER" = root ]; then + ./aqua-installer -v "$AQUA_VERSION" +else + if ! has_command sudo; then + if has_command apt-get; then + apt-get update -y + apt-get install -y sudo + elif has_command apk; then + apk add sudo + else + log_error "Please install sudo to run aqua-installer as $_REMOTE_USER" + exit 1 + fi + fi + sudo -u "$_REMOTE_USER" ./aqua-installer -v "$AQUA_VERSION" +fi rm -R "$tempdir" diff --git a/test/aqua-installer/alpine-nonroot.sh b/test/aqua-installer/alpine-nonroot.sh new file mode 100644 index 0000000..af7adce --- /dev/null +++ b/test/aqua-installer/alpine-nonroot.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +set -eu + +aqua -v diff --git a/test/aqua-installer/alpine-nonroot/Dockerfile b/test/aqua-installer/alpine-nonroot/Dockerfile new file mode 100644 index 0000000..fbe9dd0 --- /dev/null +++ b/test/aqua-installer/alpine-nonroot/Dockerfile @@ -0,0 +1,6 @@ +FROM alpine:3.19.1 +RUN apk add sudo && \ + sed -i "s|# %wheel ALL=(ALL:ALL) NOPASSWD: ALL|%wheel ALL=(ALL:ALL) NOPASSWD: ALL|" /etc/sudoers && \ + adduser -u 1000 -G wheel -D vscode && \ + rm -rf /var/cache/apk/* +USER vscode diff --git a/test/aqua-installer/scenarios.json b/test/aqua-installer/scenarios.json index d9edea6..caafed6 100644 --- a/test/aqua-installer/scenarios.json +++ b/test/aqua-installer/scenarios.json @@ -20,5 +20,18 @@ "aqua_version": "v2.27.0" } } + }, + "alpine-nonroot": { + "build": { + "dockerfile": "Dockerfile" + }, + "remoteEnv": { + "PATH": "/home/vscode/.local/share/aquaproj-aqua/bin:${containerEnv:PATH}" + }, + "features": { + "aqua-installer": { + "aqua_version": "v2.27.0" + } + } } }