Skip to content
Merged
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
7 changes: 4 additions & 3 deletions src/edgedb-cli/NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Shells: `bash`, `zsh`, `fish`

## Changelog

| Version | Notes |
| ------- | --------------- |
| 1.0.0 | Initial Version |
| Version | Notes |
| ------- | ---------------------- |
| 1.0.1 | Fix for non-root users |
| 1.0.0 | Initial Version |
2 changes: 1 addition & 1 deletion src/edgedb-cli/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "EdgeDB",
"id": "edgedb-cli",
"version": "1.0.0",
"version": "1.0.1",
"documentationURL": "https://github.com/joshuanianji/devcontainer-features/tree/main/src/edgedb-cli",
"description": "EdgeDB CLI via the official installation script. Includes the VSCode extension and mounts ~/.local/share/edgedb for data persistence.",
"options": {},
Expand Down
57 changes: 40 additions & 17 deletions src/edgedb-cli/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ LIFECYCLE_SCRIPTS_DIR="/usr/local/share/edgedb-cli/scripts"

set -e

# Checks if packages are installed and installs them if not
check_packages() {
if ! dpkg -s "$@" >/dev/null 2>&1; then
if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then
echo "Running apt-get update..."
apt-get update -y
fi
apt-get -y install --no-install-recommends "$@"
fi
}

create_cache_dir() {
if [ -d "$1" ]; then
echo "Cache directory $1 already exists. Skip creation..."
Expand All @@ -23,36 +34,48 @@ create_cache_dir() {
}

create_symlink_dir() {
# ln -s target_dir source_dir
local source_dir=$1
local target_dir=$2
# local dir is the folder edgedb will use
# cache_dir is the /dc/edgedb-cli folder
local local_dir=$1
local cache_dir=$2
local username=$3

if [ -d "$source_dir" ]; then
echo "Symlink $source_dir to $target_dir..."
ln -s "$source_dir" "$target_dir"
else
echo "Creating source dir $source_dir..."
mkdir -p "$source_dir"
fi
runuser -u "$username" -- mkdir -p "$(dirname "$local_dir")"
runuser -u "$username" -- mkdir -p "$cache_dir"

# if the folder we want to symlink already exists, the ln -s command will create a folder inside the existing folder
if [ -e "$source_dir" ]; then
echo "Moving existing $source_dir folder to $source_dir-old"
mv "$source_dir" "$source_dir-old"
if [ -e "$local_dir" ]; then
echo "Moving existing $local_dir folder to $local_dir-old"
mv "$local_dir" "$local_dir-old"
fi

echo "Symlink $source_dir to $target_dir..."
ln -s "$target_dir" "$source_dir"
echo "Symlink $local_dir to $cache_dir for $username..."
runuser -u "$username" -- ln -s "$cache_dir" "$local_dir"
}

echo "Change owner of $source_dir to $username..."
chown -R "$username:$username" "$source_dir"
install_edgedb() {
local username=$1

echo "Installing EdgeDB CLI..."
curl https://sh.edgedb.com --proto '=https' -sSf1 -o /tmp/edgedb-cli.sh
chmod +x /tmp/edgedb-cli.sh

# install edgedb for a specific user if possible
echo "Installing EdgeDB CLI for $username..."
if [ -z "$username" ]; then
/tmp/edgedb-cli.sh -y
else
runuser -u "$username" -- /tmp/edgedb-cli.sh -y
fi
}

export DEBIAN_FRONTEND=noninteractive

check_packages curl ca-certificates

create_cache_dir "/dc/edgedb-cli" "${USERNAME}"
create_symlink_dir "$_REMOTE_USER_HOME/.local/share/edgedb" "/dc/edgedb-cli" "${USERNAME}"
install_edgedb "${USERNAME}"

# Set Lifecycle scripts
if [ -f oncreate.sh ]; then
Expand Down
27 changes: 27 additions & 0 deletions test/edgedb-cli/_default.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

set -e

# This is the default test script that tests everything
# It is not run as a scenario, but is run by other test scripts.

# Optional: Import test library
source dev-container-features-test-lib

# check that the command is available
check "help" bash -c "edgedb --help | grep 'Usage'"

# check that `.config/gh` and `/dc/github-cli` exist under the user (should be node)
check "~/.local/share/edgedb exists" bash -c "ls -la ~/.local/share | grep 'edgedb'"
check "/dc/edgedb-cli exists" bash -c "ls -la /dc | grep 'edgedb-cli'"

# check that the folders are owned by the user
# https://askubuntu.com/a/175060
echo "Checking ownership of ~/.local/share/edgedb and /dc/edgedb-cli (ensure it is owned by $USER)"
ls -al ~/.local/share/

check "~/.local/share/edgedb owned by user" bash -c "test \"$(stat -c "%U" ~/.local/share/edgedb)\" = $USER"
check "/dc/edgedb-cli owned by user" bash -c "test \"$(stat -c "%U" /dc/edgedb-cli)\" = $USER"

# Report result
reportResults
9 changes: 8 additions & 1 deletion test/edgedb-cli/scenarios.json
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
{}
{
"with_node": {
"image": "mcr.microsoft.com/devcontainers/javascript-node:1-18",
"features": {
"edgedb-cli": {}
}
}
}
7 changes: 7 additions & 0 deletions test/edgedb-cli/with_node.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

set -e

# Run default test script (in same folder)
# See: https://github.com/devcontainers/features/blob/562305d37b97d47331d96306ffc2a0a3cce55e64/test/azure-cli/install_extensions_bookworm.sh
./_default.sh