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

Support ZSH #38

Merged
merged 24 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
13 changes: 6 additions & 7 deletions .devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,18 @@
]
},
"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": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
"ghcr.io/devcontainers/features/github-cli:1": {},
"ghcr.io/joshuanianji/devcontainer-features/github-cli-persistence:0": {}
},
"remoteUser": "node",
"updateContentCommand": "npm install -g @devcontainers/cli"
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
13 changes: 10 additions & 3 deletions src/aws-cli-persistence/NOTES.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
8 changes: 5 additions & 3 deletions src/aws-cli-persistence/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -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": {},
Expand All @@ -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"
}
40 changes: 28 additions & 12 deletions src/aws-cli-persistence/install.sh
Original file line number Diff line number Diff line change
@@ -1,31 +1,47 @@
#!/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
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"
8 changes: 5 additions & 3 deletions src/gcloud-cli-persistence/NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
8 changes: 5 additions & 3 deletions src/gcloud-cli-persistence/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -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": {},
Expand All @@ -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"
}
26 changes: 21 additions & 5 deletions src/gcloud-cli-persistence/install.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 <<EOF >>"$_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"
11 changes: 4 additions & 7 deletions src/github-cli-persistence/NOTES.md
Original file line number Diff line number Diff line change
@@ -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 |
Expand Down
8 changes: 5 additions & 3 deletions src/github-cli-persistence/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -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": {},
Expand All @@ -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"
}
47 changes: 31 additions & 16 deletions src/github-cli-persistence/install.sh
Original file line number Diff line number Diff line change
@@ -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"
27 changes: 10 additions & 17 deletions src/lamdera/NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions src/lamdera/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -16,6 +16,7 @@
}
},
"installsAfter": [
"ghcr.io/devcontainers/features/common-utils"
"ghcr.io/devcontainers/features/common-utils",
"ghcr.io/meaningful-ooo/devcontainer-features/fish"
]
}
Loading