Skip to content

Commit bf55a46

Browse files
authored
Merge pull request #72 from joshuanianji/gel-cli
Gel CLI
2 parents 5a02606 + 424403d commit bf55a46

File tree

11 files changed

+257
-9
lines changed

11 files changed

+257
-9
lines changed

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +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. |
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. |
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+
| [gel-cli](./src/gel-cli) | Gel CLI (previously EdgeDB) via the official installation script. Includes the VSCode extension as well as a couple mounts for data persistence. |

src/edgedb-cli/NOTES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## Deprecation Notes
2+
3+
Please use [joshuanianji/gel-cli](https://github.com/joshuanianji/devcontainer-features/tree/main/src/gel-cli) instead. See: [EdgeDB is now Gel and Postgres is the Future](https://www.geldata.com/blog/edgedb-is-now-gel-and-postgres-is-the-future)
4+
15
## Usage
26

37
**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:

src/edgedb-cli/devcontainer-feature.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "EdgeDB",
33
"id": "edgedb-cli",
44
"version": "1.0.2",
5+
"deprecated": true,
56
"documentationURL": "https://github.com/joshuanianji/devcontainer-features/tree/main/src/edgedb-cli",
67
"description": "EdgeDB CLI via the official installation script. Includes the VSCode extension and mounts the config and data folder.",
78
"options": {},

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/devcontainer-feature.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "Gel CLI",
3+
"id": "gel-cli",
4+
"version": "1.0.0",
5+
"documentationURL": "https://github.com/joshuanianji/devcontainer-features/tree/main/src/gel-cli",
6+
"description": "Gel CLI (previously EdgeDB) 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}-gel-cli",
18+
"target": "/dc/gel-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+
"gel-cli-setup": "/usr/local/share/gel-cli/scripts/oncreate.sh"
28+
}
29+
}

src/gel-cli/install.sh

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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+
# Looks like they kept the config directories the same (edgedb in the paths)
77+
78+
# cache data directory
79+
create_cache_dir "/dc/gel-cli/data" "${USERNAME}"
80+
create_symlink_dir "$_REMOTE_USER_HOME/.local/share/edgedb" "/dc/gel-cli/data" "${USERNAME}"
81+
82+
# cache config directory
83+
create_cache_dir "/dc/gel-cli/config" "${USERNAME}"
84+
create_symlink_dir "$_REMOTE_USER_HOME/.config/edgedb" "/dc/gel-cli/config" "${USERNAME}"
85+
86+
install_cli "${USERNAME}"
87+
88+
# Set Lifecycle scripts
89+
if [ -f oncreate.sh ]; then
90+
mkdir -p "${LIFECYCLE_SCRIPTS_DIR}"
91+
cp oncreate.sh "${LIFECYCLE_SCRIPTS_DIR}/oncreate.sh"
92+
fi
93+
94+
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/gel-cli
9+
fi

test/gel-cli/_default.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# This is the default test script that tests everything
6+
# It is not run as a scenario, but is run by other test scripts.
7+
8+
# Optional: Import test library
9+
source dev-container-features-test-lib
10+
11+
# check that the command is available
12+
check "help" bash -c "gel --help | grep 'Usage'"
13+
14+
gel info
15+
16+
# make sure gel directories match up with our expectations
17+
check "gel info data dir" bash -c "test \"$(gel info --get data-dir)\" = $HOME/.local/share/edgedb/data/"
18+
check "gel info config dir" bash -c "test \"$(gel info --get config-dir)\" = $HOME/.config/edgedb/"
19+
20+
# check that data directories exist
21+
check "~/.local/share/gel exists" bash -c "ls -la ~/.local/share | grep 'gel'"
22+
check "/dc/gel-cli/data exists" bash -c "ls -la /dc/gel-cli | grep 'data'"
23+
24+
# check that config directories exist
25+
check "~/.config/gel exists" bash -c "ls -la ~/.config | grep 'gel'"
26+
check "/dc/gel-cli exists" bash -c "ls -la /dc/gel-cli | grep 'config'"
27+
28+
# check that the folders are owned by the user
29+
# https://askubuntu.com/a/175060
30+
# $USER is empty when running as root, so we use $(whoami)
31+
echo "Checking ownership of data installation paths and mounts (ensure it is owned by $(whoami))"
32+
33+
check "~/.local/share/edgedb owned by user" bash -c "test \"$(stat -c "%U" ~/.local/share/edgedb)\" = $(whoami)"
34+
check "/dc/gel-cli/data owned by user" bash -c "test \"$(stat -c "%U" /dc/gel-cli/data)\" = $(whoami)"
35+
36+
check "~/.config/edgedb owned by user" bash -c "test \"$(stat -c "%U" ~/.config/edgedb)\" = $(whoami)"
37+
check "/dc/gel-cli/config owned by user" bash -c "test \"$(stat -c "%U" /dc/gel-cli/config)\" = $(whoami)"
38+
39+
# Report result
40+
reportResults

test/gel-cli/scenarios.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"with_node": {
3+
"image": "mcr.microsoft.com/devcontainers/javascript-node:1-18",
4+
"features": {
5+
"gel-cli": {}
6+
}
7+
}
8+
}

test/gel-cli/test.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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 feature with no options
11+
12+
./_default.sh

0 commit comments

Comments
 (0)