Skip to content

Commit 8d45f5c

Browse files
committed
init gel-cli
1 parent 5a02606 commit 8d45f5c

File tree

5 files changed

+250
-0
lines changed

5 files changed

+250
-0
lines changed

src/gel-cli/NOTES.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
## Usage
2+
3+
**The Gel database instance should not be in the same container as the CLI.** My experience doing so makes the `gel ui` command start failing once you restart the container. I recommend the following options:
4+
5+
1. Use a docker-compose template with two services: one for the CLI and one for the Gel database instance.
6+
7+
You can either use the [javascript-node-edgedb](https://github.com/joshuanianji/devcontainer-templates/blob/main/src/javascript-node-edgedb) or the [rust-edgedb](https://github.com/joshuanianji/devcontainer-templates/blob/main/src/rust-edgedb) templates, or use them as references to make your own.
8+
9+
Once inside the devcontainer, you can run `gel instance link` to connect the CLI to the instance. Check the templates above for more details.
10+
11+
2. Connect to a cloud instance [with `gel cloud`](https://docs.edgedb.com/cloud/cli).
12+
13+
## Notes on Volume Mounts
14+
15+
This feature mounts the gel config and data folder for persistence. To do so, it makes some assumptions about `gel info`:
16+
17+
```bash
18+
$ gel info
19+
20+
Gel uses the following local paths:
21+
┌────────────┬────────────────────────────────────────┐
22+
│ Cache │ /home/<user>/.cache/gel/ │
23+
│ Config │ /home/<user>/.config/gel/ │
24+
│ CLI Binary │ /home/<user>/.local/bin/gel │
25+
│ Data │ /home/<user>/.local/share/gel/data/ │
26+
│ Service │ /home/<user>/.config/systemd/gel/ │
27+
└────────────┴────────────────────────────────────────┘
28+
```
29+
30+
**These paths may change based on the OS!** This feature is tested on Ubuntu and Debian and the paths match up, but may not work for others.
31+
32+
## OS and Architecture Support
33+
34+
Architectures: `amd` and `arm`
35+
36+
OS: `ubuntu`, `debian`
37+
38+
Shells: `bash`, `zsh`, `fish`
39+
40+
## Changelog
41+
42+
| Version | Notes |
43+
| ------- | ------------------------------------- |
44+
| 1.0.0 | Initial Version (migrate from EdgeDB) |

src/gel-cli/README.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
2+
# EdgeDB (edgedb-cli)
3+
4+
EdgeDB CLI via the official installation script. Includes the VSCode extension and mounts the config and data folder.
5+
6+
## Example Usage
7+
8+
```json
9+
"features": {
10+
"ghcr.io/joshuanianji/devcontainer-features/edgedb-cli:1": {}
11+
}
12+
```
13+
14+
## Options
15+
16+
| Options Id | Description | Type | Default Value |
17+
|-----|-----|-----|-----|
18+
19+
20+
## Customizations
21+
22+
### VS Code Extensions
23+
24+
- `magicstack.edgedb`
25+
26+
## Usage
27+
28+
**The EdgeDB instance should not be in the same container as the CLI.** My experience doing so makes the `edgedb ui` command start failing once you restart the container. I recommend the following options:
29+
30+
1. Use a docker-compose template with two services: one for the CLI and one for the EdgeDB instance.
31+
32+
You can either use the [javascript-node-edgedb](https://github.com/joshuanianji/devcontainer-templates/blob/main/src/javascript-node-edgedb) or the [rust-edgedb](https://github.com/joshuanianji/devcontainer-templates/blob/main/src/rust-edgedb) templates, or use them as references to make your own.
33+
34+
Once inside the devcontainer, you can run `edgedb instance link` to connect the CLI to the instance. Check the templates above for more details.
35+
36+
2. Connect to a cloud instance [with `edgedb cloud`](https://docs.edgedb.com/cloud/cli).
37+
38+
## Notes on Volume Mounts
39+
40+
This feature mounts the edgedb config and data folder for persistence. To do so, it makes some assumptions about `edgedb info`:
41+
42+
```bash
43+
$ edgedb info
44+
45+
EdgeDB uses the following local paths:
46+
┌────────────┬────────────────────────────────────────┐
47+
│ Cache │ /home/<user>/.cache/edgedb/ │
48+
│ Config │ /home/<user>/.config/edgedb/ │
49+
│ CLI Binary │ /home/<user>/.local/bin/edgedb │
50+
│ Data │ /home/<user>/.local/share/edgedb/data/ │
51+
│ Service │ /home/<user>/.config/systemd/user/ │
52+
└────────────┴────────────────────────────────────────┘
53+
```
54+
55+
**These paths may change based on the OS!** This feature is tested on Ubuntu and Debian and the paths match up, but may not work for others.
56+
57+
## OS and Architecture Support
58+
59+
Architectures: `amd` and `arm`
60+
61+
OS: `ubuntu`, `debian`
62+
63+
Shells: `bash`, `zsh`, `fish`
64+
65+
## Changelog
66+
67+
| Version | Notes |
68+
| ------- | -------------------------- |
69+
| 1.0.2 | Cache edgedb config folder |
70+
| 1.0.1 | Fix for non-root users |
71+
| 1.0.0 | Initial Version |
72+
73+
74+
---
75+
76+
_Note: This file was auto-generated from the [devcontainer-feature.json](https://github.com/joshuanianji/devcontainer-features/blob/main/src/edgedb-cli/devcontainer-feature.json). Add additional notes to a `NOTES.md`._
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.2",
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 the config and data folder.",
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/gel-cli/install.sh

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/bin/sh
2+
3+
USERNAME=${USERNAME:-${_REMOTE_USER}}
4+
5+
LIFECYCLE_SCRIPTS_DIR="/usr/local/share/gel-cli/scripts"
6+
7+
set -e
8+
9+
# Checks if packages are installed and installs them if not
10+
check_packages() {
11+
if ! dpkg -s "$@" >/dev/null 2>&1; then
12+
if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then
13+
echo "Running apt-get update..."
14+
apt-get update -y
15+
fi
16+
apt-get -y install --no-install-recommends "$@"
17+
fi
18+
}
19+
20+
create_cache_dir() {
21+
if [ -d "$1" ]; then
22+
echo "Cache directory $1 already exists. Skip creation..."
23+
else
24+
echo "Create cache directory $1..."
25+
mkdir -p "$1"
26+
fi
27+
28+
if [ -z "$2" ]; then
29+
echo "No username provided. Skip chown..."
30+
else
31+
echo "Change owner of $1 to $2..."
32+
chown -R "$2:$2" "$1"
33+
fi
34+
}
35+
36+
create_symlink_dir() {
37+
# local dir is the folder gel will use
38+
# cache_dir is the /dc/gel-cli folder
39+
local local_dir=$1
40+
local cache_dir=$2
41+
local username=$3
42+
43+
runuser -u "$username" -- mkdir -p "$(dirname "$local_dir")"
44+
runuser -u "$username" -- mkdir -p "$cache_dir"
45+
46+
# if the folder we want to symlink already exists, the ln -s command will create a folder inside the existing folder
47+
if [ -e "$local_dir" ]; then
48+
echo "Moving existing $local_dir folder to $local_dir-old"
49+
mv "$local_dir" "$local_dir-old"
50+
fi
51+
52+
echo "Symlink $local_dir to $cache_dir for $username..."
53+
runuser -u "$username" -- ln -s "$cache_dir" "$local_dir"
54+
}
55+
56+
install_cli() {
57+
local username=$1
58+
59+
echo "Installing Gel CLI..."
60+
curl https://www.geldata.com/sh --proto '=https' --tlsv1.2 -sSf -o /tmp/gel-cli.sh
61+
chmod +x /tmp/gel-cli.sh
62+
63+
# install gel for a specific user if possible
64+
echo "Installing Gel CLI for $username..."
65+
if [ -z "$username" ]; then
66+
/tmp/gel-cli.sh -y
67+
else
68+
runuser -u "$username" -- /tmp/gel-cli.sh -y
69+
fi
70+
}
71+
72+
export DEBIAN_FRONTEND=noninteractive
73+
74+
check_packages curl ca-certificates
75+
76+
# cache data directory
77+
create_cache_dir "/dc/gel-cli/data" "${USERNAME}"
78+
create_symlink_dir "$_REMOTE_USER_HOME/.local/share/gel" "/dc/gel-cli/data" "${USERNAME}"
79+
80+
# cache config directory
81+
create_cache_dir "/dc/gel-cli/config" "${USERNAME}"
82+
create_symlink_dir "$_REMOTE_USER_HOME/.config/gel" "/dc/gel-cli/config" "${USERNAME}"
83+
84+
install_cli "${USERNAME}"
85+
86+
# Set Lifecycle scripts
87+
if [ -f oncreate.sh ]; then
88+
mkdir -p "${LIFECYCLE_SCRIPTS_DIR}"
89+
cp oncreate.sh "${LIFECYCLE_SCRIPTS_DIR}/oncreate.sh"
90+
fi
91+
92+
echo "Done!"

src/gel-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

0 commit comments

Comments
 (0)