Skip to content

Commit

Permalink
feat: ✨ add devcontainer files
Browse files Browse the repository at this point in the history
  • Loading branch information
tomgrv committed Sep 16, 2024
1 parent b7efc20 commit b74dfa6
Show file tree
Hide file tree
Showing 7 changed files with 305 additions and 16 deletions.
19 changes: 19 additions & 0 deletions .devcontainer/create.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh

### Ensure correct access rights
sudo chown -Rf vscode ${containerWorkspaceFolder:-.}/* ${containerWorkspaceFolder:-.}/.*
sudo chmod -Rf 755 ${containerWorkspaceFolder:-.}/* ${containerWorkspaceFolder:-.}/.*

#### Create aliases
sudo cat <<EOF > ~/.bash_aliases
alias part='php artisan'
alias sart='sail artisan'
alias snpm='sail npm'
alias snpx='sail npx --yes'
alias spm2='sail npx --yes pm2'
alias smix='spm2 restart MixWatch'
alias smiw='spm2 --name MixWatch start npm -- run watch'
alias gitv='gitversion'
alias sail='sh $([ -f sail ] && echo sail || echo vendor/bin/sail)'
EOF

99 changes: 86 additions & 13 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,98 @@
{
"image": "mcr.microsoft.com/devcontainers/javascript-node:1-20-bookworm",
"name": "Perspikapps/DevContainer",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/base:jammy",
// Features to add to the dev container. More info: https://containers.dev/features.
"features": {
"ghcr.io/devcontainers/features/node": "lts",
"ghcr.io/devcontainers/features/php": "lts",
"ghcr.io/devcontainers/features/docker-in-docker:2": "lts",
"ghcr.io/tomgrv/devcontainer-features/gitutils:1": {},
"ghcr.io/tomgrv/devcontainer-features/githooks:1": {}
},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "sh .devcontainer/create.sh",
// Configure tool-specific properties.
"customizations": {
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {
"json.schemas": [
{
"fileMatch": ["*/devcontainer-feature.json"],
"url": "https://raw.githubusercontent.com/devcontainers/spec/main/schemas/devContainerFeature.schema.json"
}
"triggerTaskOnSave.tasks": {
"php-refresh-config": [
"**/config.php",
"config/*.php",
".env"
],
"php-refresh-views": [
//"packages/**/*.blade.php"
],
"php-refresh-routes": ["**/[Rr]outes/*.php"],
"php-refresh-db": [
// "**/migrations/*.php"
]
},
"editor.formatOnSave": true,
"editor.formatOnPaste": true,
"todo-tree.general.tags": [
"BUG",
"HACK",
"FIXME",
"TODO",
"XXX",
"[ ]",
"[x]",
"NOTE"
],
"conventionalCommits.gitmoji": false,
"explorer.excludeGitIgnore": true
},
"extensions": [
"mads-hartmann.bash-ide-vscode",
"mhutchie.git-graph"
"vivaxy.vscode-conventional-commits",
"actboy168.tasks",
"spmeesseman.vscode-taskexplorer",
"gruntfuggly.triggertaskonsave",
"entexa.tall-stack",
"github.codespaces",
"natizyskunk.sftp",
"formulahendry.auto-rename-tag",
"formulahendry.auto-close-tag",
"absszero.vscode-laravel-goto",
"marabesi.php-import-checker",
"alexcvzz.vscode-sqlite",
"bmewburn.vscode-intelephense-client",
"gruntfuggly.todo-tree",
"onecentlin.laravel-blade",
"github.copilot",
"github.copilot-chat",
"donjayamanne.githistory",
"xdebug.php-debug",
"tomblind.scm-buttons-vscode",
"misterj.laravel-expack",
"devsense.composer-php-vscode",
"mhutchie.git-graph",
"christian-kohler.npm-intellisense",
"davidanson.vscode-markdownlint",
"github.vscode-github-actions",
"pcbowers.alpine-intellisense",
"softwareape.rebaser",
"arturock.gitstash"
]
}
},
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
"ghcr.io/tomgrv/devcontainer-features/gitutils": {},
"ghcr.io/tomgrv/devcontainer-features/githooks": {}
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
// Define env vars to set in the container.
"remoteEnv": {
"APP_DEBUG": "true",
"APP_ENV": "local",
"APP_PORT": "80",
"LARAVEL_SAIL": "1",
"SAIL_XDEBUG_MODE": "develop,debug",
"SAIL_XDEBUG_CONFIG": "client_host=host.docker.internal idekey=vscode",
"XDEBUG_MODE": "off"
},
"updateContentCommand": "npm install -g @devcontainers/cli"
// Ensure the container is correctly configured for the workspace.
"postStartCommand": "sh .devcontainer/start.sh"
}
36 changes: 36 additions & 0 deletions .devcontainer/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/sh

