Skip to content

Commit

Permalink
feat: Add installation scripts for Alpine user, PHP zip, PHP MySQL, a…
Browse files Browse the repository at this point in the history
…nd PHP Magento

This commit adds installation scripts for four new features in the Alpine devcontainer. The scripts activate the 'alpine-user', 'alpine-php-zip', 'alpine-php-mysql', and 'alpine-php-magento' features respectively. Each script installs the necessary dependencies and enables the corresponding PHP extensions.
  • Loading branch information
cirolosapio committed Apr 23, 2024
1 parent ae1cf25 commit 62d732c
Show file tree
Hide file tree
Showing 30 changed files with 241 additions and 58 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,14 @@
- [alpine-php-composer](https://github.com/cirolosapio/devcontainers-features/pkgs/container/devcontainers-features%2Falpine-php-composer)
- [alpine-php-gd](https://github.com/cirolosapio/devcontainers-features/pkgs/container/devcontainers-features%2Falpine-php-gd)
- [alpine-php-intl](https://github.com/cirolosapio/devcontainers-features/pkgs/container/devcontainers-features%2Falpine-php-intl)
- [alpine-php-magento](https://github.com/cirolosapio/devcontainers-features/pkgs/container/devcontainers-features%2Falpine-php-magento)
- [alpine-php-mssql](https://github.com/cirolosapio/devcontainers-features/pkgs/container/devcontainers-features%2Falpine-php-mssql)
- [alpine-php-mysql](https://github.com/cirolosapio/devcontainers-features/pkgs/container/devcontainers-features%2Falpine-php-mysql)
- [alpine-php-pcntl](https://github.com/cirolosapio/devcontainers-features/pkgs/container/devcontainers-features%2Falpine-php-pcntl)
- [alpine-php-pgsql](https://github.com/cirolosapio/devcontainers-features/pkgs/container/devcontainers-features%2Falpine-php-pgsql)
- [alpine-php-posix](https://github.com/cirolosapio/devcontainers-features/pkgs/container/devcontainers-features%2Falpine-php-posix)
- [alpine-php-xdebug](https://github.com/cirolosapio/devcontainers-features/pkgs/container/devcontainers-features%2Falpine-php-xdebug)
- [alpine-php-zip](https://github.com/cirolosapio/devcontainers-features/pkgs/container/devcontainers-features%2Falpine-php-zip)
- [alpine-phpstorm-libs](https://github.com/cirolosapio/devcontainers-features/pkgs/container/devcontainers-features%2Falpine-phpstorm-libs)
- [alpine-starship](https://github.com/cirolosapio/devcontainers-features/pkgs/container/devcontainers-features%2Falpine-starship)
- [alpine-user](https://github.com/cirolosapio/devcontainers-features/pkgs/container/devcontainers-features%2Falpine-user)
2 changes: 1 addition & 1 deletion src/alpine-bat/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "alpine-bat",
"id": "alpine-bat",
"version": "0.0.9",
"version": "0.0.10",
"description": "Installs bat on alpine",
"documentationURL": "https://github.com/cirolosapio/devcontainers-features/tree/main/src/alpine-bat",
"installsAfter": [
Expand Down
12 changes: 11 additions & 1 deletion src/alpine-bat/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,18 @@ echo "Activating feature 'alpine-bat'"
apk --no-cache add bat

if command -v zsh &> /dev/null; then
if [ -z "$_CONTAINER_USER_HOME" ]; then
CURRENT_USER=$(getent passwd 1000 | cut -d: -f1)

if [ -z "$CURRENT_USER" ]; then
_CONTAINER_USER_HOME=/root
else
_CONTAINER_USER_HOME=$(getent passwd $CURRENT_USER | cut -d: -f6)
fi
fi

apk --no-cache add bat-zsh-completion
echo "alias cat=bat" >> $_CONTAINER_USER_HOME/.zshrc
echo $'\nalias cat=bat' >> $_CONTAINER_USER_HOME/.zshrc
fi

echo 'Done!'
10 changes: 3 additions & 7 deletions src/alpine-docker-outside-of-docker/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
{
"name": "alpine-docker-outside-of-docker",
"id": "alpine-docker-outside-of-docker",
"version": "0.0.10",
"version": "0.0.11",
"description": "Re-use the host docker socket, adding the Docker CLI to alpine container",
"documentationURL": "https://github.com/cirolosapio/devcontainers-features/tree/main/src/alpine-docker-outside-of-docker",
"legacyIds": [
"alpine-docker"
],
"options": {
"hostDockerGid": {
"type": "string",
"default": "1001",
"description": "Docker group id on the host machine (retrieve with \"getent group docker \\| cut -d: -f3\"). Required if remote user is not root"
},
"installDockerCompose": {
"type": "boolean",
"default": false,
"description": "Install Docker Compose?"
}
},
"entrypoint": "/usr/local/share/docker-init.sh",
"mounts": [
{
"source": "/var/run/docker.sock",
"target": "/var/run/docker.sock",
"target": "/var/run/docker-host.sock",
"type": "bind"
}
],
Expand Down
44 changes: 31 additions & 13 deletions src/alpine-docker-outside-of-docker/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,45 @@ echo "Activating feature 'alpine-docker-outside-of-docker'"

apk add --no-cache docker

CURRENT_USER=$(awk -v val=1000 -F ":" '$3==val{print $1}' /etc/passwd)
echo "CURRENT_USER is $CURRENT_USER"
CURRENT_USER=$(getent passwd 1000 | cut -d: -f1)

if [[ -z $CURRENT_USER ]]; then
echo "CURRENT_USER is empty, using 'root'"
ln -s /var/run/docker-host.sock /var/run/docker.sock
echo -e '#!/bin/sh\nexec "$@"' > /usr/local/share/docker-init.sh
else
echo "HOST_DOCKER_GID is $HOSTDOCKERGID"
apk add --no-cache socat sudo
echo "$CURRENT_USER ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/$CURRENT_USER
chmod 0440 /etc/sudoers.d/$CURRENT_USER

HOST_DOCKER_GROUP=$(getent group $HOSTDOCKERGID | cut -d: -f1)
tee /usr/local/share/docker-init.sh > /dev/null \
<< EOF
#!/bin/sh
#-------------------------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
#-------------------------------------------------------------------------------------------------------------
set -e
if [[ -z $HOST_DOCKER_GROUP ]]; then
echo "HOST_DOCKER_GROUP is empty, creating new group 'host-docker'"
addgroup -g $HOSTDOCKERGID host-docker
HOST_DOCKER_GROUP=host-docker
else
echo "HOST_DOCKER_GROUP is already used, using existing group '$HOST_DOCKER_GROUP'"
fi
SOCAT_PATH_BASE=/tmp/vscr-docker-from-docker
SOCAT_PID=\${SOCAT_PATH_BASE}.pid
addgroup $CURRENT_USER $HOST_DOCKER_GROUP
if [ ! -f "\${SOCAT_PID}" ] || ! ps -p \$(cat \${SOCAT_PID}) > /dev/null; then
rm -rf /var/run/docker.sock
sudo socat UNIX-LISTEN:/var/run/docker.sock,fork,mode=660,user=$CURRENT_USER,backlog=128 UNIX-CONNECT:/var/run/docker-host.sock 2>&1
fi
# Execute whatever commands were passed in (if any). This allows us
# to set this script to ENTRYPOINT while still executing the default CMD.
set +e
exec "\$@"
EOF

chown ${CURRENT_USER}:root /usr/local/share/docker-init.sh
fi

chmod +x /usr/local/share/docker-init.sh

if [[ $INSTALLDOCKERCOMPOSE == "true" ]]; then
apk add --no-cache docker-compose
fi
Expand Down
2 changes: 1 addition & 1 deletion src/alpine-gh-copilot-cli/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "alpine-gh-copilot-cli",
"id": "alpine-gh-copilot-cli",
"version": "0.0.11",
"version": "0.0.12",
"description": "Installs Github Copilot CLI on alpine",
"documentationURL": "https://github.com/cirolosapio/devcontainers-features/tree/main/src/alpine-gh-copilot-cli",
"installsAfter": [
Expand Down
10 changes: 9 additions & 1 deletion src/alpine-gh-copilot-cli/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@ apk --no-cache add npm
npm i -g @githubnext/github-copilot-cli

if [[ $INITALIAS == "true" ]]; then
CURRENT_USER=$(awk -v val=1000 -F ":" '$3==val{print $1}' /etc/passwd)
CURRENT_USER=$(getent passwd 1000 | cut -d: -f1)

if [ -z "$_CONTAINER_USER_HOME" ]; then
if [ -z "$CURRENT_USER" ]; then
_CONTAINER_USER_HOME=/root
else
_CONTAINER_USER_HOME=$(getent passwd $CURRENT_USER | cut -d: -f6)
fi
fi

if [[ -z $CURRENT_USER ]]; then
echo 'eval "$(github-copilot-cli alias -- "$0")"' >> $_CONTAINER_USER_HOME/.zshrc
Expand Down
2 changes: 1 addition & 1 deletion src/alpine-magento-cloud-cli/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "alpine-magento-cloud-cli",
"id": "alpine-magento-cloud-cli",
"version": "0.0.3",
"version": "0.0.4",
"description": "Installs magento-cloud-cli on alpine",
"documentationURL": "https://github.com/cirolosapio/devcontainers-features/tree/main/src/alpine-magento-cloud-cli",
"installsAfter": [
Expand Down
20 changes: 14 additions & 6 deletions src/alpine-magento-cloud-cli/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,25 @@ echo "Activating feature 'alpine-magento-cloud-cli'"

apk --no-cache add curl git

CURRENT_USER=$(awk -v val=1000 -F ":" '$3==val{print $1}' /etc/passwd)
CURRENT_USER=$(getent passwd 1000 | cut -d: -f1)

if [ -z "$_CONTAINER_USER_HOME" ]; then
if [ -z "$CURRENT_USER" ]; then
_CONTAINER_USER_HOME=/root
else
_CONTAINER_USER_HOME=$(getent passwd $CURRENT_USER | cut -d: -f6)
fi
fi

CMD="cd $_CONTAINER_USER_HOME && curl -sS https://accounts.magento.cloud/cli/installer | php"

if [ "$SHELLTYPE" = "zsh" ]; then
apk --no-cache add zsh
sed -i "s|:/bin/ash|:/bin/zsh|g" /etc/passwd
CMD="$CMD -- --shell-type zsh"
apk --no-cache add zsh
sed -i "s|:/bin/ash|:/bin/zsh|g" /etc/passwd
CMD="$CMD -- --shell-type zsh"
else
apk --no-cache add bash
CMD="$CMD -- --shell-type bash"
apk --no-cache add bash
CMD="$CMD -- --shell-type bash"
fi

su -c "$CMD" $CURRENT_USER
Expand Down
2 changes: 1 addition & 1 deletion src/alpine-n98-magerun2/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "alpine-n98-magerun2",
"id": "alpine-n98-magerun2",
"version": "0.0.13",
"version": "0.0.14",
"description": "Installs n98-magerun2 on alpine",
"documentationURL": "https://github.com/cirolosapio/devcontainers-features/tree/main/src/alpine-n98-magerun2",
"legacyIds": [
Expand Down
10 changes: 10 additions & 0 deletions src/alpine-n98-magerun2/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ wget -q https://files.magerun.net/n98-magerun2-${VERSION}.phar -O /usr/local/bin
chmod +x /usr/local/bin/n98-magerun2.phar

if command -v zsh &> /dev/null; then
if [ -z "$_CONTAINER_USER_HOME" ]; then
CURRENT_USER=$(getent passwd 1000 | cut -d: -f1)

if [ -z "$CURRENT_USER" ]; then
_CONTAINER_USER_HOME=/root
else
_CONTAINER_USER_HOME=$(getent passwd $CURRENT_USER | cut -d: -f6)
fi
fi

# ZSH PLUGIN
mkdir -p $_CONTAINER_USER_HOME/.oh-my-zsh/custom/plugins/n98-magerun2/
wget -q https://raw.githubusercontent.com/netz98/n98-magerun2/develop/res/autocompletion/zsh/n98-magerun2.plugin.zsh -O $_CONTAINER_USER_HOME/.oh-my-zsh/custom/plugins/n98-magerun2/n98-magerun2.plugin.zsh
Expand Down
2 changes: 1 addition & 1 deletion src/alpine-navi/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "alpine-navi",
"id": "alpine-navi",
"version": "0.0.8",
"version": "0.0.9",
"description": "Installs navi on alpine",
"documentationURL": "https://github.com/cirolosapio/devcontainers-features/tree/main/src/alpine-navi",
"installsAfter": [
Expand Down
10 changes: 10 additions & 0 deletions src/alpine-navi/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ echo "Activating feature 'alpine-navi'"
apk --no-cache add skim navi

if command -v zsh &> /dev/null; then
if [ -z "$_CONTAINER_USER_HOME" ]; then
CURRENT_USER=$(getent passwd 1000 | cut -d: -f1)

if [ -z "$CURRENT_USER" ]; then
_CONTAINER_USER_HOME=/root
else
_CONTAINER_USER_HOME=$(getent passwd $CURRENT_USER | cut -d: -f6)
fi
fi

echo $'\neval "$(navi widget zsh)"' >> $_CONTAINER_USER_HOME/.zshrc
fi

Expand Down
2 changes: 1 addition & 1 deletion src/alpine-node/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "alpine-node",
"id": "alpine-node",
"version": "0.0.9",
"version": "0.0.10",
"description": "Installs node and npm on alpine",
"documentationURL": "https://github.com/cirolosapio/devcontainers-features/tree/main/src/alpine-node",
"options": {
Expand Down
2 changes: 1 addition & 1 deletion src/alpine-node/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ if [[ $COREPACK == "true" ]]; then
npm i -g corepack

if [[ $PNPMVERSION != "latest" ]]; then
CURRENT_USER=$(awk -v val=1000 -F ":" '$3==val{print $1}' /etc/passwd)
CURRENT_USER=$(getent passwd 1000 | cut -d: -f1)
su -c "corepack prepare pnpm@$PNPMVERSION --activate" $CURRENT_USER
fi
fi
Expand Down
11 changes: 2 additions & 9 deletions src/alpine-nushell/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
{
"name": "alpine-nushell",
"id": "alpine-nushell",
"version": "0.0.8",
"version": "0.0.9",
"description": "Installs nushell on alpine",
"documentationURL": "https://github.com/cirolosapio/devcontainers-features/tree/main/src/alpine-nushell",
"installsAfter": [
"ghcr.io/cirolosapio/devcontainers-features/alpine-starship"
],
"options": {
"initStarship": {
"type": "boolean",
"default": true,
"description": "Init starship"
}
}
]
}
12 changes: 11 additions & 1 deletion src/alpine-nushell/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,21 @@ echo "Activating feature 'alpine-nushell'"

apk --no-cache add nushell --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing

if [ -z "$_CONTAINER_USER_HOME" ]; then
CURRENT_USER=$(getent passwd 1000 | cut -d: -f1)

if [ -z "$CURRENT_USER" ]; then
_CONTAINER_USER_HOME=/root
else
_CONTAINER_USER_HOME=$(getent passwd $CURRENT_USER | cut -d: -f6)
fi
fi

mkdir -p $_CONTAINER_USER_HOME/.config/nushell/
wget -q https://raw.githubusercontent.com/nushell/nushell/main/crates/nu-utils/src/sample_config/default_config.nu -O $_CONTAINER_USER_HOME/.config/nushell/config.nu
wget -q https://raw.githubusercontent.com/nushell/nushell/main/crates/nu-utils/src/sample_config/default_env.nu -O $_CONTAINER_USER_HOME/.config/nushell/env.nu

if [[ $INITSTARSHIP == "true" ]]; then
if command -v starship &> /dev/null; then
echo $'\nmkdir ~/.cache/starship\nstarship init nu | save -f ~/.cache/starship/init.nu' >> $_CONTAINER_USER_HOME/.config/nushell/env.nu
echo $'\nuse ~/.cache/starship/init.nu' >> $_CONTAINER_USER_HOME/.config/nushell/config.nu
fi
Expand Down
9 changes: 2 additions & 7 deletions src/alpine-ohmyzsh/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "alpine-ohmyzsh",
"id": "alpine-ohmyzsh",
"version": "0.0.17",
"version": "0.0.18",
"description": "Installs ohmyzsh on alpine",
"documentationURL": "https://github.com/cirolosapio/devcontainers-features/tree/main/src/alpine-ohmyzsh",
"installsAfter": [
Expand All @@ -10,13 +10,8 @@
"options": {
"plugins": {
"type": "string",
"default": "alias-tips",
"default": "git alias-tips",
"description": "OhMyZsh plugins to enable (git zsh-autosuggestions zsh-syntax-highlighting are always installed)"
},
"initStarship": {
"type": "boolean",
"default": true,
"description": "Init starship"
}
}
}
15 changes: 12 additions & 3 deletions src/alpine-ohmyzsh/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,21 @@ echo "Activating feature 'alpine-ohmyzsh'"

apk --no-cache add git zsh

CURRENT_USER=$(awk -v val=1000 -F ":" '$3==val{print $1}' /etc/passwd)
CURRENT_USER=$(getent passwd 1000 | cut -d: -f1)

if [ -z "$_CONTAINER_USER_HOME" ]; then
if [ -z "$CURRENT_USER" ]; then
_CONTAINER_USER_HOME=/root
else
_CONTAINER_USER_HOME=$(getent passwd $CURRENT_USER | cut -d: -f6)
fi
fi

su -c "wget -qO- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh | sh -s" $CURRENT_USER

git clone https://github.com/zsh-users/zsh-autosuggestions $_CONTAINER_USER_HOME/.oh-my-zsh/custom/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-syntax-highlighting $_CONTAINER_USER_HOME/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting
sed -i 's/plugins=(git)/plugins=(\n git\n zsh-autosuggestions\n zsh-syntax-highlighting\n)/' $_CONTAINER_USER_HOME/.zshrc
sed -i 's/plugins=(git)/plugins=(\n zsh-autosuggestions\n zsh-syntax-highlighting\n)/' $_CONTAINER_USER_HOME/.zshrc

if echo "$PLUGINS" | grep -w -q "autojump"; then
git clone https://github.com/wting/autojump $_CONTAINER_USER_HOME/.oh-my-zsh/custom/plugins/autojump
Expand All @@ -34,7 +43,7 @@ for plugin in $PLUGINS; do
sed -i "s/^plugins=(/plugins=(\n $plugin/g" $_CONTAINER_USER_HOME/.zshrc
done

if [[ $INITSTARSHIP == "true" ]]; then
if command -v starship > /dev/null; then
echo $'\neval "$(starship init zsh)"' >> $_CONTAINER_USER_HOME/.zshrc
fi

Expand Down
6 changes: 3 additions & 3 deletions src/alpine-php-composer/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"name": "alpine-php-composer",
"id": "alpine-php-composer",
"version": "0.0.2",
"version": "0.0.3",
"description": "Installs php composer on alpine",
"documentationURL": "https://github.com/cirolosapio/devcontainers-features/tree/main/src/alpine-php-composer",
"options": {
"version": {
"type": "string",
"default": "2.7.2",
"default": "2.7.4",
"description": "Version of composer to install",
"proposals": [
"2.7.2",
"2.7.4",
"2.6.6"
]
}
Expand Down
Loading

0 comments on commit 62d732c

Please sign in to comment.