Skip to content

Commit

Permalink
πŸ§‘β€πŸ’» add devcontainer
Browse files Browse the repository at this point in the history
  • Loading branch information
QWp6t committed Oct 5, 2024
1 parent f3cd47c commit d893b04
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .devcontainer/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
APP_NAME=Laracord
APP_ENV=development

DISCORD_TOKEN=
2 changes: 2 additions & 0 deletions .devcontainer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
docker-compose.override.yml
.env
12 changes: 12 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM ghcr.io/laracord/egg:php8

USER root

RUN apk update \
&& apk add --no-cache --repository https://dl-cdn.alpinelinux.org/alpine/edge/testing watchexec ripgrep

USER vscode
ENV USER vscode
ENV HOME /home/vscode

WORKDIR /app
47 changes: 47 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "Bot",
"build": {
"dockerfile": "Dockerfile",
"context": "..",
"options": [
"--add-host=host.docker.internal:host-gateway"
]
},
"runArgs": [
"--privileged"
],
"features": {
"ghcr.io/devcontainers/features/common-utils:2": {
"installZsh": "true",
"username": "vscode",
"userUid": "1000",
"userGid": "1000",
"upgradePackages": "true"
}
},
"mounts": [
"source=${localEnv:HOME}/.ssh,target=/home/vscode/.ssh,type=,type=bind,readonly"
],
"overrideCommand": true,
"initializeCommand": "[ ! -f '.devcontainer/.env' ] && cp '.devcontainer/config/app/.env.example' '.devcontainer/.env' || true",
"onCreateCommand": "chmod +x /app/framework/.devcontainer/install.sh && /app/framework/.devcontainer/install.sh",
"forwardPorts": [],
"workspaceFolder": "/app",
"workspaceMount": "source=${localWorkspaceFolder},target=/app/framework,type=bind,consistency=cached",
"remoteUser": "vscode",
"customizations": {
"vscode": {
"extensions": [
"mikestead.dotenv",
"amiralizadeh9480.laravel-extra-intellisense",
"ryannaddy.laravel-artisan",
"onecentlin.laravel5-snippets",
"onecentlin.laravel-blade",
"bmewburn.vscode-intelephense-client"
],
"settings": {
"php.validate.executablePath": "/usr/local/bin/php"
}
}
}
}
67 changes: 67 additions & 0 deletions .devcontainer/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/bin/ash

set -eux

# Add a welcome message
echo 'πŸ‘‹ Welcome to Laracord Development πŸ€–' | sudo tee /usr/local/etc/vscode-dev-containers/first-run-notice.txt

# This is the default .env file used by the application
FALLBACK_APP_ENV_FILE="/app/framework/.devcontainer/.env.example";
APP_ENV_FILE="${FALLBACK_APP_ENV_FILE}";

# If .env file exists in the workspace, let's use that instead
if [ ! -z ${APP_ENV+x} ] && [ -f "/app/framework/.devcontainer/.env.${APP_ENV}" ]; then
APP_ENV_FILE="/app/framework/.devcontainer/.env.${APP_ENV}";
elif [ -f "/app/framework/.devcontainer/.env" ]; then
APP_ENV_FILE="/app/framework/.devcontainer/.env";
fi

. "${APP_ENV_FILE}";
# source our application env vars

REPOSITORY_URL="${REPOSITORY_URL:-"https://github.com/laracord/laracord.git"}"

sudo mkdir -p /app/laracord
sudo chown -R vscode:vscode /app/laracord
cd /app/laracord

# Install composer
curl -s https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
sudo chmod +x /usr/local/bin/composer

# if composer.json already exists, exit early
if [ -f "composer.json" ]; then
exit 0
fi

# Clone the repository
git clone --depth=1 ${REPOSITORY_URL} . \
&& rm -rf .git

# if composer.json does not exist, exit with error message
if [ ! -f "composer.json" ]; then
echo "composer.json not found in /app/laracord"
exit 1
fi

# copy .env file if APP_ENV_FILE is default, otherwise link .env file
[ "${APP_ENV_FILE}" = "${FALLBACK_APP_ENV_FILE}" ] \
&& cp "${APP_ENV_FILE}" /app/laracord/.env \
|| ln -fs "${APP_ENV_FILE}" /app/laracord/.env

cd /app/laracord

# Install Composer dependencies
composer -d /app/laracord install --no-progress --optimize-autoloader --prefer-dist --no-interaction

# Link the workspace folder
cat /app/laracord/composer.json | jq ".repositories += [{ type: \"path\", url: \"/app/framework\" }]" > /app/laracord/composer.tmp \
&& rm /app/laracord/composer.json \
&& mv /app/laracord/composer.tmp /app/laracord/composer.json \
&& composer require -d /app/laracord $(cat "/app/framework/composer.json" | jq '.name' | tr -d '"') --no-interaction -W

# Set filesystem permissions
sudo chown -R vscode:vscode /app/laracord
sudo find /app/laracord/ -type d -exec chmod g+s {} \;
sudo chmod g+w -R /app/laracord

0 comments on commit d893b04

Please sign in to comment.