mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-01-13 15:07:49 +00:00
feat: add .devcontainer support
This commit is contained in:
parent
ce443de76c
commit
e2a2c8a21c
9 changed files with 307 additions and 0 deletions
70
.devcontainer/.env.example
Normal file
70
.devcontainer/.env.example
Normal file
|
|
@ -0,0 +1,70 @@
|
||||||
|
APP_NAME=TrmnlServer
|
||||||
|
APP_ENV=local
|
||||||
|
APP_KEY=base64:zzPXBQPlgn0NHwVBTVG0B//8P/PVwVnBp2gk0ZWR0+k=
|
||||||
|
APP_DEBUG=true
|
||||||
|
APP_TIMEZONE=UTC
|
||||||
|
APP_URL=http://localhost
|
||||||
|
|
||||||
|
APP_LOCALE=en
|
||||||
|
APP_FALLBACK_LOCALE=en
|
||||||
|
APP_FAKER_LOCALE=en_US
|
||||||
|
|
||||||
|
APP_MAINTENANCE_DRIVER=file
|
||||||
|
# APP_MAINTENANCE_STORE=database
|
||||||
|
|
||||||
|
PHP_CLI_SERVER_WORKERS=4
|
||||||
|
|
||||||
|
BCRYPT_ROUNDS=12
|
||||||
|
|
||||||
|
LOG_CHANNEL=stack
|
||||||
|
LOG_STACK=single,stderr,stdout
|
||||||
|
LOG_DEPRECATIONS_CHANNEL=null
|
||||||
|
LOG_LEVEL=debug
|
||||||
|
|
||||||
|
DB_CONNECTION=sqlite
|
||||||
|
# DB_HOST=127.0.0.1
|
||||||
|
# DB_PORT=3306
|
||||||
|
# DB_DATABASE=laravel
|
||||||
|
# DB_USERNAME=root
|
||||||
|
# DB_PASSWORD=
|
||||||
|
|
||||||
|
SESSION_DRIVER=database
|
||||||
|
SESSION_LIFETIME=120
|
||||||
|
SESSION_ENCRYPT=false
|
||||||
|
SESSION_PATH=/
|
||||||
|
SESSION_DOMAIN=null
|
||||||
|
|
||||||
|
BROADCAST_CONNECTION=log
|
||||||
|
FILESYSTEM_DISK=local
|
||||||
|
QUEUE_CONNECTION=database
|
||||||
|
|
||||||
|
CACHE_STORE=database
|
||||||
|
CACHE_PREFIX=
|
||||||
|
|
||||||
|
MEMCACHED_HOST=127.0.0.1
|
||||||
|
|
||||||
|
REDIS_CLIENT=phpredis
|
||||||
|
REDIS_HOST=127.0.0.1
|
||||||
|
REDIS_PASSWORD=null
|
||||||
|
REDIS_PORT=6379
|
||||||
|
|
||||||
|
MAIL_MAILER=log
|
||||||
|
MAIL_SCHEME=null
|
||||||
|
MAIL_HOST=127.0.0.1
|
||||||
|
MAIL_PORT=2525
|
||||||
|
MAIL_USERNAME=null
|
||||||
|
MAIL_PASSWORD=null
|
||||||
|
MAIL_FROM_ADDRESS="hello@example.com"
|
||||||
|
MAIL_FROM_NAME="${APP_NAME}"
|
||||||
|
|
||||||
|
AWS_ACCESS_KEY_ID=
|
||||||
|
AWS_SECRET_ACCESS_KEY=
|
||||||
|
AWS_DEFAULT_REGION=us-east-1
|
||||||
|
AWS_BUCKET=
|
||||||
|
AWS_USE_PATH_STYLE_ENDPOINT=false
|
||||||
|
|
||||||
|
VITE_APP_NAME="${APP_NAME}"
|
||||||
|
|
||||||
|
TRMNL_PROXY_BASE_URL=https://trmnl.app
|
||||||
|
TRMNL_PROXY_REFRESH_MINUTES=15
|
||||||
|
REGISTRATION_ENABLED=1
|
||||||
36
.devcontainer/cli/Dockerfile
Normal file
36
.devcontainer/cli/Dockerfile
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
# From official php image.
|
||||||
|
FROM php:8.3-cli-alpine
|
||||||
|
# Create a user group and account under id 1000.
|
||||||
|
RUN addgroup -g 1000 -S user && adduser -u 1000 -D user -G user
|
||||||
|
# Install quality-of-life packages.
|
||||||
|
RUN apk add --no-cache bash curl git vim
|
||||||
|
# Install composer for php deps.
|
||||||
|
RUN apk add --no-cache composer
|
||||||
|
# Add Chromium and Image Magick for puppeteer.
|
||||||
|
RUN apk add --no-cache \
|
||||||
|
imagemagick-dev \
|
||||||
|
chromium
|
||||||
|
|
||||||
|
ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium
|
||||||
|
ENV PUPPETEER_DOCKER=1
|
||||||
|
|
||||||
|
RUN mkdir -p /usr/src/php/ext/imagick
|
||||||
|
RUN chmod 777 /usr/src/php/ext/imagick
|
||||||
|
RUN curl -fsSL https://github.com/Imagick/imagick/archive/refs/tags/3.7.0.tar.gz | tar xvz -C "/usr/src/php/ext/imagick" --strip 1
|
||||||
|
|
||||||
|
# Install PHP extensions
|
||||||
|
RUN docker-php-ext-install imagick
|
||||||
|
|
||||||
|
# Composer uses its php binary, but we want it to use the container's one
|
||||||
|
RUN rm -f /usr/bin/php83
|
||||||
|
RUN ln -s /usr/local/bin/php /usr/bin/php83
|
||||||
|
# Install postgres pdo driver.
|
||||||
|
# RUN apk add --no-cache postgresql-dev && docker-php-ext-install pdo_pgsql
|
||||||
|
# Install redis driver.
|
||||||
|
# RUN mkdir -p /usr/src/php/ext/redis; \
|
||||||
|
# curl -fsSL --ipv4 https://github.com/phpredis/phpredis/archive/6.0.2.tar.gz | tar xvz -C "/usr/src/php/ext/redis" --strip 1; \
|
||||||
|
# docker-php-ext-install redis
|
||||||
|
# Install nodejs and npm for frontend.
|
||||||
|
RUN apk add --no-cache nodejs npm
|
||||||
|
# Prevent container from exiting early.
|
||||||
|
CMD ["sleep", "infinity"]
|
||||||
21
.devcontainer/devcontainer.json
Normal file
21
.devcontainer/devcontainer.json
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
{
|
||||||
|
"name": "LaravelServer",
|
||||||
|
"service": "cli",
|
||||||
|
"remoteUser": "user",
|
||||||
|
"shutdownAction": "stopCompose",
|
||||||
|
"workspaceFolder": "/workspaces/laravel",
|
||||||
|
"dockerComposeFile": "docker-compose.yaml",
|
||||||
|
"forwardPorts": [ "nginx:80" ],
|
||||||
|
"customizations": {
|
||||||
|
"vscode": {
|
||||||
|
"extensions": [
|
||||||
|
"bmewburn.vscode-intelephense-client",
|
||||||
|
"eamodio.gitlens",
|
||||||
|
"EditorConfig.EditorConfig",
|
||||||
|
"mikestead.dotenv",
|
||||||
|
"onecentlin.laravel-blade",
|
||||||
|
"laravel.vscode-laravel"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
21
.devcontainer/docker-compose.yaml
Normal file
21
.devcontainer/docker-compose.yaml
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
version: "3.9"
|
||||||
|
services:
|
||||||
|
cli:
|
||||||
|
build: cli
|
||||||
|
volumes:
|
||||||
|
- ..:/workspaces/laravel
|
||||||
|
|
||||||
|
fpm:
|
||||||
|
build: fpm
|
||||||
|
volumes:
|
||||||
|
- ..:/workspaces/laravel
|
||||||
|
user: 1000:1000
|
||||||
|
|
||||||
|
nginx:
|
||||||
|
build: nginx
|
||||||
|
volumes:
|
||||||
|
- ..:/workspaces/laravel
|
||||||
|
ports:
|
||||||
|
- 8080:80
|
||||||
|
depends_on:
|
||||||
|
- fpm
|
||||||
30
.devcontainer/fpm/Dockerfile
Normal file
30
.devcontainer/fpm/Dockerfile
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
# From official php image.
|
||||||
|
FROM php:8.3-fpm-alpine
|
||||||
|
RUN addgroup -g 1000 -S user && adduser -u 1000 -D user -G user
|
||||||
|
# Install postgres pdo driver.
|
||||||
|
# RUN apk add --no-cache postgresql-dev && docker-php-ext-install pdo_pgsql
|
||||||
|
# Install redis driver.
|
||||||
|
# RUN mkdir -p /usr/src/php/ext/redis; \
|
||||||
|
# curl -fsSL --ipv4 https://github.com/phpredis/phpredis/archive/6.0.2.tar.gz | tar xvz -C "/usr/src/php/ext/redis" --strip 1; \
|
||||||
|
# docker-php-ext-install redis
|
||||||
|
|
||||||
|
RUN apk add --no-cache \
|
||||||
|
curl \
|
||||||
|
git \
|
||||||
|
nodejs \
|
||||||
|
npm \
|
||||||
|
imagemagick-dev \
|
||||||
|
chromium
|
||||||
|
|
||||||
|
ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium
|
||||||
|
ENV PUPPETEER_DOCKER=1
|
||||||
|
|
||||||
|
RUN mkdir -p /usr/src/php/ext/imagick
|
||||||
|
RUN chmod 777 /usr/src/php/ext/imagick
|
||||||
|
RUN curl -fsSL https://github.com/Imagick/imagick/archive/refs/tags/3.7.0.tar.gz | tar xvz -C "/usr/src/php/ext/imagick" --strip 1
|
||||||
|
|
||||||
|
# Install PHP extensions
|
||||||
|
RUN docker-php-ext-install imagick
|
||||||
|
|
||||||
|
RUN rm -f /usr/bin/php83
|
||||||
|
RUN ln -s /usr/local/bin/php /usr/bin/php83
|
||||||
21
.devcontainer/license.md
Normal file
21
.devcontainer/license.md
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2021 Theodore Messinezis
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
2
.devcontainer/nginx/Dockerfile
Normal file
2
.devcontainer/nginx/Dockerfile
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
FROM nginx:1.27-alpine
|
||||||
|
COPY default.conf /etc/nginx/conf.d/default.conf
|
||||||
35
.devcontainer/nginx/default.conf
Normal file
35
.devcontainer/nginx/default.conf
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
server_name localhost;
|
||||||
|
root /workspaces/laravel/public;
|
||||||
|
|
||||||
|
add_header X-Frame-Options "SAMEORIGIN";
|
||||||
|
add_header X-Content-Type-Options "nosniff";
|
||||||
|
|
||||||
|
index index.php;
|
||||||
|
|
||||||
|
charset utf-8;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
try_files $uri $uri/ /index.php?$query_string;
|
||||||
|
}
|
||||||
|
|
||||||
|
location = /favicon.ico { access_log off; log_not_found off; }
|
||||||
|
location = /robots.txt { access_log off; log_not_found off; }
|
||||||
|
|
||||||
|
error_page 404 /index.php;
|
||||||
|
|
||||||
|
location ~ \.php$ {
|
||||||
|
fastcgi_pass fpm:9000;
|
||||||
|
fastcgi_index index.php;
|
||||||
|
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
|
||||||
|
fastcgi_param PHP_VALUE "error_log=/var/log/nginx/php_errors.log";
|
||||||
|
fastcgi_buffers 16 16k;
|
||||||
|
fastcgi_buffer_size 32k;
|
||||||
|
include fastcgi_params;
|
||||||
|
}
|
||||||
|
|
||||||
|
location ~ /\.(?!well-known).* {
|
||||||
|
deny all;
|
||||||
|
}
|
||||||
|
}
|
||||||
71
.devcontainer/readme.md
Normal file
71
.devcontainer/readme.md
Normal file
|
|
@ -0,0 +1,71 @@
|
||||||
|
### Laravel Development Containers for Visual Studio Code
|
||||||
|
|
||||||
|
`laravel-devcontainer` is a simple configuration to support fully-dockerised development of Laravel applications using Visual Studio Code.
|
||||||
|
Unlike Laravel Sail, `laravel-devcontainer` has been built so that the entire development experience is dockerised. The only requirements are:
|
||||||
|
|
||||||
|
- [Visual Studio Code](https://code.visualstudio.com/)
|
||||||
|
- [Visual Studio Code Remote Containers Extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers)
|
||||||
|
- [Docker](https://docs.docker.com/get-docker/)
|
||||||
|
- [Docker Compose](https://docs.docker.com/compose/install/)
|
||||||
|
|
||||||
|
Visual Studio Code will actually run inside a Docker container with php-cli as well as other development tools.
|
||||||
|
Any Extensions will also run in the same container, meaning that intellisense will use the same php-cli configuration!
|
||||||
|
|
||||||
|
`laravel-devcontainer` currently ships with:
|
||||||
|
|
||||||
|
- `php:8.3-cli-alpine` workspace with composer, pgsql, redis, and nodejs.
|
||||||
|
- `php:8.3-fpm-alpine` container with pgsql and redis extensions.
|
||||||
|
- `nginx:1.27-alpine` preconfigured for your Laravel application.
|
||||||
|
- `postgres:16.3-alpine` preconfigured with the default Laravel credentials.
|
||||||
|
- `redis:7.2-alpine` for caching, queues, sessions, etc.
|
||||||
|
|
||||||
|
#### Easy Installation
|
||||||
|
|
||||||
|
Using this configuration is quite simple. [Download](https://github.com/theomessin/laravel-devcontainer/archive/refs/heads/master.zip) and place `laravel-devcontainer` in a `.devcontainer` folder with your Laravel Code. If starting a new project, you may create a new folder with just `laravel-devcontainer` in your `.devcontainer` folder. You may then [install Laravel using Composer](https://laravel.com/docs/11.x/installation#creating-a-laravel-project) (e.g. under `example-app`). You may then move the `.devcontainer` folder to your code folder (`mv .devcontainer example-app`) and use that!
|
||||||
|
|
||||||
|
#### Installing Using Git Submodules
|
||||||
|
|
||||||
|
Alternatively, you may use [Git Submodules](https://git-scm.com/book/en/v2/Git-Tools-Submodules). Install the configuration by running
|
||||||
|
|
||||||
|
```sh
|
||||||
|
git submodule add https://github.com/theomessin/laravel-devcontainer .devcontainer
|
||||||
|
```
|
||||||
|
|
||||||
|
If you use this method, do not forget to install submodules when cloning:
|
||||||
|
|
||||||
|
```
|
||||||
|
git clone --recurse-submodules ...
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Usage
|
||||||
|
|
||||||
|
Start Visual Studio Code (e.g. `code example-app`) and re-open in remote containers (`Remote-Containers: Reopen in Container`). This may take some time on the first use, as Docker initially downloads and builds the images. Eventually, Visual Studio Code will run inside the workspace container. Extensions and settings specified in `devcontainer.json` will be auto-configured!
|
||||||
|
|
||||||
|
Be sure to correctly configure your application `.env` to use the devcontainer postgres and redis. For example:
|
||||||
|
|
||||||
|
```env
|
||||||
|
DB_CONNECTION=pgsql
|
||||||
|
DB_HOST=postgres
|
||||||
|
DB_PORT=5432
|
||||||
|
DB_DATABASE=laravel
|
||||||
|
DB_USERNAME=root
|
||||||
|
DB_PASSWORD=
|
||||||
|
|
||||||
|
REDIS_HOST=redis
|
||||||
|
REDIS_PASSWORD=null
|
||||||
|
REDIS_PORT=6379
|
||||||
|
```
|
||||||
|
|
||||||
|
You may then navigate to [`localhost`](http://localhost) on your local machine. Fingers crossed, you will see your Laravel application!
|
||||||
|
Run any artisan or composer commands using the Visual Studio Code [Integrated Terminal](https://code.visualstudio.com/docs/editor/integrated-terminal).
|
||||||
|
As such, you do not need anything else installed on your host machine!
|
||||||
|
|
||||||
|
#### Extensions
|
||||||
|
|
||||||
|
`laravel-devcontainer` currently ships with the following extensions for Laravel development in Visual Studio Code:
|
||||||
|
|
||||||
|
- ["bmewburn.vscode-intelephense-client"](https://marketplace.visualstudio.com/items?itemName=bmewburn.vscode-intelephense-client)
|
||||||
|
- ["eamodio.gitlens"](https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens)
|
||||||
|
- ["EditorConfig.EditorConfig"](https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig)
|
||||||
|
- ["mikestead.dotenv"](https://marketplace.visualstudio.com/items?itemName=mikestead.dotenv)
|
||||||
|
- ["onecentlin.laravel-blade"](https://marketplace.visualstudio.com/items?itemName=onecentlin.laravel-blade)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue