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
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ This repo contains my custom devcontainer features.

## Features

| Feature | Description |
| ------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------- |
| [github-cli-persistence](./src/github-cli-persistence) | Avoid extra logins from the Github CLI by preserving the `~/.config/gh` folder across container instances. |
| [terraform-cli-persistence](./src/terraform-cli-persistence) | Avoid extra logins from the Terraform CLI by preserving the `~/.terraform.d` folder across container instances. |
| [aws-cli-persistence](./src/aws-cli-persistence) | Avoid extra logins from the AWS CLI by preserving the `~/.aws` folder across container instances. |
| [gcloud-cli-persistence](./src/gcloud-cli-persistence) | Avoid extra logins from the Google Cloud CLI by preserving the `~/.config/gcloud` folder across container instances. |
| [lamdera](./src/lamdera) | Installs [Lamdera](https://dashboard.lamdera.app/), a type-safe full-stack web-app platform for Elm (v1.1.0 and later). |
| [mount-pnpm-store](./src/mount-pnpm-store) | Mounts the pnpm store to a volume to share between multiple devcontainers. |
| [edgedb-cli](./src/edgedb-cli) | EdgeDB CLI via the official installation script. Includes the VSCode extension and mounts ~/.local/share/edgedb for data persistence. |
| Feature | Description |
| ------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| [github-cli-persistence](./src/github-cli-persistence) | Avoid extra logins from the Github CLI by preserving the `~/.config/gh` folder across container instances. |
| [terraform-cli-persistence](./src/terraform-cli-persistence) | Avoid extra logins from the Terraform CLI by preserving the `~/.terraform.d` folder across container instances. |
| [aws-cli-persistence](./src/aws-cli-persistence) | Avoid extra logins from the AWS CLI by preserving the `~/.aws` folder across container instances. |
| [gcloud-cli-persistence](./src/gcloud-cli-persistence) | Avoid extra logins from the Google Cloud CLI by preserving the `~/.config/gcloud` folder across container instances. |
| [lamdera](./src/lamdera) | Installs [Lamdera](https://dashboard.lamdera.app/), a type-safe full-stack web-app platform for Elm (v1.1.0 and later). |
| [mount-pnpm-store](./src/mount-pnpm-store) | Mounts the pnpm store to a volume to share between multiple devcontainers. |
| [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. |
4 changes: 4 additions & 0 deletions src/edgedb-cli/NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Deprecation Notes

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)

## Usage

**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:
Expand Down
1 change: 1 addition & 0 deletions src/edgedb-cli/devcontainer-feature.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "EdgeDB",
"id": "edgedb-cli",
"version": "1.0.2",
"deprecated": true,
"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 the config and data folder.",
"options": {},
Expand Down
44 changes: 44 additions & 0 deletions src/gel-cli/NOTES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
## Usage

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

1. Use a docker-compose template with two services: one for the CLI and one for the Gel database instance.

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.

Once inside the devcontainer, you can run `gel instance link` to connect the CLI to the instance. Check the templates above for more details.

2. Connect to a cloud instance [with `gel cloud`](https://docs.edgedb.com/cloud/cli).

## Notes on Volume Mounts

This feature mounts the gel config and data folder for persistence. To do so, it makes some assumptions about `gel info`:

```bash
$ gel info

Gel uses the following local paths:
┌────────────┬────────────────────────────────────────┐
│ Cache │ /home/<user>/.cache/gel/ │
│ Config │ /home/<user>/.config/gel/ │
│ CLI Binary │ /home/<user>/.local/bin/gel │
│ Data │ /home/<user>/.local/share/gel/data/ │
│ Service │ /home/<user>/.config/systemd/gel/ │
└────────────┴────────────────────────────────────────┘
```

**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.

## OS and Architecture Support

Architectures: `amd` and `arm`

OS: `ubuntu`, `debian`

Shells: `bash`, `zsh`, `fish`

## Changelog

| Version | Notes |
| ------- | ------------------------------------- |
| 1.0.0 | Initial Version (migrate from EdgeDB) |
29 changes: 29 additions & 0 deletions src/gel-cli/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "Gel CLI",
"id": "gel-cli",
"version": "1.0.0",
"documentationURL": "https://github.com/joshuanianji/devcontainer-features/tree/main/src/gel-cli",
"description": "Gel CLI (previously EdgeDB) via the official installation script. Includes the VSCode extension and mounts the config and data folder.",
"options": {},
"customizations": {
"vscode": {
"extensions": [
"magicstack.edgedb"
]
}
},
"mounts": [
{
"source": "${devcontainerId}-gel-cli",
"target": "/dc/gel-cli",
"type": "volume"
}
],
"installsAfter": [
"ghcr.io/devcontainers/features/common-utils",
"ghcr.io/meaningful-ooo/devcontainer-features/fish"
],
"onCreateCommand": {
"gel-cli-setup": "/usr/local/share/gel-cli/scripts/oncreate.sh"
}
}
94 changes: 94 additions & 0 deletions src/gel-cli/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/bin/sh

USERNAME=${USERNAME:-${_REMOTE_USER}}

LIFECYCLE_SCRIPTS_DIR="/usr/local/share/gel-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..."
else
echo "Create cache directory $1..."
mkdir -p "$1"
fi

if [ -z "$2" ]; then
echo "No username provided. Skip chown..."
else
echo "Change owner of $1 to $2..."
chown -R "$2:$2" "$1"
fi
}

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

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 "$local_dir" ]; then
echo "Moving existing $local_dir folder to $local_dir-old"
mv "$local_dir" "$local_dir-old"
fi

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

