From 98083f3a4b94f6c93fa9c30922b353ce7718b0c9 Mon Sep 17 00:00:00 2001 From: Joshua Ji Date: Wed, 6 Mar 2024 01:28:06 +0000 Subject: [PATCH 1/6] add edgedb --- src/edgedb-cli/NOTES.md | 13 +++++ src/edgedb-cli/devcontainer-feature.json | 27 ++++++++++ src/edgedb-cli/install.sh | 63 ++++++++++++++++++++++++ src/edgedb-cli/oncreate.sh | 5 ++ test/edgedb-cli/scenarios.json | 0 test/edgedb-cli/test.sh | 26 ++++++++++ 6 files changed, 134 insertions(+) create mode 100644 src/edgedb-cli/NOTES.md create mode 100644 src/edgedb-cli/devcontainer-feature.json create mode 100644 src/edgedb-cli/install.sh create mode 100644 src/edgedb-cli/oncreate.sh create mode 100644 test/edgedb-cli/scenarios.json create mode 100644 test/edgedb-cli/test.sh diff --git a/src/edgedb-cli/NOTES.md b/src/edgedb-cli/NOTES.md new file mode 100644 index 0000000..a746cd3 --- /dev/null +++ b/src/edgedb-cli/NOTES.md @@ -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 | diff --git a/src/edgedb-cli/devcontainer-feature.json b/src/edgedb-cli/devcontainer-feature.json new file mode 100644 index 0000000..541a99b --- /dev/null +++ b/src/edgedb-cli/devcontainer-feature.json @@ -0,0 +1,27 @@ +{ + "name": "EdgeDB", + "id": "edgedb-cli", + "version": "1.0.0", + "documentationURL": "https://github.com/joshuanianji/devcontainer-features/tree/main/src/edgedb-cli", + "description": "Installs the EdgeDB CLI via the official installation script as well as the VSCode extension. ", + "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": "/usr/local/share/edgedb-cli/oncreate.sh" +} \ No newline at end of file diff --git a/src/edgedb-cli/install.sh b/src/edgedb-cli/install.sh new file mode 100644 index 0000000..0e0217d --- /dev/null +++ b/src/edgedb-cli/install.sh @@ -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!" diff --git a/src/edgedb-cli/oncreate.sh b/src/edgedb-cli/oncreate.sh new file mode 100644 index 0000000..549c407 --- /dev/null +++ b/src/edgedb-cli/oncreate.sh @@ -0,0 +1,5 @@ +# if the user is not root, chown /dc/aws-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 diff --git a/test/edgedb-cli/scenarios.json b/test/edgedb-cli/scenarios.json new file mode 100644 index 0000000..e69de29 diff --git a/test/edgedb-cli/test.sh b/test/edgedb-cli/test.sh new file mode 100644 index 0000000..531fd97 --- /dev/null +++ b/test/edgedb-cli/test.sh @@ -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 From 6d7d9b20dd306a0b62264d40f2284e6232e7eb79 Mon Sep 17 00:00:00 2001 From: Joshua Ji Date: Wed, 6 Mar 2024 01:32:22 +0000 Subject: [PATCH 2/6] add scenarios.json --- test/edgedb-cli/scenarios.json | 1 + 1 file changed, 1 insertion(+) diff --git a/test/edgedb-cli/scenarios.json b/test/edgedb-cli/scenarios.json index e69de29..9e26dfe 100644 --- a/test/edgedb-cli/scenarios.json +++ b/test/edgedb-cli/scenarios.json @@ -0,0 +1 @@ +{} \ No newline at end of file From 9a628d234c59aee27c2b0ca34a4a014a701d0cda Mon Sep 17 00:00:00 2001 From: Joshua Ji Date: Wed, 6 Mar 2024 01:34:16 +0000 Subject: [PATCH 3/6] fix onCreateCommand thing --- src/edgedb-cli/devcontainer-feature.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/edgedb-cli/devcontainer-feature.json b/src/edgedb-cli/devcontainer-feature.json index 541a99b..8e79437 100644 --- a/src/edgedb-cli/devcontainer-feature.json +++ b/src/edgedb-cli/devcontainer-feature.json @@ -23,5 +23,5 @@ "ghcr.io/devcontainers/features/common-utils", "ghcr.io/meaningful-ooo/devcontainer-features/fish" ], - "onCreateCommand": "/usr/local/share/edgedb-cli/oncreate.sh" + "onCreateCommand": "/usr/local/share/edgedb-cli/scripts/oncreate.sh" } \ No newline at end of file From 2a7783906e93bdffafb62f727ce24d92c45c435f Mon Sep 17 00:00:00 2001 From: Joshua Ji Date: Wed, 6 Mar 2024 02:51:27 +0000 Subject: [PATCH 4/6] update onCreate script --- src/edgedb-cli/oncreate.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/edgedb-cli/oncreate.sh b/src/edgedb-cli/oncreate.sh index 549c407..701795a 100644 --- a/src/edgedb-cli/oncreate.sh +++ b/src/edgedb-cli/oncreate.sh @@ -1,4 +1,8 @@ -# if the user is not root, chown /dc/aws-cli to the user +#!/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 From f3430ddab72c0c97acbe7fdfbe2b1661e2c018c6 Mon Sep 17 00:00:00 2001 From: Joshua Ji Date: Wed, 6 Mar 2024 02:51:35 +0000 Subject: [PATCH 5/6] update onCreateCommand --- src/edgedb-cli/devcontainer-feature.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/edgedb-cli/devcontainer-feature.json b/src/edgedb-cli/devcontainer-feature.json index 8e79437..4a66273 100644 --- a/src/edgedb-cli/devcontainer-feature.json +++ b/src/edgedb-cli/devcontainer-feature.json @@ -23,5 +23,7 @@ "ghcr.io/devcontainers/features/common-utils", "ghcr.io/meaningful-ooo/devcontainer-features/fish" ], - "onCreateCommand": "/usr/local/share/edgedb-cli/scripts/oncreate.sh" + "onCreateCommand": { + "edgedb-cli-setup": "/usr/local/share/edgedb-cli/scripts/oncreate.sh" + } } \ No newline at end of file From 77ee81062a30f8a2807efe872e97b1d8eb1c255a Mon Sep 17 00:00:00 2001 From: Joshua Ji Date: Wed, 6 Mar 2024 02:54:18 +0000 Subject: [PATCH 6/6] update description --- README.md | 17 +++++++++-------- src/edgedb-cli/devcontainer-feature.json | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 514b787..b256f59 100644 --- a/README.md +++ b/README.md @@ -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. | diff --git a/src/edgedb-cli/devcontainer-feature.json b/src/edgedb-cli/devcontainer-feature.json index 4a66273..2d0b052 100644 --- a/src/edgedb-cli/devcontainer-feature.json +++ b/src/edgedb-cli/devcontainer-feature.json @@ -3,7 +3,7 @@ "id": "edgedb-cli", "version": "1.0.0", "documentationURL": "https://github.com/joshuanianji/devcontainer-features/tree/main/src/edgedb-cli", - "description": "Installs the EdgeDB CLI via the official installation script as well as the VSCode extension. ", + "description": "EdgeDB CLI via the official installation script. Includes the VSCode extension and mounts ~/.local/share/edgedb for data persistence.", "options": {}, "customizations": { "vscode": {