Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] Edgedb CLI #49

Merged
merged 7 commits into from
Mar 6, 2024
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
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +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. |
| 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. |
13 changes: 13 additions & 0 deletions src/edgedb-cli/NOTES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## OS and Architecture Support

Architectures: `amd` and `arm`

OS: `ubuntu`, `debian`

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

## Changelog

| Version | Notes |
| ------- | --------------- |
| 1.0.0 | Initial Version |
29 changes: 29 additions & 0 deletions src/edgedb-cli/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "EdgeDB",
"id": "edgedb-cli",
"version": "1.0.0",
"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": {},
"customizations": {
"vscode": {
"extensions": [
"magicstack.edgedb"
]
}
},
"mounts": [
{
"source": "${devcontainerId}-edgedb-cli",
"target": "/dc/edgedb-cli",
"type": "volume"
}
],
"installsAfter": [
"ghcr.io/devcontainers/features/common-utils",
"ghcr.io/meaningful-ooo/devcontainer-features/fish"
],
"onCreateCommand": {
"edgedb-cli-setup": "/usr/local/share/edgedb-cli/scripts/oncreate.sh"
}
}
63 changes: 63 additions & 0 deletions src/edgedb-cli/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/sh

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

LIFECYCLE_SCRIPTS_DIR="/usr/local/share/edgedb-cli/scripts"

set -e

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() {
# ln -s target_dir source_dir
local source_dir=$1
local target_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

# 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"
fi

echo "Symlink $source_dir to $target_dir..."
ln -s "$target_dir" "$source_dir"

echo "Change owner of $source_dir to $username..."
chown -R "$username:$username" "$source_dir"
}

export DEBIAN_FRONTEND=noninteractive

create_cache_dir "/dc/edgedb-cli" "${USERNAME}"
create_symlink_dir "$_REMOTE_USER_HOME/.local/share/edgedb" "/dc/edgedb-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/edgedb-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/edgedb-cli
fi
1 change: 1 addition & 0 deletions test/edgedb-cli/scenarios.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
26 changes: 26 additions & 0 deletions test/edgedb-cli/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/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 'gcloud-cli-persistence' Feature with no options.
#
# https://github.com/devcontainers/cli/blob/main/docs/features/test.md
#
# From my tests, this means the `gcloud` CLI will not be installed:
# Thus, here, I only check basic directory existence

# check that `~/.config/gcloud` and `/dc/gcloud-cli` exist`
check "config" bash -c "ls -la ~/.local/share/ | grep 'edgedb'"
check "dc" bash -c "ls -la /dc | grep 'edgedb-cli'"

# check that `~/.config/gcloud` is a symlink
# https://unix.stackexchange.com/a/96910
check "~/.local/share/edgedb is a symlink" bash -c "test -L ~/.local/share/edgedb && test -d ~/.local/share/edgedb"

# Report result
reportResults