generated from devcontainers/feature-starter
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from joshuanianji/pnpm-global-store
(feat) PNPM Global Mount Feature
- Loading branch information
Showing
12 changed files
with
184 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
## Important Implementation Details | ||
|
||
### Ensuring PNPM is installed | ||
|
||
This feature does not install PNPM by itself and expects `pnpm` to be installed already, either by a base image or by a feature. It fails quietly if pnpm is not installed. | ||
|
||
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`: | ||
|
||
```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": {} | ||
}, | ||
"overrideFeatureInstallOrder": [ | ||
"ghcr.io/devcontainers/features/node", | ||
"ghcr.io/joshuanianji/devcontainer-features/mount-pnpm-store" | ||
] | ||
``` | ||
|
||
### Volume Mount Naming | ||
|
||
The volume mount is called `global-devcontainer-pnpm-store`, so ensure that no other docker volumes match this name. | ||
|
||
## Changelog | ||
|
||
| Version | Notes | | ||
| ------- | ---------------------------------------------------- | | ||
| 0.0.0 | Initial Version | | ||
|
||
## References | ||
|
||
- [PNPM Devcontainer Setup by PatrickChoDev](https://gist.github.com/PatrickChoDev/81d36159aca4dc687b8c89983e64da2e) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "Mount PNPM Store", | ||
"id": "mount-pnpm-store", | ||
"version": "0.0.0", | ||
"documentationURL": "https://github.com/joshuanianji/devcontainer-features/tree/main/src/mount-pnpm-store", | ||
"description": "Mounts the pnpm store to a volume to share between multiple devcontainers, and sets pnpm store to ~/.pnpm-store. Fails if pnpm is not installed.", | ||
"options": {}, | ||
"mounts": [ | ||
{ | ||
"source": "global-devcontainer-pnpm-store", | ||
"target": "/dc/pnpm-store", | ||
"type": "volume" | ||
} | ||
], | ||
"installsAfter": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/bin/sh | ||
set -e | ||
|
||
echo "Activating feature 'mount-pnpm-store'" | ||
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 | ||
fi | ||
|
||
# make /dc/mounted-pnpm-store folder if doesn't exist | ||
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" | ||
fi | ||
|
||
ln -s /dc/mounted-pnpm-store "$_REMOTE_USER_HOME/.pnpm-store" | ||
# 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/.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 | ||
|
||
# set pnpm store location | ||
# if pnpm is not installed, print out a warning | ||
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" | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"with_node": { | ||
"image": "mcr.microsoft.com/devcontainers/javascript-node:1-18", | ||
"features": { | ||
"mount-pnpm-store": {} | ||
} | ||
}, | ||
"with_pnpm": { | ||
"image": "mcr.microsoft.com/devcontainers/base:bullseye", | ||
"features": { | ||
"ghcr.io/devcontainers/features/node:1": { | ||
"version": "20" | ||
}, | ||
"mount-pnpm-store": {} | ||
}, | ||
"overrideFeatureInstallOrder": [ | ||
"ghcr.io/devcontainers/features/node", "./mount-pnpm-store" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/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 'mount-pnpm-store' feature with no options. | ||
# | ||
# https://github.com/devcontainers/cli/blob/main/docs/features/test.md | ||
# | ||
# From my tests, this means the `pnpm` CLI will not be installed | ||
|
||
# check that `~/.pnpm-store` and `/dc/mounted-pnpm-store` exist` | ||
check "config" bash -c "ls -la ~ | grep '.pnpm-store'" | ||
check "dc" bash -c "ls -la /dc | grep 'mounted-pnpm-store'" | ||
|
||
# check that `~/.pnpm-store` is a symlink | ||
# https://unix.stackexchange.com/a/96910 | ||
check "~/.pnpm-store is a symlink" bash -c "test -L ~/.pnpm-store && test -d ~/.pnpm-store" | ||
|
||
# Report result | ||
reportResults |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/bash | ||
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters