Skip to content

Commit 52e036a

Browse files
authored
Merge pull request #49 from joshuanianji/edgedb-cli
[feature] Edgedb CLI
2 parents 19ff49e + dd151d9 commit 52e036a

File tree

7 files changed

+150
-8
lines changed

7 files changed

+150
-8
lines changed

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ This repo contains my custom devcontainer features.
66

77
## Features
88

9-
| Feature | Description |
10-
| ------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------- |
11-
| [github-cli-persistence](./src/github-cli-persistence) | Avoid extra logins from the Github CLI by preserving the `~/.config/gh` folder across container instances. |
12-
| [terraform-cli-persistence](./src/terraform-cli-persistence) | Avoid extra logins from the Terraform CLI by preserving the `~/.terraform.d` folder across container instances. |
13-
| [aws-cli-persistence](./src/aws-cli-persistence) | Avoid extra logins from the AWS CLI by preserving the `~/.aws` folder across container instances. |
14-
| [gcloud-cli-persistence](./src/gcloud-cli-persistence) | Avoid extra logins from the Google Cloud CLI by preserving the `~/.config/gcloud` folder across container instances. |
15-
| [lamdera](./src/lamdera) | Installs [Lamdera](https://dashboard.lamdera.app/), a type-safe full-stack web-app platform for Elm (v1.1.0 and later). |
16-
| [mount-pnpm-store](./src/mount-pnpm-store) | Mounts the pnpm store to a volume to share between multiple devcontainers. |
9+
| Feature | Description |
10+
| ------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------- |
11+
| [github-cli-persistence](./src/github-cli-persistence) | Avoid extra logins from the Github CLI by preserving the `~/.config/gh` folder across container instances. |
12+
| [terraform-cli-persistence](./src/terraform-cli-persistence) | Avoid extra logins from the Terraform CLI by preserving the `~/.terraform.d` folder across container instances. |
13+
| [aws-cli-persistence](./src/aws-cli-persistence) | Avoid extra logins from the AWS CLI by preserving the `~/.aws` folder across container instances. |
14+
| [gcloud-cli-persistence](./src/gcloud-cli-persistence) | Avoid extra logins from the Google Cloud CLI by preserving the `~/.config/gcloud` folder across container instances. |
15+
| [lamdera](./src/lamdera) | Installs [Lamdera](https://dashboard.lamdera.app/), a type-safe full-stack web-app platform for Elm (v1.1.0 and later). |
16+
| [mount-pnpm-store](./src/mount-pnpm-store) | Mounts the pnpm store to a volume to share between multiple devcontainers. |
17+
| [edgedb-cli](./src/edgedb-cli) | EdgeDB CLI via the official installation script. Includes the VSCode extension and mounts ~/.local/share/edgedb for data persistence. |

src/edgedb-cli/NOTES.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## OS and Architecture Support
2+
3+
Architectures: `amd` and `arm`
4+
5+
OS: `ubuntu`, `debian`
6+
7+
Shells: `bash`, `zsh`, `fish`
8+
9+
## Changelog
10+
11+
| Version | Notes |
12+
| ------- | --------------- |
13+
| 1.0.0 | Initial Version |
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "EdgeDB",
3+
"id": "edgedb-cli",
4+
"version": "1.0.0",
5+
"documentationURL": "https://github.com/joshuanianji/devcontainer-features/tree/main/src/edgedb-cli",
6+
"description": "EdgeDB CLI via the official installation script. Includes the VSCode extension and mounts ~/.local/share/edgedb for data persistence.",
7+
"options": {},
8+
"customizations": {
9+
"vscode": {
10+
"extensions": [
11+
"magicstack.edgedb"
12+
]
13+
}
14+
},
15+
"mounts": [
16+
{
17+
"source": "${devcontainerId}-edgedb-cli",
18+
"target": "/dc/edgedb-cli",
19+
"type": "volume"
20+
}
21+
],
22+
"installsAfter": [
23+
"ghcr.io/devcontainers/features/common-utils",
24+
"ghcr.io/meaningful-ooo/devcontainer-features/fish"
25+
],
26+
"onCreateCommand": {
27+
"edgedb-cli-setup": "/usr/local/share/edgedb-cli/scripts/oncreate.sh"
28+
}
29+
}

src/edgedb-cli/install.sh

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/bin/sh
2+
3+
USERNAME=${USERNAME:-${_REMOTE_USER}}
4+
5+
LIFECYCLE_SCRIPTS_DIR="/usr/local/share/edgedb-cli/scripts"
6+
7+
set -e
8+
9+
create_cache_dir() {
10+
if [ -d "$1" ]; then
11+
echo "Cache directory $1 already exists. Skip creation..."
12+
else
13+
echo "Create cache directory $1..."
14+
mkdir -p "$1"
15+
fi
16+
17+
if [ -z "$2" ]; then
18+
echo "No username provided. Skip chown..."
19+
else
20+
echo "Change owner of $1 to $2..."
21+
chown -R "$2:$2" "$1"
22+
fi
23+
}
24+
25+
create_symlink_dir() {
26+
# ln -s target_dir source_dir
27+
local source_dir=$1
28+
local target_dir=$2
29+
local username=$3
30+
31+
if [ -d "$source_dir" ]; then
32+
echo "Symlink $source_dir to $target_dir..."
33+
ln -s "$source_dir" "$target_dir"
34+
else
35+
echo "Creating source dir $source_dir..."
36+
mkdir -p "$source_dir"
37+
fi
38+
39+
# if the folder we want to symlink already exists, the ln -s command will create a folder inside the existing folder
40+
if [ -e "$source_dir" ]; then
41+
echo "Moving existing $source_dir folder to $source_dir-old"
42+
mv "$source_dir" "$source_dir-old"
43+
fi
44+
45+
echo "Symlink $source_dir to $target_dir..."
46+
ln -s "$target_dir" "$source_dir"
47+
48+
echo "Change owner of $source_dir to $username..."
49+
chown -R "$username:$username" "$source_dir"
50+
}
51+
52+
export DEBIAN_FRONTEND=noninteractive
53+
54+
create_cache_dir "/dc/edgedb-cli" "${USERNAME}"
55+
create_symlink_dir "$_REMOTE_USER_HOME/.local/share/edgedb" "/dc/edgedb-cli" "${USERNAME}"
56+
57+
# Set Lifecycle scripts
58+
if [ -f oncreate.sh ]; then
59+
mkdir -p "${LIFECYCLE_SCRIPTS_DIR}"
60+
cp oncreate.sh "${LIFECYCLE_SCRIPTS_DIR}/oncreate.sh"
61+
fi
62+
63+
echo "Done!"

src/edgedb-cli/oncreate.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
# if the user is not root, chown /dc/edgedb-cli to the user
6+
if [ "$(id -u)" != "0" ]; then
7+
echo "Running oncreate.sh for user $USER"
8+
sudo chown -R "$USER:$USER" /dc/edgedb-cli
9+
fi

test/edgedb-cli/scenarios.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

test/edgedb-cli/test.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Optional: Import test library
6+
source dev-container-features-test-lib
7+
8+
# NOTE: this is an "auto-generated" test, which means it will be
9+
# executed against an auto-generated devcontainer.json that
10+
# includes the 'gcloud-cli-persistence' Feature with no options.
11+
#
12+
# https://github.com/devcontainers/cli/blob/main/docs/features/test.md
13+
#
14+
# From my tests, this means the `gcloud` CLI will not be installed:
15+
# Thus, here, I only check basic directory existence
16+
17+
# check that `~/.config/gcloud` and `/dc/gcloud-cli` exist`
18+
check "config" bash -c "ls -la ~/.local/share/ | grep 'edgedb'"
19+
check "dc" bash -c "ls -la /dc | grep 'edgedb-cli'"
20+
21+
# check that `~/.config/gcloud` is a symlink
22+
# https://unix.stackexchange.com/a/96910
23+
check "~/.local/share/edgedb is a symlink" bash -c "test -L ~/.local/share/edgedb && test -d ~/.local/share/edgedb"
24+
25+
# Report result
26+
reportResults

0 commit comments

Comments
 (0)