### Make sure the workspace folder is owned by the user
git config --global --add safe.directory ${containerWorkspaceFolder:-.}

### Install composer dependencies if composer.json exists
if [ -f ${containerWorkspaceFolder:-.}/composer.json ]; then
composer install --ignore-platform-reqs --no-interaction --no-progress
fi

### Install npm dependencies if package.json exists
if [ -f ${containerWorkspaceFolder:-.}/package.json ]; then
npm install --ws --if-present --include-workspace-root
fi

### Init laravel
if [ -f ${containerWorkspaceFolder:-.}/vendor/bin/sail ] && [ "${LARAVEL_SAIL}" -eq "1" ]; then

${containerWorkspaceFolder:-.}/vendor/bin/sail up --build -d
${containerWorkspaceFolder:-.}/vendor/bin/sail artisan key:generate --force
${containerWorkspaceFolder:-.}/vendor/bin/sail artisan config:cache
${containerWorkspaceFolder:-.}/vendor/bin/sail artisan view:cache
${containerWorkspaceFolder:-.}/vendor/bin/sail artisan route:cache
${containerWorkspaceFolder:-.}/vendor/bin/sail artisan migrate --seed
${containerWorkspaceFolder:-.}/vendor/bin/sail npx --yes pm2 --name MixWatch start npm -- run watch

elif [ -f ${containerWorkspaceFolder:-.}/artisan ]; then
touch $DB_DATABASE
echo APP_KEY=null > .env
php -d xdebug.mode=off artisan key:generate --force
php -d xdebug.mode=off artisan config:cache
php -d xdebug.mode=off artisan view:cache
php -d xdebug.mode=off artisan route:cache
php -d xdebug.mode=off artisan migrate --seed
npx --yes pm2 --name MixWatch start npm -- run watch
fi
14 changes: 11 additions & 3 deletions local-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if [ -n "$1" ]; then
echo "Usage: $0 [--help|--stubs|--all|<features>]"
exit
;;
--all)
--all|--start)
echo "All selected" | npx --yes chalk-cli --stdin green
stubs=1
features=$(jq -r '.config.local[]' package.json)
Expand Down Expand Up @@ -53,7 +53,10 @@ if [ "$stubs" -eq "1" ]; then

