diff --git a/.devcontainer.json b/.devcontainer.json index 8c6a80f..34596f9 100644 --- a/.devcontainer.json +++ b/.devcontainer.json @@ -14,12 +14,12 @@ ] }, "extensions": [ - "mads-hartmann.bash-ide-vscode", - "yzhang.markdown-all-in-one", - "github.vscode-github-actions", - "GitHub.copilot", - "foxundermoon.shell-format" - ] + "mads-hartmann.bash-ide-vscode", + "yzhang.markdown-all-in-one", + "github.vscode-github-actions", + "GitHub.copilot", + "foxundermoon.shell-format" + ] } }, "features": { @@ -27,6 +27,5 @@ "ghcr.io/devcontainers/features/github-cli:1": {}, "ghcr.io/joshuanianji/devcontainer-features/github-cli-persistence:0": {} }, - "remoteUser": "node", "updateContentCommand": "npm install -g @devcontainers/cli" } \ No newline at end of file diff --git a/README.md b/README.md index 2f83c78..b7eab28 100644 --- a/README.md +++ b/README.md @@ -12,4 +12,4 @@ This repo contains my custom devcontainer features. | [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. | | [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. | +| [mount-pnpm-store](./src/mount-pnpm-store) | Mounts the pnpm store to a volume to share between multiple devcontainers. | diff --git a/src/aws-cli-persistence/NOTES.md b/src/aws-cli-persistence/NOTES.md index 1d06834..824aa21 100644 --- a/src/aws-cli-persistence/NOTES.md +++ b/src/aws-cli-persistence/NOTES.md @@ -1,8 +1,15 @@ +## OS and Architecture Support + +Architectures: `amd` and `arm`. +OS: `ubuntu`, `debian` +Shells: `bash`, `zsh`, `fish` + ## Changelog -| Version | Notes | -| ------- | --------------- | -| 0.0.0 | Initial Version | +| Version | Notes | +| ------- | ---------------------- | +| 1.0.0 | Support zsh + refactor | +| 0.0.0 | Initial Version | ## References diff --git a/src/aws-cli-persistence/devcontainer-feature.json b/src/aws-cli-persistence/devcontainer-feature.json index 0543436..db919d8 100644 --- a/src/aws-cli-persistence/devcontainer-feature.json +++ b/src/aws-cli-persistence/devcontainer-feature.json @@ -1,7 +1,7 @@ { "name": "AWS CLI Persistence", "id": "aws-cli-persistence", - "version": "0.0.0", + "version": "1.0.0", "documentationURL": "https://github.com/joshuanianji/devcontainer-features/tree/main/src/aws-cli-persistence", "description": "Avoid extra logins from the AWS CLI by preserving the `~/.aws` folder across container instances.", "options": {}, @@ -13,6 +13,8 @@ } ], "installsAfter": [ - "ghcr.io/devcontainers/features/aws-cli" - ] + "ghcr.io/devcontainers/features/aws-cli", + "ghcr.io/meaningful-ooo/devcontainer-features/fish" + ], + "postCreateCommand": "/usr/local/share/aws-cli-persistence-post-create.sh" } \ No newline at end of file diff --git a/src/aws-cli-persistence/install.sh b/src/aws-cli-persistence/install.sh index 92bf3c4..bf51027 100644 --- a/src/aws-cli-persistence/install.sh +++ b/src/aws-cli-persistence/install.sh @@ -1,14 +1,16 @@ #!/bin/sh set -e -echo "Activating feature 'aws-cli-persistence'" +FEATURE_ID="aws-cli-persistence" + +echo "Activating feature '$FEATURE_ID'" echo "User: ${_REMOTE_USER} User home: ${_REMOTE_USER_HOME}" -if [ -z "$_REMOTE_USER" ] || [ -z "$_REMOTE_USER_HOME" ]; then - echo "***********************************************************************************" - echo "*** Require _REMOTE_USER and _REMOTE_USER_HOME to be set (by dev container CLI) ***" - echo "***********************************************************************************" - exit 1 +if [ -z "$_REMOTE_USER" ] || [ -z "$_REMOTE_USER_HOME" ]; then + echo "***********************************************************************************" + echo "*** Require _REMOTE_USER and _REMOTE_USER_HOME to be set (by dev container CLI) ***" + echo "***********************************************************************************" + exit 1 fi # make /dc/aws-cli folder if doesn't exist @@ -16,16 +18,30 @@ mkdir -p "/dc/aws-cli" # as to why we move around the folder, check `github-cli-persistence/install.sh` if [ -e "$_REMOTE_USER_HOME/.aws" ]; then - echo "Moving existing .aws folder to .aws-old" - mv "$_REMOTE_USER_HOME/.aws" "$_REMOTE_USER_HOME/.aws-old" + echo "Moving existing .aws folder to .aws-old" + mv "$_REMOTE_USER_HOME/.aws" "$_REMOTE_USER_HOME/.aws-old" fi ln -s /dc/aws-cli "$_REMOTE_USER_HOME/.aws" # chown .aws folder chown -R "${_REMOTE_USER}:${_REMOTE_USER}" "$_REMOTE_USER_HOME/.aws" -# chown mount (only attached on startup) -cat << EOF >> "$_REMOTE_USER_HOME/.bashrc" -sudo chown -R "${_REMOTE_USER}:${_REMOTE_USER}" /dc/aws-cli +# --- Generate a '$FEATURE_ID-post-create.sh' script to be executed by the 'postCreateCommand' lifecycle hook +# Looks like this is the best way to run a script in lifecycle hooks +# Source: https://github.com/devcontainers/features/blob/562305d37b97d47331d96306ffc2a0a3cce55e64/src/git-lfs/install.sh#L190C1-L190C109 +POST_CREATE_SCRIPT_PATH="/usr/local/share/$FEATURE_ID-post-create.sh" + +tee "$POST_CREATE_SCRIPT_PATH" >/dev/null \ + <<'EOF' +#!/bin/sh + +set -e + +# if the user is not root, chown /dc/aws-cli to the user +if [ "$(id -u)" != "0" ]; then + echo "Running post-start.sh for user $USER" + sudo chown -R "$USER:$USER" /dc/aws-cli +fi EOF -chown -R $_REMOTE_USER $_REMOTE_USER_HOME/.bashrc + +chmod 755 "$POST_CREATE_SCRIPT_PATH" diff --git a/src/gcloud-cli-persistence/NOTES.md b/src/gcloud-cli-persistence/NOTES.md index 045b599..b50ac02 100644 --- a/src/gcloud-cli-persistence/NOTES.md +++ b/src/gcloud-cli-persistence/NOTES.md @@ -2,9 +2,11 @@ Architectures: `amd` and `arm`. OS: `ubuntu`, `debian` +Shells: `bash`, `zsh`, `fish` ## Changelog -| Version | Notes | -| ------- | --------------- | -| 0.0.0 | Initial Version | +| Version | Notes | +| ------- | ---------------------- | +| 1.0.0 | Support zsh + refactor | +| 0.0.0 | Initial Version | diff --git a/src/gcloud-cli-persistence/devcontainer-feature.json b/src/gcloud-cli-persistence/devcontainer-feature.json index 098ffee..bbfb892 100644 --- a/src/gcloud-cli-persistence/devcontainer-feature.json +++ b/src/gcloud-cli-persistence/devcontainer-feature.json @@ -1,7 +1,7 @@ { "name": "Google Cloud CLI Persistence", "id": "gcloud-cli-persistence", - "version": "0.0.0", + "version": "1.0.0", "documentationURL": "https://github.com/joshuanianji/devcontainer-features/tree/main/src/gcloud-cli-persistence", "description": "Avoid extra logins from the Google Cloud CLI by preserving the `~/.config/gcloud` folder across container instances.", "options": {}, @@ -13,6 +13,8 @@ } ], "installsAfter": [ - "ghcr.io/dhoeric/features/google-cloud-cli" - ] + "ghcr.io/dhoeric/features/google-cloud-cli", + "ghcr.io/meaningful-ooo/devcontainer-features/fish" + ], + "postCreateCommand": "/usr/local/share/gcloud-cli-persistence-post-create.sh" } \ No newline at end of file diff --git a/src/gcloud-cli-persistence/install.sh b/src/gcloud-cli-persistence/install.sh index adbf2f8..16cb04f 100644 --- a/src/gcloud-cli-persistence/install.sh +++ b/src/gcloud-cli-persistence/install.sh @@ -1,7 +1,9 @@ #!/bin/sh set -e -echo "Activating feature 'gcloud-cli-persistence'" +FEATURE_ID="gcloud-cli-persistence" + +echo "Activating feature '$FEATURE_ID'" echo "User: ${_REMOTE_USER} User home: ${_REMOTE_USER_HOME}" if [ -z "$_REMOTE_USER" ] || [ -z "$_REMOTE_USER_HOME" ]; then @@ -28,8 +30,22 @@ ln -s /dc/gcloud-cli "$_REMOTE_USER_HOME/.config/gcloud" # a `~/.config/vscode-dev-containers` folder later on chown -R "${_REMOTE_USER}:${_REMOTE_USER}" "$_REMOTE_USER_HOME/.config" -# chown mount (only attached on startup) -cat <>"$_REMOTE_USER_HOME/.bashrc" -sudo chown -R "${_REMOTE_USER}:${_REMOTE_USER}" /dc/gcloud-cli +# --- Generate a '$FEATURE_ID-post-create.sh' script to be executed by the 'postCreateCommand' lifecycle hook +# Looks like this is the best way to run a script in lifecycle hooks +# Source: https://github.com/devcontainers/features/blob/562305d37b97d47331d96306ffc2a0a3cce55e64/src/git-lfs/install.sh#L190C1-L190C109 +POST_CREATE_SCRIPT_PATH="/usr/local/share/$FEATURE_ID-post-create.sh" + +tee "$POST_CREATE_SCRIPT_PATH" >/dev/null \ + <<'EOF' +#!/bin/sh + +set -e + +# if the user is not root, chown /dc/aws-cli to the user +if [ "$(id -u)" != "0" ]; then + echo "Running post-start.sh for user $USER" + sudo chown -R "$USER:$USER" /dc/gcloud-cli +fi EOF -chown -R $_REMOTE_USER $_REMOTE_USER_HOME/.bashrc + +chmod 755 "$POST_CREATE_SCRIPT_PATH" diff --git a/src/github-cli-persistence/NOTES.md b/src/github-cli-persistence/NOTES.md index bca5fca..b22ada7 100644 --- a/src/github-cli-persistence/NOTES.md +++ b/src/github-cli-persistence/NOTES.md @@ -1,17 +1,14 @@ ## OS and Architecture Support -| | amd64 | arm64 | -| ------ | ----- | ----- | -| ubuntu | ✅ | ✔️ | -| debian | ✅ | ✔️ | - -- ✅: Tested and verified on Github Actions -- ✔️: Tested locally on my mac (but not on GHA) +Architectures: `amd` and `arm`. +OS: `ubuntu`, `debian` +Shells: `bash`, `zsh`, `fish` ## Changelog | Version | Notes | | ------- | ---------------------------------------------------- | +| 1.0.0 | Support zsh + refactor | | 0.0.3 | Delete some unnecessary "echo" statements | | 0.0.2 | `chown -R` the entire `~/.config` directory | | 0.0.1 | Rename ~/.config/gh to ~/.config/gh-old if it exists | diff --git a/src/github-cli-persistence/devcontainer-feature.json b/src/github-cli-persistence/devcontainer-feature.json index b3c166f..422e4ff 100644 --- a/src/github-cli-persistence/devcontainer-feature.json +++ b/src/github-cli-persistence/devcontainer-feature.json @@ -1,7 +1,7 @@ { "name": "Github CLI Persistence", "id": "github-cli-persistence", - "version": "0.0.3", + "version": "1.0.0", "documentationURL": "https://github.com/joshuanianji/devcontainer-features/tree/main/src/github-cli-persistence", "description": "Avoid extra logins from the Github CLI by preserving the `~/.config/gh` folder across container instances.", "options": {}, @@ -13,6 +13,8 @@ } ], "installsAfter": [ - "ghcr.io/devcontainers/features/github-cli" - ] + "ghcr.io/devcontainers/features/github-cli", + "ghcr.io/meaningful-ooo/devcontainer-features/fish" + ], + "postCreateCommand": "/usr/local/share/github-cli-persistence-post-create.sh" } \ No newline at end of file diff --git a/src/github-cli-persistence/install.sh b/src/github-cli-persistence/install.sh index 6098295..7e2ce95 100644 --- a/src/github-cli-persistence/install.sh +++ b/src/github-cli-persistence/install.sh @@ -1,35 +1,50 @@ #!/bin/sh set -e -echo "Activating feature 'github-cli-persistence'" +FEATURE_ID="github-cli-persistence" + +echo "Activating feature '$FEATURE_ID'" echo "User: ${_REMOTE_USER} User home: ${_REMOTE_USER_HOME}" -if [ -z "$_REMOTE_USER" ] || [ -z "$_REMOTE_USER_HOME" ]; then - echo "***********************************************************************************" - echo "*** Require _REMOTE_USER and _REMOTE_USER_HOME to be set (by dev container CLI) ***" - echo "***********************************************************************************" - exit 1 +if [ -z "$_REMOTE_USER" ] || [ -z "$_REMOTE_USER_HOME" ]; then + echo "***********************************************************************************" + echo "*** Require _REMOTE_USER and _REMOTE_USER_HOME to be set (by dev container CLI) ***" + echo "***********************************************************************************" + exit 1 fi # make ~/.config folder if doesn't exist mkdir -p "$_REMOTE_USER_HOME/.config" mkdir -p "/dc/github-cli" -# if `.config/gh` already exists, the `ln -s` command will create an extra +# if `.config/gh` already exists, the `ln -s` command will create an extra # folder *inside* `.config/gh` that symlinks to `github-cli` # Thus, we want to make sure the folder does NOT exist so the symlink will actually be to ~/.config/gh if [ -e "$_REMOTE_USER_HOME/.config/gh" ]; then - echo "Moving existing gh folder to gh-old" - mv "$_REMOTE_USER_HOME/.config/gh" "$_REMOTE_USER_HOME/.config/gh-old" + echo "Moving existing gh folder to gh-old" + mv "$_REMOTE_USER_HOME/.config/gh" "$_REMOTE_USER_HOME/.config/gh-old" fi ln -s /dc/github-cli "$_REMOTE_USER_HOME/.config/gh" -# chown the entire `.config` folder because devcontainers creates -# a `~/.config/vscode-dev-containers` folder later on -chown -R "${_REMOTE_USER}:${_REMOTE_USER}" "$_REMOTE_USER_HOME/.config" +# chown the entire `.config` folder because devcontainers creates +chown -R "${_REMOTE_USER}:${_REMOTE_USER}" "$_REMOTE_USER_HOME/.config/gh" + +# --- Generate a '$FEATURE_ID-post-create.sh' script to be executed by the 'postCreateCommand' lifecycle hook +# Looks like this is the best way to run a script in lifecycle hooks +# Source: https://github.com/devcontainers/features/blob/562305d37b97d47331d96306ffc2a0a3cce55e64/src/git-lfs/install.sh#L190C1-L190C109 +POST_CREATE_SCRIPT_PATH="/usr/local/share/$FEATURE_ID-post-create.sh" + +tee "$POST_CREATE_SCRIPT_PATH" >/dev/null \ + <<'EOF' +#!/bin/sh -# chown mount (only attached on startup) -cat << EOF >> "$_REMOTE_USER_HOME/.bashrc" -sudo chown -R "${_REMOTE_USER}:${_REMOTE_USER}" /dc/github-cli +set -e + +# if the user is not root, chown /dc/aws-cli to the user +if [ "$(id -u)" != "0" ]; then + echo "Running post-start.sh for user $USER" + sudo chown -R "$USER:$USER" /dc/github-cli +fi EOF -chown -R $_REMOTE_USER $_REMOTE_USER_HOME/.bashrc + +chmod 755 "$POST_CREATE_SCRIPT_PATH" diff --git a/src/lamdera/NOTES.md b/src/lamdera/NOTES.md index 3aac32d..6170de5 100644 --- a/src/lamdera/NOTES.md +++ b/src/lamdera/NOTES.md @@ -8,27 +8,20 @@ curl "https://static.lamdera.com/bin/lamdera-$VERSION-linux-$ARCH" ``` Based on my tests, v1.1.0 is the only one that works reliably. -## OS and Arch Support +## OS and Architecture Support -`v1.1.0` Supports the following OS and architectures: - -| | amd64 | arm64 | -| ------ | ----- | ----- | -| ubuntu | ✅ | ✔️ | -| debian | ✅ | ✔️ | - -- ✅: Tested and verified on Github Actions -- ✔️: Tested locally on my mac (but not on GHA) - -Other lamdera versions are not tested, but please submit an issue/PR if you need to use them! +Architectures: `amd` and `arm`. +OS: `ubuntu`, `debian` +Shells: `bash`, `zsh`, `fish` ## Changelog -| Version | Notes | -| ------- | ----------------- | -| 0.0.2 | Fix typos in Docs | -| 0.0.1 | Update Docs | -| 0.0.0 | Initial Version | +| Version | Notes | +| ------- | ----------------------------- | +| 1.0.0 | Support zsh/fish and refactor | +| 0.0.2 | Fix typos in Docs | +| 0.0.1 | Update Docs | +| 0.0.0 | Initial Version | ## References diff --git a/src/lamdera/devcontainer-feature.json b/src/lamdera/devcontainer-feature.json index 1a98550..3437416 100644 --- a/src/lamdera/devcontainer-feature.json +++ b/src/lamdera/devcontainer-feature.json @@ -1,7 +1,7 @@ { "name": "Lamdera", "id": "lamdera", - "version": "0.0.2", + "version": "1.0.0", "documentationURL": "https://github.com/joshuanianji/devcontainer-features/tree/main/src/lamdera", "description": "Installs [Lamdera](https://dashboard.lamdera.app/), a type-safe full-stack web-app platform for Elm (v1.1.0 and later).", "options": { @@ -16,6 +16,7 @@ } }, "installsAfter": [ - "ghcr.io/devcontainers/features/common-utils" + "ghcr.io/devcontainers/features/common-utils", + "ghcr.io/meaningful-ooo/devcontainer-features/fish" ] } \ No newline at end of file diff --git a/src/mount-pnpm-store/NOTES.md b/src/mount-pnpm-store/NOTES.md index 3f902e4..464b26c 100644 --- a/src/mount-pnpm-store/NOTES.md +++ b/src/mount-pnpm-store/NOTES.md @@ -1,3 +1,9 @@ +## OS and Architecture Support + +Architectures: `amd` and `arm`. +OS: `ubuntu`, `debian` +Shells: `bash`, `zsh`, `fish` + ## Important Implementation Details ### pnpm `store-dir` @@ -8,18 +14,18 @@ This is opinionated, but I dislike the pnpm store being in the workspace along w This feature does not install pnpm by itself and expects `pnpm` to be installed already, either by a base image or by a feature. If pnpm is not installed, it just gives a warning (you'll have a random ~/.pnpm-store folder in your home directory and the pnpm `store-dir` config will not be set) but does not fail. -If you are installing pnpm with a feature, you may need to ensure it is run **before** `mount-pnpm-store`. To make this work, use the [`overrideFeatureInstallOrder` property](https://containers.dev/implementors/features/#overrideFeatureInstallOrder), since the default feature installation order is based on ID (alphanumerically i think). Here is an example using `features/node`: +If you are installing pnpm with a feature, you may need to ensure it is run **before** `mount-pnpm-store`. I have set a soft dependency on `ghcr.io/devcontainers/features/node` already, but if it is any other feature that installs pnpm you might need to put some extra work. + +To make this work, use the [`overrideFeatureInstallOrder` property](https://containers.dev/implementors/features/#overrideFeatureInstallOrder), since the default feature installation order is based on ID (alphanumerically i think). Here is an example using a fake `unknown-install-pnpm`: ```json "image": "mcr.microsoft.com/devcontainers/base:bullseye", "features": { - "ghcr.io/devcontainers/features/node:1": { - "version": "20" - }, - "ghcr.io/joshuanianji/devcontainer-features/mount-pnpm-store": {} + "ghcr.io/random-user/devcontainer-features/unknown-install-pnpm:1": {}, + "ghcr.io/joshuanianji/devcontainer-features/mount-pnpm-store:1": {} }, "overrideFeatureInstallOrder": [ - "ghcr.io/devcontainers/features/node", + "ghcr.io/random-user/devcontainer-features/unknown-install-pnpm", "ghcr.io/joshuanianji/devcontainer-features/mount-pnpm-store" ] ``` @@ -30,11 +36,12 @@ The volume mount is called `global-devcontainer-pnpm-store`, so ensure that no o ## Changelog -| Version | Notes | -| ------- | ---------------------------------------------------- | -| 0.1.1 | Fix mount name | -| 0.1.0 | Documentation | -| 0.0.0 | Initial Version | +| Version | Notes | +| ------- | ---------------------- | +| 1.0.0 | Support zsh + refactor | +| 0.1.1 | Fix mount name | +| 0.1.0 | Documentation | +| 0.0.0 | Initial Version | ## References diff --git a/src/mount-pnpm-store/devcontainer-feature.json b/src/mount-pnpm-store/devcontainer-feature.json index 048800b..51e017c 100644 --- a/src/mount-pnpm-store/devcontainer-feature.json +++ b/src/mount-pnpm-store/devcontainer-feature.json @@ -1,7 +1,7 @@ { "name": "Mount pnpm Store", "id": "mount-pnpm-store", - "version": "0.1.1", + "version": "1.0.0", "documentationURL": "https://github.com/joshuanianji/devcontainer-features/tree/main/src/mount-pnpm-store", "description": "Sets pnpm store to ~/.pnpm-store and mounts it to a volume to share between multiple devcontainers", "options": {}, @@ -12,5 +12,10 @@ "type": "volume" } ], - "installsAfter": [] + "installsAfter": [ + "ghcr.io/devcontainers/features/node", + "ghcr.io/devcontainers/features/common-utils", + "ghcr.io/meaningful-ooo/devcontainer-features/fish" + ], + "postCreateCommand": "/usr/local/share/mount-pnpm-store-post-create.sh" } \ No newline at end of file diff --git a/src/mount-pnpm-store/install.sh b/src/mount-pnpm-store/install.sh index 576712c..e7b5693 100644 --- a/src/mount-pnpm-store/install.sh +++ b/src/mount-pnpm-store/install.sh @@ -1,10 +1,12 @@ #!/bin/sh set -e -echo "Activating feature 'mount-pnpm-store'" +FEATURE_ID="mount-pnpm-store" + +echo "Activating feature '$FEATURE_ID'" echo "User: ${_REMOTE_USER} User home: ${_REMOTE_USER_HOME}" -if [ -z "$_REMOTE_USER" ] || [ -z "$_REMOTE_USER_HOME" ]; then +if [ -z "$_REMOTE_USER" ] || [ -z "$_REMOTE_USER_HOME" ]; then echo "***********************************************************************************" echo "*** Require _REMOTE_USER and _REMOTE_USER_HOME to be set (by dev container CLI) ***" echo "***********************************************************************************" @@ -16,27 +18,38 @@ mkdir -p "/dc/mounted-pnpm-store" # as to why we move around the folder, check `github-cli-persistence/install.sh` if [ -e "$_REMOTE_USER_HOME/.pnpm-store" ]; then - echo "Moving existing .pnpm-store folder to .pnpm-store-old" - mv "$_REMOTE_USER_HOME/.pnpm-store" "$_REMOTE_USER_HOME/.pnpm-store-old" + echo "Moving existing .pnpm-store folder to .pnpm-store-old" + mv "$_REMOTE_USER_HOME/.pnpm-store" "$_REMOTE_USER_HOME/.pnpm-store-old" fi ln -s /dc/mounted-pnpm-store "$_REMOTE_USER_HOME/.pnpm-store" chown -R "$_REMOTE_USER:$_REMOTE_USER" "$_REMOTE_USER_HOME/.pnpm-store" -# chown mount (only attached on startup) -cat << EOF >> "$_REMOTE_USER_HOME/.bashrc" -sudo chown -R "$_REMOTE_USER:$_REMOTE_USER" /dc/mounted-pnpm-store -EOF -chown -R $_REMOTE_USER $_REMOTE_USER_HOME/.bashrc +# --- Generate a '$FEATURE_ID-post-create.sh' script to be executed by the 'postCreateCommand' lifecycle hook +# Looks like this is the best way to run a script in lifecycle hooks +# Source: https://github.com/devcontainers/features/blob/562305d37b97d47331d96306ffc2a0a3cce55e64/src/git-lfs/install.sh#L190C1-L190C109 +POST_CREATE_SCRIPT_PATH="/usr/local/share/$FEATURE_ID-post-create.sh" + +tee "$POST_CREATE_SCRIPT_PATH" >/dev/null \ + <<'EOF' +#!/bin/sh + +set -e -# set pnpm store location -# if pnpm is not installed, print out a warning -if type pnpm > /dev/null 2>&1; then +# set pnpm config (if it's installed) +if type pnpm >/dev/null 2>&1; then echo "Setting pnpm store location to $_REMOTE_USER_HOME/.pnpm-store" - # we have to run the `pnpm config set store-dir` as the remote user - # because the remote user is the one that will be using pnpm - runuser -l $_REMOTE_USER -c "pnpm config set store-dir $_REMOTE_USER_HOME/.pnpm-store --global" + pnpm config set store-dir ~/.pnpm-store --global else echo "WARN: pnpm is not installed! Please ensure pnpm is installed and in your PATH." echo "WARN: pnpm store location will not be set." fi + +# if the user is not root, chown /dc/mounted-pnpm-store to the user +if [ "$(id -u)" != "0" ]; then + echo "Running post-start.sh for user $USER" + sudo chown -R "$USER:$USER" /dc/mounted-pnpm-store +fi +EOF + +chmod 755 "$POST_CREATE_SCRIPT_PATH" diff --git a/src/terraform-cli-persistence/NOTES.md b/src/terraform-cli-persistence/NOTES.md index 1d06834..824aa21 100644 --- a/src/terraform-cli-persistence/NOTES.md +++ b/src/terraform-cli-persistence/NOTES.md @@ -1,8 +1,15 @@ +## OS and Architecture Support + +Architectures: `amd` and `arm`. +OS: `ubuntu`, `debian` +Shells: `bash`, `zsh`, `fish` + ## Changelog -| Version | Notes | -| ------- | --------------- | -| 0.0.0 | Initial Version | +| Version | Notes | +| ------- | ---------------------- | +| 1.0.0 | Support zsh + refactor | +| 0.0.0 | Initial Version | ## References diff --git a/src/terraform-cli-persistence/devcontainer-feature.json b/src/terraform-cli-persistence/devcontainer-feature.json index ede2ad4..02751f4 100644 --- a/src/terraform-cli-persistence/devcontainer-feature.json +++ b/src/terraform-cli-persistence/devcontainer-feature.json @@ -1,7 +1,7 @@ { "name": "Terraform CLI Persistence", "id": "terraform-cli-persistence", - "version": "0.0.0", + "version": "1.0.0", "documentationURL": "https://github.com/joshuanianji/devcontainer-features/tree/main/src/terraform-cli-persistence", "description": "Avoid extra logins from the Terraform CLI by preserving the `~/.terraform.d` folder across container instances.", "options": {}, @@ -13,6 +13,9 @@ } ], "installsAfter": [ - "ghcr.io/devcontainers/features/terraform" - ] + "ghcr.io/devcontainers/features/terraform", + "ghcr.io/devcontainers/features/common-utils", + "ghcr.io/meaningful-ooo/devcontainer-features/fish" + ], + "postCreateCommand": "/usr/local/share/terraform-cli-persistence-post-create.sh" } \ No newline at end of file diff --git a/src/terraform-cli-persistence/install.sh b/src/terraform-cli-persistence/install.sh index 609bd50..93cf38a 100644 --- a/src/terraform-cli-persistence/install.sh +++ b/src/terraform-cli-persistence/install.sh @@ -1,14 +1,16 @@ #!/bin/sh set -e -echo "Activating feature 'terraform-cli-persistence'" +FEATURE_ID="terraform-cli-persistence" + +echo "Activating feature '$FEATURE_ID'" echo "User: ${_REMOTE_USER} User home: ${_REMOTE_USER_HOME}" -if [ -z "$_REMOTE_USER" ] || [ -z "$_REMOTE_USER_HOME" ]; then - echo "***********************************************************************************" - echo "*** Require _REMOTE_USER and _REMOTE_USER_HOME to be set (by dev container CLI) ***" - echo "***********************************************************************************" - exit 1 +if [ -z "$_REMOTE_USER" ] || [ -z "$_REMOTE_USER_HOME" ]; then + echo "***********************************************************************************" + echo "*** Require _REMOTE_USER and _REMOTE_USER_HOME to be set (by dev container CLI) ***" + echo "***********************************************************************************" + exit 1 fi # make /dc/terraform-cli folder if doesn't exist @@ -16,17 +18,31 @@ mkdir -p "/dc/terraform-cli" # as to why we move around the folder, check `github-cli-persistence/install.sh` if [ -e "$_REMOTE_USER_HOME/.terraform.d" ]; then - echo "Moving existing .terraform.d folder to .terraform.d-old" - mv "$_REMOTE_USER_HOME/.terraform.d" "$_REMOTE_USER_HOME/.terraform.d-old" + echo "Moving existing .terraform.d folder to .terraform.d-old" + mv "$_REMOTE_USER_HOME/.terraform.d" "$_REMOTE_USER_HOME/.terraform.d-old" fi ln -s /dc/terraform-cli "$_REMOTE_USER_HOME/.terraform.d" -# chown the entire `.config` folder because devcontainers creates -# a `~/.config/vscode-dev-containers` folder later on +# chown the entire `.config` folder because devcontainers creates +# a `~/.config/vscode-dev-containers` folder later on chown -R "${_REMOTE_USER}:${_REMOTE_USER}" "$_REMOTE_USER_HOME/.terraform.d" -# chown mount (only attached on startup) -cat << EOF >> "$_REMOTE_USER_HOME/.bashrc" -sudo chown -R "${_REMOTE_USER}:${_REMOTE_USER}" /dc/terraform-cli +# --- Generate a '$FEATURE_ID-post-create.sh' script to be executed by the 'postCreateCommand' lifecycle hook +# Looks like this is the best way to run a script in lifecycle hooks +# Source: https://github.com/devcontainers/features/blob/562305d37b97d47331d96306ffc2a0a3cce55e64/src/git-lfs/install.sh#L190C1-L190C109 +POST_CREATE_SCRIPT_PATH="/usr/local/share/$FEATURE_ID-post-create.sh" + +tee "$POST_CREATE_SCRIPT_PATH" >/dev/null \ + <<'EOF' +#!/bin/sh + +set -e + +# if the user is not root, chown /dc/aws-cli to the user +if [ "$(id -u)" != "0" ]; then + echo "Running post-start.sh for user $USER" + sudo chown -R "$USER:$USER" /dc/terraform-cli +fi EOF -chown -R $_REMOTE_USER $_REMOTE_USER_HOME/.bashrc + +chmod 755 "$POST_CREATE_SCRIPT_PATH" diff --git a/test/aws-cli-persistence/_default.sh b/test/aws-cli-persistence/_default.sh new file mode 100755 index 0000000..a1295c1 --- /dev/null +++ b/test/aws-cli-persistence/_default.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +set -e + +# This script is the "default" test script for the aws-cli-persistence feature. +# 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 `aws --help` works +check "help" bash -c "aws help | grep 'usage'" + +# check that `.aws` and `/dc/aws-cli` exist under the user (should be node) +check "~/.aws existence" bash -c "ls -la ~ | grep '.aws'" +check "/dc/aws-cli existence" bash -c "ls -la /dc | grep 'aws-cli'" + +# check that the folders are owned by the user +# https://askubuntu.com/a/175060 +echo "Checking ownership of ~/.aws and /dc/aws-cli (ensure it is owned by $USER)" + +check "~/.aws owned by user" bash -c "test \"$(stat -c "%U" ~/.aws)\" = $USER" +check "/dc/aws-cli owned by user" bash -c "test \"$(stat -c "%U" /dc/aws-cli)\" = $USER" + +# Report result +reportResults diff --git a/test/aws-cli-persistence/fish_shell.sh b/test/aws-cli-persistence/fish_shell.sh new file mode 100644 index 0000000..1fe2fa4 --- /dev/null +++ b/test/aws-cli-persistence/fish_shell.sh @@ -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 diff --git a/test/aws-cli-persistence/root_user.sh b/test/aws-cli-persistence/root_user.sh new file mode 100644 index 0000000..1898f45 --- /dev/null +++ b/test/aws-cli-persistence/root_user.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +set -e + +source dev-container-features-test-lib + +# Run default test script (in same folder) +# See: https://github.com/devcontainers/features/blob/562305d37b97d47331d96306ffc2a0a3cce55e64/test/azure-cli/install_extensions_bookworm.sh +./_default.sh diff --git a/test/aws-cli-persistence/scenarios.json b/test/aws-cli-persistence/scenarios.json index 31dbef2..52bf258 100644 --- a/test/aws-cli-persistence/scenarios.json +++ b/test/aws-cli-persistence/scenarios.json @@ -2,8 +2,34 @@ "with_node": { "image": "mcr.microsoft.com/devcontainers/javascript-node:1-18", "features": { - "aws-cli-persistence": {}, - "ghcr.io/devcontainers/features/aws-cli": {} + "ghcr.io/devcontainers/features/aws-cli": {}, + "aws-cli-persistence": {} } + }, + "zsh_shell": { + "image": "mcr.microsoft.com/devcontainers/base:debian", + "features": { + "ghcr.io/devcontainers/features/common-utils:2": { + "configureZshAsDefaultShell": true + }, + "ghcr.io/devcontainers/features/aws-cli": {}, + "aws-cli-persistence": {} + } + }, + "fish_shell": { + "image": "mcr.microsoft.com/devcontainers/base:debian", + "features": { + "ghcr.io/meaningful-ooo/devcontainer-features/fish:1": {}, + "ghcr.io/devcontainers/features/aws-cli": {}, + "aws-cli-persistence": {} + } + }, + "root_user": { + "image": "mcr.microsoft.com/devcontainers/base:debian", + "features": { + "ghcr.io/devcontainers/features/aws-cli": {}, + "aws-cli-persistence": {} + }, + "remoteUser": "root" } -} +} \ No newline at end of file diff --git a/test/aws-cli-persistence/with_node.sh b/test/aws-cli-persistence/with_node.sh index bd22931..1fe2fa4 100644 --- a/test/aws-cli-persistence/with_node.sh +++ b/test/aws-cli-persistence/with_node.sh @@ -2,21 +2,6 @@ set -e -# Optional: Import test library -source dev-container-features-test-lib - -# check that `aws --help` works -check "help" bash -c "aws help | grep 'usage'" - -# check that `.aws` and `/dc/aws-cli` exist under the user (should be node) -check "~/.aws existence" bash -c "ls -la ~ | grep '.aws'" -check "/dc/aws-cli existence" bash -c "ls -la /dc | grep 'aws-cli'" - -# check that the folders are owned by the user -# `stat -c "%U %G" ~/.aws` returns "$USER $GROUP", in this case "node node" -# https://askubuntu.com/a/175060 -check "~/.aws owned by user" bash -c "test \"$(stat -c "%U %G" ~/.aws)\" = 'node node'" -check "/dc/aws-cli owned by user" bash -c "test \"$(stat -c "%U %G" /dc/aws-cli)\" = 'node node'" - -# Report result -reportResults +# Run default test script (in same folder) +# See: https://github.com/devcontainers/features/blob/562305d37b97d47331d96306ffc2a0a3cce55e64/test/azure-cli/install_extensions_bookworm.sh +./_default.sh diff --git a/test/aws-cli-persistence/zsh_shell.sh b/test/aws-cli-persistence/zsh_shell.sh new file mode 100644 index 0000000..1fe2fa4 --- /dev/null +++ b/test/aws-cli-persistence/zsh_shell.sh @@ -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 diff --git a/test/gcloud-cli-persistence/_default.sh b/test/gcloud-cli-persistence/_default.sh new file mode 100644 index 0000000..9bc0e63 --- /dev/null +++ b/test/gcloud-cli-persistence/_default.sh @@ -0,0 +1,26 @@ +#!/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 `gcloud --help` works +check "help" bash -c "gcloud --help | grep 'NAME'" + +# check that `.config/gcloud` and `/dc/gcloud-cli` exist under the user (should be node) +check "config" bash -c "ls -la ~/.config | grep 'gcloud'" +check "dc" bash -c "ls -la /dc | grep 'gcloud-cli'" + +# check that the folders are owned by the user +# https://askubuntu.com/a/175060 +echo "Checking ownership of ~/.config/gcloud and /dc/gcloud-cli (ensure it is owned by $USER)" + +check "~/.config/gloud owned by user" bash -c "test \"$(stat -c "%U" ~/.config/gcloud)\" = $USER" +check "/dc/gcloud-cli owned by user" bash -c "test \"$(stat -c "%U" /dc/gcloud-cli)\" = $USER" + +# Report result +reportResults diff --git a/test/gcloud-cli-persistence/fish_shell.sh b/test/gcloud-cli-persistence/fish_shell.sh new file mode 100644 index 0000000..1fe2fa4 --- /dev/null +++ b/test/gcloud-cli-persistence/fish_shell.sh @@ -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 diff --git a/test/gcloud-cli-persistence/root_user.sh b/test/gcloud-cli-persistence/root_user.sh new file mode 100644 index 0000000..1fe2fa4 --- /dev/null +++ b/test/gcloud-cli-persistence/root_user.sh @@ -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 diff --git a/test/gcloud-cli-persistence/scenarios.json b/test/gcloud-cli-persistence/scenarios.json index 6e274b1..f0e926f 100644 --- a/test/gcloud-cli-persistence/scenarios.json +++ b/test/gcloud-cli-persistence/scenarios.json @@ -2,8 +2,34 @@ "with_node": { "image": "mcr.microsoft.com/devcontainers/javascript-node:1-18", "features": { - "gcloud-cli-persistence": {}, - "ghcr.io/dhoeric/features/google-cloud-cli": {} + "ghcr.io/dhoeric/features/google-cloud-cli": {}, + "gcloud-cli-persistence": {} } + }, + "zsh_shell": { + "image": "mcr.microsoft.com/devcontainers/base:debian", + "features": { + "ghcr.io/devcontainers/features/common-utils:2": { + "configureZshAsDefaultShell": true + }, + "ghcr.io/dhoeric/features/google-cloud-cli": {}, + "gcloud-cli-persistence": {} + } + }, + "fish_shell": { + "image": "mcr.microsoft.com/devcontainers/base:debian", + "features": { + "ghcr.io/meaningful-ooo/devcontainer-features/fish:1": {}, + "ghcr.io/dhoeric/features/google-cloud-cli": {}, + "gcloud-cli-persistence": {} + } + }, + "root_user": { + "image": "mcr.microsoft.com/devcontainers/base:debian", + "features": { + "ghcr.io/dhoeric/features/google-cloud-cli": {}, + "gcloud-cli-persistence": {} + }, + "remoteUser": "root" } } \ No newline at end of file diff --git a/test/gcloud-cli-persistence/with_node.sh b/test/gcloud-cli-persistence/with_node.sh index ba526cd..1fe2fa4 100644 --- a/test/gcloud-cli-persistence/with_node.sh +++ b/test/gcloud-cli-persistence/with_node.sh @@ -2,21 +2,6 @@ set -e -# Optional: Import test library -source dev-container-features-test-lib - -# check that `gcloud --help` works -check "help" bash -c "gcloud --help | grep 'NAME'" - -# check that `.config/gcloud` and `/dc/gcloud-cli` exist under the user (should be node) -check "config" bash -c "ls -la ~/.config | grep 'gcloud'" -check "dc" bash -c "ls -la /dc | grep 'gcloud-cli'" - -# check that the folders are owned by the user -# `stat -c "%U %G" ~/.config` returns "$USER $GROUP", in this case "node node" -# https://askubuntu.com/a/175060 -check "~/.config/gloud owned by user" bash -c "test \"$(stat -c "%U %G" ~/.config/gcloud)\" = 'node node'" -check "/dc/gcloud-cli owned by user" bash -c "test \"$(stat -c "%U %G" /dc/gcloud-cli)\" = 'node node'" - -# Report result -reportResults +# Run default test script (in same folder) +# See: https://github.com/devcontainers/features/blob/562305d37b97d47331d96306ffc2a0a3cce55e64/test/azure-cli/install_extensions_bookworm.sh +./_default.sh diff --git a/test/gcloud-cli-persistence/zsh_shell.sh b/test/gcloud-cli-persistence/zsh_shell.sh new file mode 100644 index 0000000..1fe2fa4 --- /dev/null +++ b/test/gcloud-cli-persistence/zsh_shell.sh @@ -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 diff --git a/test/github-cli-persistence/_default.sh b/test/github-cli-persistence/_default.sh new file mode 100644 index 0000000..5fb5918 --- /dev/null +++ b/test/github-cli-persistence/_default.sh @@ -0,0 +1,26 @@ +#!/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 `gh --help` works +check "help" bash -c "gh --help | grep 'USAGE'" + +# check that `.config/gh` and `/dc/github-cli` exist under the user (should be node) +check "config" bash -c "ls -la ~/.config | grep 'gh'" +check "dc" bash -c "ls -la /dc | grep 'github-cli'" + +# check that the folders are owned by the user +# https://askubuntu.com/a/175060 +echo "Checking ownership of ~/.config/gh and /dc/github-cli (ensure it is owned by $USER)" + +check "~/.config/gh owned by user" bash -c "test \"$(stat -c "%U" ~/.config/gh)\" = $USER" +check "/dc/github-cli owned by user" bash -c "test \"$(stat -c "%U" /dc/github-cli)\" = $USER" + +# Report result +reportResults diff --git a/test/github-cli-persistence/fish_shell.sh b/test/github-cli-persistence/fish_shell.sh new file mode 100644 index 0000000..1fe2fa4 --- /dev/null +++ b/test/github-cli-persistence/fish_shell.sh @@ -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 diff --git a/test/github-cli-persistence/root_user.sh b/test/github-cli-persistence/root_user.sh new file mode 100644 index 0000000..1fe2fa4 --- /dev/null +++ b/test/github-cli-persistence/root_user.sh @@ -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 diff --git a/test/github-cli-persistence/scenarios.json b/test/github-cli-persistence/scenarios.json index 0a25476..71f0937 100644 --- a/test/github-cli-persistence/scenarios.json +++ b/test/github-cli-persistence/scenarios.json @@ -2,8 +2,34 @@ "with_node": { "image": "mcr.microsoft.com/devcontainers/javascript-node:1-18", "features": { - "github-cli-persistence": {}, - "ghcr.io/devcontainers/features/github-cli": {} + "ghcr.io/devcontainers/features/github-cli": {}, + "github-cli-persistence": {} } + }, + "zsh_shell": { + "image": "mcr.microsoft.com/devcontainers/base:debian", + "features": { + "ghcr.io/devcontainers/features/common-utils:2": { + "configureZshAsDefaultShell": true + }, + "ghcr.io/devcontainers/features/github-cli": {}, + "github-cli-persistence": {} + } + }, + "fish_shell": { + "image": "mcr.microsoft.com/devcontainers/base:debian", + "features": { + "ghcr.io/meaningful-ooo/devcontainer-features/fish:1": {}, + "ghcr.io/devcontainers/features/github-cli": {}, + "github-cli-persistence": {} + } + }, + "root_user": { + "image": "mcr.microsoft.com/devcontainers/base:debian", + "features": { + "ghcr.io/devcontainers/features/github-cli": {}, + "github-cli-persistence": {} + }, + "remoteUser": "root" } -} +} \ No newline at end of file diff --git a/test/github-cli-persistence/with_node.sh b/test/github-cli-persistence/with_node.sh index c55f121..1fe2fa4 100644 --- a/test/github-cli-persistence/with_node.sh +++ b/test/github-cli-persistence/with_node.sh @@ -2,21 +2,6 @@ set -e -# Optional: Import test library -source dev-container-features-test-lib - -# check that `gh --help` works -check "help" bash -c "gh --help | grep 'USAGE'" - -# check that `.config/gh` and `/dc/github-cli` exist under the user (should be node) -check "config" bash -c "ls -la ~/.config | grep 'gh'" -check "dc" bash -c "ls -la /dc | grep 'github-cli'" - -# check that the folders are owned by the user -# `stat -c "%U %G" ~/.config` returns "$USER $GROUP", in this case "node node" -# https://askubuntu.com/a/175060 -check "~/.config/gh owned by user" bash -c "test \"$(stat -c "%U %G" ~/.config)\" = 'node node'" -check "/dc/github-cli owned by user" bash -c "test \"$(stat -c "%U %G" /dc/github-cli)\" = 'node node'" - -# Report result -reportResults +# Run default test script (in same folder) +# See: https://github.com/devcontainers/features/blob/562305d37b97d47331d96306ffc2a0a3cce55e64/test/azure-cli/install_extensions_bookworm.sh +./_default.sh diff --git a/test/github-cli-persistence/zsh_shell.sh b/test/github-cli-persistence/zsh_shell.sh new file mode 100644 index 0000000..1fe2fa4 --- /dev/null +++ b/test/github-cli-persistence/zsh_shell.sh @@ -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 diff --git a/test/lamdera/_default.sh b/test/lamdera/_default.sh new file mode 100644 index 0000000..7e7c9b1 --- /dev/null +++ b/test/lamdera/_default.sh @@ -0,0 +1,18 @@ +#!/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 running the binary by itself works +check "normal" bash -c "lamdera" + +# check version +check "version" bash -c "lamdera --version" + +# Report result +reportResults diff --git a/test/lamdera/fish_shell.sh b/test/lamdera/fish_shell.sh new file mode 100644 index 0000000..1fe2fa4 --- /dev/null +++ b/test/lamdera/fish_shell.sh @@ -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 diff --git a/test/lamdera/scenarios.json b/test/lamdera/scenarios.json index aecd407..e1e3977 100644 --- a/test/lamdera/scenarios.json +++ b/test/lamdera/scenarios.json @@ -6,5 +6,21 @@ "version": "1.1.0" } } + }, + "zsh_shell": { + "image": "mcr.microsoft.com/devcontainers/base:debian", + "features": { + "ghcr.io/devcontainers/features/common-utils:2": { + "configureZshAsDefaultShell": true + }, + "lamdera": {} + } + }, + "fish_shell": { + "image": "mcr.microsoft.com/devcontainers/base:debian", + "features": { + "ghcr.io/meaningful-ooo/devcontainer-features/fish:1": {}, + "lamdera": {} + } } -} +} \ No newline at end of file diff --git a/test/lamdera/v1.1.0.sh b/test/lamdera/v1.1.0.sh index c408c70..1fe2fa4 100644 --- a/test/lamdera/v1.1.0.sh +++ b/test/lamdera/v1.1.0.sh @@ -2,14 +2,6 @@ set -e -# Optional: Import test library -source dev-container-features-test-lib - -# check that running the binary by itself works -check "normal" bash -c "lamdera" - -# check version -check "version" bash -c "lamdera --version" - -# Report result -reportResults +# Run default test script (in same folder) +# See: https://github.com/devcontainers/features/blob/562305d37b97d47331d96306ffc2a0a3cce55e64/test/azure-cli/install_extensions_bookworm.sh +./_default.sh diff --git a/test/lamdera/zsh_shell.sh b/test/lamdera/zsh_shell.sh new file mode 100644 index 0000000..1fe2fa4 --- /dev/null +++ b/test/lamdera/zsh_shell.sh @@ -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 diff --git a/test/mount-pnpm-store/_default.sh b/test/mount-pnpm-store/_default.sh new file mode 100644 index 0000000..0beadc9 --- /dev/null +++ b/test/mount-pnpm-store/_default.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +set -e + +# 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 + +# user is `node` in dev container + +echo "User: $(whoami)" +pnpm config list + +# check that `pnpm config get store-dir` equals ~/.pnpm-store +pnpmConfig=$(pnpm config get store-dir) +echo "pnpm config get store-dir: '$pnpmConfig'" +check "config" test $pnpmConfig = "$(echo ~)/.pnpm-store" + +# check that the folders are owned by the user +# https://askubuntu.com/a/175060 +echo "Checking ownership of /dc/mounted-pnpm-store (ensure it is owned by $USER)" + +check "/dc/mounted-pnpm-store owned by user" bash -c "test \"$(stat -c "%U" /dc/mounted-pnpm-store)\" = $USER" + +# Report result +reportResults diff --git a/test/mount-pnpm-store/fish_shell.sh b/test/mount-pnpm-store/fish_shell.sh new file mode 100644 index 0000000..ace33be --- /dev/null +++ b/test/mount-pnpm-store/fish_shell.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +set -e + +# tests installing pnpm after zsh shell + +./_default.sh diff --git a/test/mount-pnpm-store/pnpm_from_feature.sh b/test/mount-pnpm-store/pnpm_from_feature.sh new file mode 100644 index 0000000..e9d42a7 --- /dev/null +++ b/test/mount-pnpm-store/pnpm_from_feature.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +set -e + +# tests installing pnpm through a feature + +./_default.sh diff --git a/test/mount-pnpm-store/root_user.sh b/test/mount-pnpm-store/root_user.sh new file mode 100644 index 0000000..e9d42a7 --- /dev/null +++ b/test/mount-pnpm-store/root_user.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +set -e + +# tests installing pnpm through a feature + +./_default.sh diff --git a/test/mount-pnpm-store/scenarios.json b/test/mount-pnpm-store/scenarios.json index f0ab156..f7a1355 100644 --- a/test/mount-pnpm-store/scenarios.json +++ b/test/mount-pnpm-store/scenarios.json @@ -5,16 +5,34 @@ "mount-pnpm-store": {} } }, - "with_pnpm": { + "pnpm_from_feature": { "image": "mcr.microsoft.com/devcontainers/base:bullseye", "features": { - "ghcr.io/devcontainers/features/node:1": { - "version": "20" + "ghcr.io/devcontainers/features/node:1": {}, + "mount-pnpm-store": {} + } + }, + "zsh_shell": { + "image": "mcr.microsoft.com/devcontainers/javascript-node:1-18", + "features": { + "ghcr.io/devcontainers/features/common-utils:2": { + "configureZshAsDefaultShell": true }, "mount-pnpm-store": {} + } + }, + "fish_shell": { + "image": "mcr.microsoft.com/devcontainers/javascript-node:1-18", + "features": { + "ghcr.io/meaningful-ooo/devcontainer-features/fish:1": {}, + "mount-pnpm-store": {} + } + }, + "root_user": { + "image": "mcr.microsoft.com/devcontainers/javascript-node:1-18", + "features": { + "mount-pnpm-store": {} }, - "overrideFeatureInstallOrder": [ - "ghcr.io/devcontainers/features/node", "./mount-pnpm-store" - ] + "remoteUser": "root" } -} +} \ No newline at end of file diff --git a/test/mount-pnpm-store/with_node.sh b/test/mount-pnpm-store/with_node.sh index b20456b..2f6c9ea 100644 --- a/test/mount-pnpm-store/with_node.sh +++ b/test/mount-pnpm-store/with_node.sh @@ -4,18 +4,4 @@ set -e # tests installing pnpm mount when pnpm is already installed in the base image -# Optional: Import test library -source dev-container-features-test-lib - -# user is `node` in dev container - -echo "User: $(whoami)" -pnpm config list - -# check that `pnpm config get store-dir` equals /home/node/.pnpm-store -pnpmConfig=$(pnpm config get store-dir) -echo "pnpm config get store-dir: '$pnpmConfig'" -check "config" test $pnpmConfig = "/home/node/.pnpm-store" - -# Report result -reportResults +./_default.sh diff --git a/test/mount-pnpm-store/with_pnpm.sh b/test/mount-pnpm-store/with_pnpm.sh deleted file mode 100644 index b55cb7a..0000000 --- a/test/mount-pnpm-store/with_pnpm.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash - -set -e - -# tests installing pnpm with a feature - -# Optional: Import test library -source dev-container-features-test-lib - -echo "User: $(whoami)" -pnpm config list - -# check that `pnpm config get store-dir` returns /home/vscode/.pnpm-store -pnpmConfig=$(pnpm config get store-dir) -echo "pnpm config get store-dir: '$pnpmConfig'" -check "config" test $pnpmConfig = "/home/vscode/.pnpm-store" - -# Report result -reportResults diff --git a/test/mount-pnpm-store/zsh_shell.sh b/test/mount-pnpm-store/zsh_shell.sh new file mode 100644 index 0000000..ace33be --- /dev/null +++ b/test/mount-pnpm-store/zsh_shell.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +set -e + +# tests installing pnpm after zsh shell + +./_default.sh diff --git a/test/terraform-cli-persistence/_default.sh b/test/terraform-cli-persistence/_default.sh new file mode 100644 index 0000000..9b6656f --- /dev/null +++ b/test/terraform-cli-persistence/_default.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +set -e + +# 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 `terraform --help` works +check "help" bash -c "terraform --help | grep 'Usage'" + +# check that `.terraform.d` and `/dc/terraform-cli` exist under the user (should be node) +check "~/.terraform.d existence" bash -c "ls -la ~ | grep '.terraform.d'" +check "/dc/terraform-cli existence" bash -c "ls -la /dc | grep 'terraform-cli'" + +# check that the folders are owned by the user +# https://askubuntu.com/a/175060 +echo "Checking ownership of ~/.terraform.d and /dc/terraform-cli (ensure it is owned by $USER)" + +check "~/.terraform.d owned by user" bash -c "test \"$(stat -c "%U" ~/.terraform.d)\" = $USER" +check "/dc/terraform-cli owned by user" bash -c "test \"$(stat -c "%U" /dc/terraform-cli)\" = $USER" + +# Report result +reportResults diff --git a/test/terraform-cli-persistence/fish_shell.sh b/test/terraform-cli-persistence/fish_shell.sh new file mode 100644 index 0000000..ace33be --- /dev/null +++ b/test/terraform-cli-persistence/fish_shell.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +set -e + +# tests installing pnpm after zsh shell + +./_default.sh diff --git a/test/terraform-cli-persistence/root_user.sh b/test/terraform-cli-persistence/root_user.sh new file mode 100644 index 0000000..9bbf662 --- /dev/null +++ b/test/terraform-cli-persistence/root_user.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +set -e + +./_default.sh diff --git a/test/terraform-cli-persistence/scenarios.json b/test/terraform-cli-persistence/scenarios.json index 042a81d..6db9786 100644 --- a/test/terraform-cli-persistence/scenarios.json +++ b/test/terraform-cli-persistence/scenarios.json @@ -2,8 +2,34 @@ "with_node": { "image": "mcr.microsoft.com/devcontainers/javascript-node:1-18", "features": { - "terraform-cli-persistence": {}, - "ghcr.io/devcontainers/features/terraform:1": {} + "ghcr.io/devcontainers/features/terraform:1": {}, + "terraform-cli-persistence": {} } + }, + "zsh_shell": { + "image": "mcr.microsoft.com/devcontainers/base:debian", + "features": { + "ghcr.io/devcontainers/features/common-utils:2": { + "configureZshAsDefaultShell": true + }, + "ghcr.io/devcontainers/features/terraform:1": {}, + "terraform-cli-persistence": {} + } + }, + "fish_shell": { + "image": "mcr.microsoft.com/devcontainers/base:debian", + "features": { + "ghcr.io/meaningful-ooo/devcontainer-features/fish:1": {}, + "ghcr.io/devcontainers/features/terraform:1": {}, + "terraform-cli-persistence": {} + } + }, + "root_user": { + "image": "mcr.microsoft.com/devcontainers/base:debian", + "features": { + "ghcr.io/devcontainers/features/terraform:1": {}, + "terraform-cli-persistence": {} + }, + "remoteUser": "root" } -} +} \ No newline at end of file diff --git a/test/terraform-cli-persistence/with_node.sh b/test/terraform-cli-persistence/with_node.sh index e6b8819..9bbf662 100644 --- a/test/terraform-cli-persistence/with_node.sh +++ b/test/terraform-cli-persistence/with_node.sh @@ -2,21 +2,4 @@ set -e -# Optional: Import test library -source dev-container-features-test-lib - -# check that `terraform --help` works -check "help" bash -c "terraform --help | grep 'Usage'" - -# check that `.terraform.d` and `/dc/terraform-cli` exist under the user (should be node) -check "~/.terraform.d existence" bash -c "ls -la ~ | grep '.terraform.d'" -check "/dc/terraform-cli existence" bash -c "ls -la /dc | grep 'terraform-cli'" - -# check that the folders are owned by the user -# `stat -c "%U %G" ~/.terraform.d` returns "$USER $GROUP", in this case "node node" -# https://askubuntu.com/a/175060 -check "~/.terraform.d owned by user" bash -c "test \"$(stat -c "%U %G" ~/.terraform.d)\" = 'node node'" -check "/dc/terraform-cli owned by user" bash -c "test \"$(stat -c "%U %G" /dc/terraform-cli)\" = 'node node'" - -# Report result -reportResults +./_default.sh diff --git a/test/terraform-cli-persistence/zsh_shell.sh b/test/terraform-cli-persistence/zsh_shell.sh new file mode 100644 index 0000000..9bbf662 --- /dev/null +++ b/test/terraform-cli-persistence/zsh_shell.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +set -e + +./_default.sh