install_cli() {
local username=$1

echo "Installing Gel CLI..."
curl https://www.geldata.com/sh --proto '=https' --tlsv1.2 -sSf -o /tmp/gel-cli.sh
chmod +x /tmp/gel-cli.sh

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

export DEBIAN_FRONTEND=noninteractive

check_packages curl ca-certificates

# Looks like they kept the config directories the same (edgedb in the paths)

# cache data directory
create_cache_dir "/dc/gel-cli/data" "${USERNAME}"
create_symlink_dir "$_REMOTE_USER_HOME/.local/share/edgedb" "/dc/gel-cli/data" "${USERNAME}"

# cache config directory
create_cache_dir "/dc/gel-cli/config" "${USERNAME}"
create_symlink_dir "$_REMOTE_USER_HOME/.config/edgedb" "/dc/gel-cli/config" "${USERNAME}"

install_cli "${USERNAME}"

# Set Lifecycle scripts
if [ -f oncreate.sh ]; then
mkdir -p "${LIFECYCLE_SCRIPTS_DIR}"
cp oncreate.sh "${LIFECYCLE_SCRIPTS_DIR}/oncreate.sh"
fi

echo "Done!"
9 changes: 9 additions & 0 deletions src/gel-cli/oncreate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

set -e

# if the user is not root, chown /dc/edgedb-cli to the user
if [ "$(id -u)" != "0" ]; then
echo "Running oncreate.sh for user $USER"
sudo chown -R "$USER:$USER" /dc/gel-cli
fi
40 changes: 40 additions & 0 deletions test/gel-cli/_default.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/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 "gel --help | grep 'Usage'"

gel info

# make sure gel directories match up with our expectations
check "gel info data dir" bash -c "test \"$(gel info --get data-dir)\" = $HOME/.local/share/edgedb/data/"
check "gel info config dir" bash -c "test \"$(gel info --get config-dir)\" = $HOME/.config/edgedb/"

# check that data directories exist
check "~/.local/share/gel exists" bash -c "ls -la ~/.local/share | grep 'gel'"
check "/dc/gel-cli/data exists" bash -c "ls -la /dc/gel-cli | grep 'data'"

# check that config directories exist
check "~/.config/gel exists" bash -c "ls -la ~/.config | grep 'gel'"
check "/dc/gel-cli exists" bash -c "ls -la /dc/gel-cli | grep 'config'"

# check that the folders are owned by the user
# https://askubuntu.com/a/175060
# $USER is empty when running as root, so we use $(whoami)
echo "Checking ownership of data installation paths and mounts (ensure it is owned by $(whoami))"

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

check "~/.config/edgedb owned by user" bash -c "test \"$(stat -c "%U" ~/.config/edgedb)\" = $(whoami)"
check "/dc/gel-cli/config owned by user" bash -c "test \"$(stat -c "%U" /dc/gel-cli/config)\" = $(whoami)"

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

set -e

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

# NOTE: this is an "auto-generated" test, which means it will be
# executed against an auto-generated devcontainer.json that
# includes the feature with no options

./_default.sh
7 changes: 7 additions & 0 deletions test/gel-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