Compare commits
1 Commits
main
...
9315b97c66
| Author | SHA1 | Date | |
|---|---|---|---|
|
9315b97c66
|
@@ -1,3 +1,3 @@
|
|||||||
*
|
*
|
||||||
!docker/entrypoint.sh
|
!docker/entrypoint.sh
|
||||||
!docker/php.ini
|
!docker/php-fpm.conf
|
||||||
|
|||||||
@@ -16,9 +16,3 @@ indent_size = 2
|
|||||||
|
|
||||||
[*.sh]
|
[*.sh]
|
||||||
indent_size = 2
|
indent_size = 2
|
||||||
|
|
||||||
[Makefile]
|
|
||||||
indent_style = tab
|
|
||||||
|
|
||||||
[justfile]
|
|
||||||
indent_size = 2
|
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
# Database
|
|
||||||
# config/database.php
|
|
||||||
DB_CONNECTION=mysql
|
DB_CONNECTION=mysql
|
||||||
DB_HOST=mysql
|
DB_HOST=mysql
|
||||||
DB_PORT=3306
|
DB_PORT=3306
|
||||||
DB_DATABASE=app
|
DB_DATABASE=app
|
||||||
DB_USERNAME=laravel
|
DB_USERNAME=laravel
|
||||||
DB_PASSWORD=secret
|
DB_PASSWORD=secret
|
||||||
|
|
||||||
# Docker
|
|
||||||
DB_ROOT_PASSWORD=secret
|
DB_ROOT_PASSWORD=secret
|
||||||
|
|
||||||
APP_UID=1000
|
APP_UID=1000
|
||||||
APP_GID=1000
|
APP_GID=1000
|
||||||
|
|||||||
35
.gitignore
vendored
35
.gitignore
vendored
@@ -9,7 +9,7 @@ Homestead.json
|
|||||||
# Vendor / dependencies
|
# Vendor / dependencies
|
||||||
/vendor
|
/vendor
|
||||||
/composer/
|
/composer/
|
||||||
.composer/
|
.composer-hash
|
||||||
|
|
||||||
# Laravel storage and cache
|
# Laravel storage and cache
|
||||||
/storage/*.key
|
/storage/*.key
|
||||||
@@ -23,7 +23,6 @@ Homestead.json
|
|||||||
# Build artifacts
|
# Build artifacts
|
||||||
/public/build
|
/public/build
|
||||||
/public/hot
|
/public/hot
|
||||||
/public/docs
|
|
||||||
/bootstrap/cache/*
|
/bootstrap/cache/*
|
||||||
!/bootstrap/cache/.gitignore
|
!/bootstrap/cache/.gitignore
|
||||||
|
|
||||||
@@ -36,12 +35,40 @@ Homestead.json
|
|||||||
/.vscode
|
/.vscode
|
||||||
.phpactor.json
|
.phpactor.json
|
||||||
.scribe/
|
.scribe/
|
||||||
|
.scribe-hash
|
||||||
|
|
||||||
# System / logs
|
# System / logs
|
||||||
*.log
|
*.log
|
||||||
.DS_Store
|
.DS_Store
|
||||||
Thumbs.db
|
Thumbs.db
|
||||||
.bash_history
|
.bash_history
|
||||||
|
/bootstrap/ssr
|
||||||
|
/node_modules
|
||||||
|
/public/build
|
||||||
|
/public/hot
|
||||||
|
/public/storage
|
||||||
|
/storage/*.key
|
||||||
|
/storage/pail
|
||||||
|
/resources/js/actions
|
||||||
|
/resources/js/routes
|
||||||
|
/resources/js/wayfinder
|
||||||
|
/vendor
|
||||||
|
.DS_Store
|
||||||
|
.env
|
||||||
|
.env.backup
|
||||||
|
.env.production
|
||||||
|
.phpactor.json
|
||||||
|
.phpunit.result.cache
|
||||||
|
Homestead.json
|
||||||
|
Homestead.yaml
|
||||||
|
npm-debug.log
|
||||||
|
yarn-error.log
|
||||||
|
/auth.json
|
||||||
|
/.fleet
|
||||||
|
/.idea
|
||||||
|
/.nova
|
||||||
|
/.vscode
|
||||||
|
/.zed
|
||||||
|
|
||||||
# Custom
|
.composer-hash
|
||||||
.hashes/
|
.scribe-hash
|
||||||
|
|||||||
56
Makefile
Normal file
56
Makefile
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
-include .env
|
||||||
|
APP_UID ?= 1000
|
||||||
|
APP_GID ?= 1000
|
||||||
|
|
||||||
|
IMAGE_NAME := laravel-setup-php-fpm
|
||||||
|
IMAGE_TAG := latest
|
||||||
|
IMAGE := $(IMAGE_NAME):$(IMAGE_TAG)
|
||||||
|
TAR_FILE := $(IMAGE_NAME)_$(IMAGE_TAG).tar.gz
|
||||||
|
|
||||||
|
.PHONY: help build load shell docs
|
||||||
|
|
||||||
|
help:
|
||||||
|
@echo "Usage:"
|
||||||
|
@echo " make <target> [SOURCE=...]"
|
||||||
|
@echo ""
|
||||||
|
@echo "Targets:"
|
||||||
|
@echo " build Build Docker image and save to archive"
|
||||||
|
@echo " load Load Docker image from archive, URL, or build if missing"
|
||||||
|
@echo " Optional: SOURCE=url_or_file"
|
||||||
|
@echo " shell Enter php-fpm container as www"
|
||||||
|
@echo " docs Regenerate API documentation"
|
||||||
|
|
||||||
|
|
||||||
|
build:
|
||||||
|
@echo "Building image..."
|
||||||
|
docker build -f docker/Dockerfile --build-arg UID=$(APP_UID) --build-arg GID=$(APP_GID) -t $(IMAGE) .
|
||||||
|
@echo "Saving image to $(TAR_FILE)..."
|
||||||
|
docker save $(IMAGE) | gzip > $(TAR_FILE)
|
||||||
|
|
||||||
|
load:
|
||||||
|
ifdef SOURCE
|
||||||
|
@if echo "$(SOURCE)" | grep -qE '^https?://'; then \
|
||||||
|
echo "Downloading and loading image from $(SOURCE)..."; \
|
||||||
|
curl -L "$(SOURCE)" -o $(TAR_FILE); \
|
||||||
|
docker load < $(TAR_FILE); \
|
||||||
|
else \
|
||||||
|
echo "Loading image from file $(SOURCE)..."; \
|
||||||
|
docker load < $(SOURCE); \
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
@if [ -f "$(TAR_FILE)" ]; then \
|
||||||
|
echo "Loading image from archive $(TAR_FILE)..."; \
|
||||||
|
docker load < $(TAR_FILE); \
|
||||||
|
else \
|
||||||
|
echo "No archive found; building image..."; \
|
||||||
|
docker build -f docker/Dockerfile --build-arg UID=$(APP_UID) --build-arg GID=$(APP_GID) -t $(IMAGE) .; \
|
||||||
|
fi
|
||||||
|
endif
|
||||||
|
|
||||||
|
shell:
|
||||||
|
@echo "Entering php-fpm container as www..."
|
||||||
|
docker compose exec --user www php-fpm bash
|
||||||
|
|
||||||
|
docs:
|
||||||
|
@echo "Regenerating API documentation..."
|
||||||
|
docker compose exec --user www php-fpm php artisan scribe:generate
|
||||||
36
README.md
36
README.md
@@ -1,45 +1,25 @@
|
|||||||
# Laravel Docker Setup
|
# Laravel Docker Setup
|
||||||
|
|
||||||
- PHP-FPM, NGINX, MySQL, phpMyAdmin (in `compose.yaml`)
|
- NGINX, MySQL, phpMyAdmin
|
||||||
|
|
||||||
## Run a container
|
## Create a project:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cp .env.example .env
|
cp .env.example .env
|
||||||
# !change .env for yourself
|
# !change .env for yourself
|
||||||
docker compose up -d php-fpm
|
docker compose up -d php-fpm
|
||||||
docker compose exec --user www php-fpm bash
|
docker compose exec php-fpm bash
|
||||||
# or `just shell`
|
# or `make shell`
|
||||||
```
|
```
|
||||||
|
|
||||||
## Create a project:
|
# Rewrite below:
|
||||||
|
|
||||||
**_Rewrite below for yourself:_**
|
|
||||||
|
|
||||||
*RECOMENDED:*
|
|
||||||
|
|
||||||
**The latest version** via [laravel/installer package](https://packagist.org/packages/laravel/installer)
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
composer global require laravel/installer && \
|
composer global require laravel/installer
|
||||||
|
|
||||||
export PATH="$HOME/.composer/vendor/bin:$PATH"
|
export PATH="$HOME/.composer/vendor/bin:$PATH"
|
||||||
|
|
||||||
# Check options via `laravel new -h`
|
|
||||||
laravel new example-app
|
laravel new example-app
|
||||||
|
|
||||||
# copy your `.env` content to `example-app/.env`
|
|
||||||
mv example-app/* example-app/.* ./
|
|
||||||
rmdir example-app
|
|
||||||
```
|
|
||||||
|
|
||||||
*OR:*
|
|
||||||
|
|
||||||
**The specific version** via composer
|
|
||||||
|
|
||||||
```bash
|
|
||||||
composer create-project --prefer-dist laravel/laravel example-app ^11.0
|
|
||||||
|
|
||||||
# copy your `.env` content to `example-app/.env`
|
|
||||||
mv example-app/* example-app/.* ./
|
mv example-app/* example-app/.* ./
|
||||||
rmdir example-app
|
rmdir example-app
|
||||||
```
|
```
|
||||||
@@ -47,5 +27,5 @@ rmdir example-app
|
|||||||
## Quick Actions
|
## Quick Actions
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
just
|
make help
|
||||||
```
|
```
|
||||||
|
|||||||
11
compose.yaml
11
compose.yaml
@@ -29,25 +29,22 @@ services:
|
|||||||
mysql:
|
mysql:
|
||||||
image: mysql:8.0
|
image: mysql:8.0
|
||||||
ports:
|
ports:
|
||||||
- "127.0.0.1:${DB_PORT:-3306}:3306"
|
- "${DB_PORT:-3306}:3306"
|
||||||
environment:
|
environment:
|
||||||
- MYSQL_DATABASE=${DB_DATABASE}
|
- MYSQL_DATABASE=${DB_DATABASE}
|
||||||
- MYSQL_USER=${DB_USERNAME}
|
- MYSQL_USER=${DB_USERNAME}
|
||||||
- MYSQL_PASSWORD=${DB_PASSWORD}
|
- MYSQL_PASSWORD=${DB_PASSWORD}
|
||||||
- MYSQL_ROOT_PASSWORD=${DB_ROOT_PASSWORD}
|
- MYSQL_ROOT_PASSWORD=${DB_ROOT_PASSWORD}
|
||||||
volumes:
|
volumes:
|
||||||
- mysql-data-development:/var/lib/mysql
|
- mysql-data:/var/lib/mysql
|
||||||
|
|
||||||
|
|
||||||
phpmyadmin:
|
phpmyadmin:
|
||||||
image: phpmyadmin:latest
|
image: phpmyadmin:latest
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
ports:
|
ports:
|
||||||
- "127.0.0.1:8080:80"
|
- "8080:80"
|
||||||
environment:
|
environment:
|
||||||
- PMA_HOST=mysql
|
- PMA_HOST=mysql
|
||||||
- PMA_USER=root
|
|
||||||
- PMA_PASSWORD=${DB_ROOT_PASSWORD}
|
|
||||||
- PMA_PORT=${DB_PORT:-3306}
|
- PMA_PORT=${DB_PORT:-3306}
|
||||||
- UPLOAD_LIMIT=100M
|
- UPLOAD_LIMIT=100M
|
||||||
depends_on:
|
depends_on:
|
||||||
@@ -55,4 +52,4 @@ services:
|
|||||||
condition: service_started
|
condition: service_started
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
mysql-data-development:
|
mysql-data:
|
||||||
|
|||||||
@@ -1,14 +1,10 @@
|
|||||||
FROM mysql:8.0 AS mysql
|
|
||||||
|
|
||||||
FROM php:8.3-fpm
|
FROM php:8.3-fpm
|
||||||
|
|
||||||
COPY --from=mysql /usr/bin/mysql /usr/bin/mysql
|
|
||||||
COPY --from=mysql /usr/bin/mysqldump /usr/bin/mysqldump
|
|
||||||
|
|
||||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
libonig-dev libicu-dev \
|
libpng-dev libonig-dev libxml2-dev libzip-dev \
|
||||||
gosu netcat-traditional \
|
zip unzip git gosu \
|
||||||
&& docker-php-ext-install pdo_mysql mbstring intl \
|
netcat-traditional \
|
||||||
|
&& docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd zip \
|
||||||
&& apt-get clean && rm -rf /var/lib/apt/lists/*
|
&& apt-get clean && rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
|
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
|
||||||
@@ -17,6 +13,7 @@ ARG UID
|
|||||||
ARG GID
|
ARG GID
|
||||||
|
|
||||||
# Create a new user with the specified UID and GID, reusing an existing group if GID exists
|
# Create a new user with the specified UID and GID, reusing an existing group if GID exists
|
||||||
|
# and update php-fpm to use the new user and group
|
||||||
RUN if getent group ${GID}; then \
|
RUN if getent group ${GID}; then \
|
||||||
group_name=$(getent group ${GID} | cut -d: -f1); \
|
group_name=$(getent group ${GID} | cut -d: -f1); \
|
||||||
useradd -m -u ${UID} -g ${GID} -s /bin/bash www; \
|
useradd -m -u ${UID} -g ${GID} -s /bin/bash www; \
|
||||||
@@ -30,8 +27,6 @@ RUN if getent group ${GID}; then \
|
|||||||
RUN sed -i "s/user = www-data/user = www/g" /usr/local/etc/php-fpm.d/www.conf && \
|
RUN sed -i "s/user = www-data/user = www/g" /usr/local/etc/php-fpm.d/www.conf && \
|
||||||
sed -i "s/group = www-data/group = $group_name/g" /usr/local/etc/php-fpm.d/www.conf
|
sed -i "s/group = www-data/group = $group_name/g" /usr/local/etc/php-fpm.d/www.conf
|
||||||
|
|
||||||
COPY --chmod=644 ./docker/php.ini /usr/local/etc/php/conf.d/laravel.ini
|
|
||||||
|
|
||||||
COPY ./docker/entrypoint.sh /usr/local/bin/
|
COPY ./docker/entrypoint.sh /usr/local/bin/
|
||||||
RUN chmod +x /usr/local/bin/entrypoint.sh
|
RUN chmod +x /usr/local/bin/entrypoint.sh
|
||||||
|
|
||||||
|
|||||||
@@ -9,13 +9,10 @@ if [ ! -f "artisan" ]; then
|
|||||||
exec "$@"
|
exec "$@"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
gosu www mkdir -p .hashes
|
if [ ! -f .composer-hash ] || ! sha1sum -c .composer-hash > /dev/null 2>&1; then
|
||||||
|
|
||||||
if [ ! -f "vendor/autoload.php" ] || [ ! -f .hashes/.composer-hash ] || ! sha1sum -c .hashes/.composer-hash; then
|
|
||||||
echo ">> composer.json or composer.lock changed, installing dependencies..."
|
echo ">> composer.json or composer.lock changed, installing dependencies..."
|
||||||
gosu www composer install --optimize-autoloader --no-interaction
|
gosu www composer install --optimize-autoloader --no-interaction
|
||||||
gosu www sha1sum composer.json composer.lock > .hashes/.composer-hash
|
sha1sum composer.json composer.lock > .composer-hash
|
||||||
chown www: .hashes/.composer-hash
|
|
||||||
else
|
else
|
||||||
echo ">> Composer dependencies up to date (hash match), skipping install."
|
echo ">> Composer dependencies up to date (hash match), skipping install."
|
||||||
fi
|
fi
|
||||||
@@ -46,12 +43,10 @@ if composer show knuckleswtf/scribe >/dev/null 2>&1; then
|
|||||||
# Create combined hash of all .php files in those paths
|
# Create combined hash of all .php files in those paths
|
||||||
CURRENT_HASH=$(find $SCRIBE_SOURCES -type f -name "*.php" -exec sha1sum {} + | sha1sum)
|
CURRENT_HASH=$(find $SCRIBE_SOURCES -type f -name "*.php" -exec sha1sum {} + | sha1sum)
|
||||||
|
|
||||||
if [ ! -f .hashes/.scribe-hash ] || [ "$CURRENT_HASH" != "$(cat .hashes/.scribe-hash)" ]; then
|
if [ ! -f .scribe-hash ] || [ "$CURRENT_HASH" != "$(cat .scribe-hash)" ]; then
|
||||||
echo ">> Generating API documentation..."
|
echo ">> Generating API documentation..."
|
||||||
gosu www php artisan scribe:generate --no-interaction \
|
gosu www php artisan scribe:generate --no-interaction || true
|
||||||
|| echo ">> Warning: Scribe generation failed, continuing..."
|
echo "$CURRENT_HASH" > .scribe-hash
|
||||||
echo "$CURRENT_HASH" > .hashes/.scribe-hash
|
|
||||||
chown www: .hashes/.scribe-hash
|
|
||||||
else
|
else
|
||||||
echo ">> API docs up to date, skipping Scribe generation."
|
echo ">> API docs up to date, skipping Scribe generation."
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
server {
|
server {
|
||||||
listen 80;
|
listen 80;
|
||||||
client_max_body_size 20M;
|
|
||||||
index index.php index.html;
|
index index.php index.html;
|
||||||
error_log /var/log/nginx/error.log;
|
error_log /var/log/nginx/error.log;
|
||||||
access_log /var/log/nginx/access.log;
|
access_log /var/log/nginx/access.log;
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
post_max_size = 20M
|
|
||||||
upload_max_filesize = 20M
|
|
||||||
44
justfile
44
justfile
@@ -1,44 +0,0 @@
|
|||||||
set dotenv-load
|
|
||||||
set shell := ["bash", "-eu", "-o", "pipefail", "-c"]
|
|
||||||
|
|
||||||
APP_UID := env("APP_UID", "1000")
|
|
||||||
APP_GID := env("APP_GID", "1000")
|
|
||||||
|
|
||||||
IMAGE_NAME := "laravel-setup-php-fpm"
|
|
||||||
IMAGE_TAG := "latest"
|
|
||||||
IMAGE := IMAGE_NAME + ":" + IMAGE_TAG
|
|
||||||
|
|
||||||
# Show available recipes
|
|
||||||
default:
|
|
||||||
@just --list
|
|
||||||
|
|
||||||
# Build Docker image
|
|
||||||
build:
|
|
||||||
docker build -f docker/Dockerfile \
|
|
||||||
--build-arg UID={{APP_UID}} \
|
|
||||||
--build-arg GID={{APP_GID}} \
|
|
||||||
-t {{IMAGE}} .
|
|
||||||
|
|
||||||
# Open shell in PHP-FPM container
|
|
||||||
shell:
|
|
||||||
docker compose exec --user www php-fpm bash
|
|
||||||
|
|
||||||
# Generate API documentation
|
|
||||||
docs *args:
|
|
||||||
docker compose exec --user www php-fpm php artisan scribe:generate {{ args }}
|
|
||||||
|
|
||||||
# Regenerate DB and docs
|
|
||||||
docs-fresh:
|
|
||||||
just db && just docs --force
|
|
||||||
|
|
||||||
# Reset database with fresh migration and seeding
|
|
||||||
db:
|
|
||||||
docker compose exec --user www php-fpm php artisan migrate:fresh --seed
|
|
||||||
|
|
||||||
# Run tests
|
|
||||||
test:
|
|
||||||
docker compose exec --user www php-fpm php artisan test
|
|
||||||
|
|
||||||
# Run Pint
|
|
||||||
lint:
|
|
||||||
docker compose exec --user www php-fpm php ./vendor/bin/pint
|
|
||||||
Reference in New Issue
Block a user