From d893b047cf214a3cc3bd03f5dbbbca8c0c206aaf Mon Sep 17 00:00:00 2001 From: QWp6t Date: Mon, 24 Jun 2024 01:25:19 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB=20=20add=20de?= =?UTF-8?q?vcontainer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .devcontainer/.env.example | 4 ++ .devcontainer/.gitignore | 2 + .devcontainer/Dockerfile | 12 ++++++ .devcontainer/devcontainer.json | 47 +++++++++++++++++++++++ .devcontainer/install.sh | 67 +++++++++++++++++++++++++++++++++ 5 files changed, 132 insertions(+) create mode 100644 .devcontainer/.env.example create mode 100644 .devcontainer/.gitignore create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json create mode 100755 .devcontainer/install.sh diff --git a/.devcontainer/.env.example b/.devcontainer/.env.example new file mode 100644 index 0000000..e3ea499 --- /dev/null +++ b/.devcontainer/.env.example @@ -0,0 +1,4 @@ +APP_NAME=Laracord +APP_ENV=development + +DISCORD_TOKEN= diff --git a/.devcontainer/.gitignore b/.devcontainer/.gitignore new file mode 100644 index 0000000..215d7c8 --- /dev/null +++ b/.devcontainer/.gitignore @@ -0,0 +1,2 @@ +docker-compose.override.yml +.env diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..3160fbc --- /dev/null +++ b/.devcontainer/Dockerfile @@ -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 diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..6a1e780 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -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" + } + } + } +} diff --git a/.devcontainer/install.sh b/.devcontainer/install.sh new file mode 100755 index 0000000..d807b1c --- /dev/null +++ b/.devcontainer/install.sh @@ -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