### Merge file
echo "Merge $folder/$(basename $file)" | npx --yes chalk-cli --stdin yellow
git merge-file -p $file $folder/$(basename $file) ${folder#./}/$(basename $file) >$folder/$(basename $file)
git merge-file -p $file $folder/$(basename $file) ${folder#./}/$(basename $file) > $folder/$(basename $file)

### Apply rights
chmod $(stat -c "%a" $file) $folder/$(basename $file)
done

### Find all file with a trailing slash outside dist folder, make sure they are added to .gitignore and remove the trailing slash
Expand Down Expand Up @@ -115,4 +118,9 @@ git diff -w --no-color | git apply --cached --ignore-whitespace --allow-empty
git checkout -- . && git reset && git add .

### Unstash changes
test -n "$stash" && git stash apply && git stash drop
test -n "$stash" && git stash apply && git stash drop

### Start script
if [ "$1" = "--start" ]; then
./.devcontainer/start.sh
fi
19 changes: 19 additions & 0 deletions stubs/.devcontainer/create.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh

### Ensure correct access rights
sudo chown -Rf vscode ${containerWorkspaceFolder:-.}/* ${containerWorkspaceFolder:-.}/.*
sudo chmod -Rf 755 ${containerWorkspaceFolder:-.}/* ${containerWorkspaceFolder:-.}/.*

#### Create aliases
sudo cat <<EOF > ~/.bash_aliases
alias part='php artisan'
alias sart='sail artisan'
alias snpm='sail npm'
alias snpx='sail npx --yes'
alias spm2='sail npx --yes pm2'
alias smix='spm2 restart MixWatch'
alias smiw='spm2 --name MixWatch start npm -- run watch'
alias gitv='gitversion'
alias sail='sh $([ -f sail ] && echo sail || echo vendor/bin/sail)'
EOF

98 changes: 98 additions & 0 deletions stubs/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{
"name": "Perspikapps/DevContainer",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/base:jammy",
// Features to add to the dev container. More info: https://containers.dev/features.
"features": {
"ghcr.io/devcontainers/features/node": "lts",
"ghcr.io/devcontainers/features/php": "lts",
"ghcr.io/devcontainers/features/docker-in-docker:2": "lts",
"ghcr.io/tomgrv/devcontainer-features/gitutils:1": {},
"ghcr.io/tomgrv/devcontainer-features/githooks:1": {}
},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "sh .devcontainer/create.sh",
// Configure tool-specific properties.
"customizations": {
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {
"triggerTaskOnSave.tasks": {
"php-refresh-config": [
"**/config.php",
"config/*.php",
".env"
],
"php-refresh-views": [
//"packages/**/*.blade.php"
],
"php-refresh-routes": ["**/[Rr]outes/*.php"],
"php-refresh-db": [
// "**/migrations/*.php"
]
},
"editor.formatOnSave": true,
"editor.formatOnPaste": true,
"todo-tree.general.tags": [
"BUG",
"HACK",
"FIXME",
"TODO",
"XXX",
"[ ]",
"[x]",
"NOTE"
],
"conventionalCommits.gitmoji": false,
"explorer.excludeGitIgnore": true
},
"extensions": [
"vivaxy.vscode-conventional-commits",
"actboy168.tasks",
"spmeesseman.vscode-taskexplorer",
"gruntfuggly.triggertaskonsave",
"entexa.tall-stack",
"github.codespaces",
"natizyskunk.sftp",
"formulahendry.auto-rename-tag",
"formulahendry.auto-close-tag",
"absszero.vscode-laravel-goto",
"marabesi.php-import-checker",
"alexcvzz.vscode-sqlite",
"bmewburn.vscode-intelephense-client",
"gruntfuggly.todo-tree",
"onecentlin.laravel-blade",
"github.copilot",
"github.copilot-chat",
"donjayamanne.githistory",
"xdebug.php-debug",
"tomblind.scm-buttons-vscode",
"misterj.laravel-expack",
"devsense.composer-php-vscode",
"mhutchie.git-graph",
"christian-kohler.npm-intellisense",
"davidanson.vscode-markdownlint",
"github.vscode-github-actions",
"pcbowers.alpine-intellisense",
"softwareape.rebaser",
"arturock.gitstash"
]
}
},
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
// Define env vars to set in the container.
"remoteEnv": {
"APP_DEBUG": "true",
"APP_ENV": "local",
"APP_PORT": "80",
"LARAVEL_SAIL": "1",
"SAIL_XDEBUG_MODE": "develop,debug",
"SAIL_XDEBUG_CONFIG": "client_host=host.docker.internal idekey=vscode",
"XDEBUG_MODE": "off"
},
// Ensure the container is correctly configured for the workspace.
"postStartCommand": "sh .devcontainer/start.sh"
}
36 changes: 36 additions & 0 deletions stubs/.devcontainer/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/sh

### Make sure the workspace folder is owned by the user
git config --global --add safe.directory ${containerWorkspaceFolder:-.}

### Install composer dependencies if composer.json exists
if [ -f ${containerWorkspaceFolder:-.}/composer.json ]; then
composer install --ignore-platform-reqs --no-interaction --no-progress
fi

### Install npm dependencies if package.json exists
if [ -f ${containerWorkspaceFolder:-.}/package.json ]; then
npm install --ws --if-present --include-workspace-root
fi

### Init laravel
if [ -f ${containerWorkspaceFolder:-.}/vendor/bin/sail ] && [ "${LARAVEL_SAIL}" -eq "1" ]; then

${containerWorkspaceFolder:-.}/vendor/bin/sail up --build -d
${containerWorkspaceFolder:-.}/vendor/bin/sail artisan key:generate --force
${containerWorkspaceFolder:-.}/vendor/bin/sail artisan config:cache
${containerWorkspaceFolder:-.}/vendor/bin/sail artisan view:cache
${containerWorkspaceFolder:-.}/vendor/bin/sail artisan route:cache
${containerWorkspaceFolder:-.}/vendor/bin/sail artisan migrate --seed
${containerWorkspaceFolder:-.}/vendor/bin/sail npx --yes pm2 --name MixWatch start npm -- run watch

elif [ -f ${containerWorkspaceFolder:-.}/artisan ]; then
touch $DB_DATABASE
echo APP_KEY=null > .env
php -d xdebug.mode=off artisan key:generate --force
php -d xdebug.mode=off artisan config:cache
php -d xdebug.mode=off artisan view:cache
php -d xdebug.mode=off artisan route:cache
php -d xdebug.mode=off artisan migrate --seed
npx --yes pm2 --name MixWatch start npm -- run watch
fi

0 comments on commit b74dfa6

Please sign in to comment.