Skip to content

Commit 86e1f8f

Browse files
author
Sylvain Dherbecourt
committed
chore: init skeleton magento2 with frankenphp
0 parents  commit 86e1f8f

16 files changed

+382
-0
lines changed

.docker/.gitignore

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# ./docker directory
2+
*
3+
!.gitignore
4+
!database
5+
!database/**
6+
!opensearch
7+
!opensearch/**
8+
!php
9+
!php/**
10+
!rabbitmq
11+
!rabbitmq/**
12+
*/.env

.docker/database/.env.dist

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
MARIADB_DATABASE=magento-database
2+
MARIADB_ROOT_PASSWORD=magento-root-password
3+
MARIADB_USER=magento-user
4+
MARIADB_PASSWORD=magento-password

.docker/opensearch/.env.dist

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
OPENSEARCH_HOST=opensearch
2+
OPENSEARCH_PORT=9200
3+
4+
# Prevent security patch conflicts with core M2 code
5+
DISABLE_SECURITY_PLUGIN=true

.docker/opensearch/Dockerfile

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM opensearchproject/opensearch:2.12.0
2+
3+
RUN /usr/share/opensearch/bin/opensearch-plugin install --batch \
4+
analysis-icu \
5+
analysis-phonetic \

.docker/php/Dockerfile

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Versions
2+
FROM dunglas/frankenphp:1.3.3-php8.3 AS frankenphp_upstream
3+
4+
# Base FrankenPHP image
5+
FROM frankenphp_upstream AS frankenphp_base
6+
7+
WORKDIR /var/www/html
8+
9+
# Install system dependencies
10+
RUN apt-get update && apt-get install -y --no-install-recommends \
11+
cron \
12+
ssmtp \
13+
libfreetype6-dev \
14+
libicu-dev \
15+
libjpeg62-turbo-dev \
16+
libmcrypt-dev \
17+
libxslt1-dev \
18+
zip \
19+
git \
20+
acl \
21+
&& rm -rf /var/lib/apt/lists/*
22+
23+
RUN set -eux; \
24+
install-php-extensions \
25+
@composer \
26+
bcmath \
27+
gd \
28+
intl \
29+
mbstring \
30+
mcrypt \
31+
opcache \
32+
pdo_mysql \
33+
soap \
34+
xsl \
35+
zip \
36+
sockets
37+
38+
# Copy the application code
39+
COPY --link ./.docker/php/conf/app.ini $PHP_INI_DIR/conf.d/
40+
COPY --link --chmod=755 ./.docker/php/conf/docker-entrypoint.sh /usr/local/bin/docker-entrypoint
41+
COPY --link ./.docker/php/conf/Caddyfile /etc/caddy/Caddyfile
42+
43+
# Set the entrypoint
44+
ENTRYPOINT ["docker-entrypoint"]
45+
46+
HEALTHCHECK --start-period=60s CMD curl -f https://$SERVER_NAME/health_check.php || exit 1
47+
CMD [ "frankenphp", "run", "--config", "/etc/caddy/Caddyfile" ]
48+
49+
# Development FrankenPHP image
50+
FROM frankenphp_base AS frankenphp_dev
51+
52+
RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"
53+
54+
RUN apt-get update && apt-get install -y --no-install-recommends mkcert
55+
56+
RUN set -eux; \
57+
install-php-extensions \
58+
xdebug
59+
60+
# Configuration for development
61+
COPY --link ./.docker/php/conf/app.dev.ini ./.docker/php/conf/xdebug.ini $PHP_INI_DIR/conf.d/
62+
RUN echo "mailhub=mailcatcher:1025\nUseTLS=NO\nFromLineOverride=YES" > /etc/ssmtp/ssmtp.conf
63+
CMD [ "frankenphp", "run", "--config", "/etc/caddy/Caddyfile", "--watch" ]

.docker/php/conf/Caddyfile

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
{
2+
{$CADDY_GLOBAL_OPTIONS}
3+
4+
frankenphp {
5+
{$FRANKENPHP_CONFIG}
6+
}
7+
8+
# https://caddyserver.com/docs/caddyfile/directives#sorting-algorithm
9+
order php_server before file_server
10+
}
11+
12+
{$CADDY_EXTRA_CONFIG}
13+
14+
(404) {
15+
rewrite * /errors/404.php
16+
}
17+
18+
{$SERVER_NAME} {
19+
log {
20+
output file /var/log/caddy.log
21+
}
22+
23+
root * /var/www/html/pub
24+
encode zstd br gzip
25+
26+
{$CADDY_SERVER_EXTRA_DIRECTIVES}
27+
28+
# Deny access to sensitive files and directories
29+
@sensitiveFiles {
30+
path_regexp sensitiveFiles /(\.user.ini|\.php$|.*\.phtml$|\.htaccess$|\.htpasswd$|\.git|.*\.txt|.*\.md|errors\/.*\.xml|media\/theme_customization\/.*\.xml)
31+
}
32+
@sensitiveDirectories {
33+
path_regexp sensitiveDirectories /(media\/customer\/*|media\/downloadable\/*|media\/import\/*|media\/custom_options\/*|setup\/*)
34+
}
35+
36+
# Rewrite to 404 for sensitive files and directories
37+
handle @sensitiveFiles {
38+
import 404
39+
}
40+
handle @sensitiveDirectories {
41+
import 404
42+
}
43+
44+
# Disable Topics tracking if not enabled explicitly: https://github.com/jkarlin/topics
45+
header ?Permissions-Policy "browsing-topics=()"
46+
47+
php_server
48+
49+
@staticPath path_regexp reg_static ^/static/(version\d*/)?(.*)$
50+
handle @staticPath {
51+
@static file /static/{re.reg_static.2}
52+
rewrite @static /static/{re.reg_static.2}
53+
54+
@staticFiles {
55+
path *.ico *.jpg *.jpeg *.png *.gif *.svg *.svgz *.webp *.avif *.avifs *.js *.css *.eot *.ttf *.otf *.woff *.woff2 *.html *.json *.webmanifest
56+
}
57+
handle @staticFiles {
58+
# Set headers for matched static assets
59+
header Cache-Control "public, max-age=31536000"
60+
}
61+
@noCacheFiles {
62+
path *.zip *.gz *.gzip *.bz2 *.csv *.xml
63+
}
64+
handle @noCacheFiles {
65+
# Set Cache-Control header to no-store
66+
header Cache-Control "no-store, no-cache, must-revalidate"
67+
}
68+
69+
@dynamic not file /static/{re.reg_static.2}
70+
rewrite @dynamic /static.php?resource={re.reg_static.2}
71+
header X-Frame-Options "SAMEORIGIN"
72+
}
73+
74+
handle /media/* {
75+
@staticFiles {
76+
path *.ico *.jpg *.jpeg *.png *.gif *.svg *.svgz *.webp *.avif *.avifs *.js *.css *.eot *.ttf *.otf *.woff *.woff2
77+
}
78+
handle @staticFiles {
79+
# Set Cache-Control header for 1 year caching
80+
header Cache-Control "public, max-age=31536000"
81+
}
82+
@noCacheFiles {
83+
path *.zip *.gz *.gzip *.bz2 *.csv *.xml
84+
}
85+
handle @noCacheFiles {
86+
# Set Cache-Control header to no-store
87+
header Cache-Control "no-store, no-cache, must-revalidate"
88+
}
89+
90+
try_files {path} {path}/ /get.php{query}
91+
header X-Frame-Options "SAMEORIGIN"
92+
}
93+
94+
# PHP entry point for main application
95+
@phpFiles path /index.php /get.php /static.php /errors/report.php /errors/404.php /errors/503.php /health_check.php
96+
handle @phpFiles {
97+
try_files {path} {path}/ =404
98+
}
99+
100+
handle_errors 404 403 {
101+
import 404
102+
}
103+
}

.docker/php/conf/app.dev.ini

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
memory_limit = 2G
2+
max_execution_time = 60
3+
apc.enable_cli = 1
4+
5+
xdebug.start_with_request = yes
6+
xdebug.idekey = PHPSTORM
7+
xdebug.client_host = host.docker.internal
8+
xdebug.discover_client_host = 1
9+
10+
sendmail_path = /usr/sbin/ssmtp -t

.docker/php/conf/app.ini

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
expose_php = 0
2+
date.timezone = UTC
3+
session.use_strict_mode = 1
4+
memory_limit = 1G
5+
max_execution_time = 30
6+
zlib.output_compression = On
7+
cgi.fix_pathinfo = 0
8+
9+
realpath_cache_size = 10M
10+
realpath_cache_ttl = 7200
11+
opcache.memory_consumption=512
12+
opcache.max_accelerated_files=60000
13+
opcache.consistency_checks=0
14+
opcache.validate_timestamps=0
15+
opcache.enable_cli=1
16+
opcache.interned_strings_buffer = 16
17+
opcache.enable_file_override = 1
18+
19+
upload_max_filesize = 10M
20+
post_max_size = 10M
21+
max_input_vars = 10000

.docker/php/conf/docker-entrypoint.sh

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
set -e
3+
4+
if [ "$1" = 'frankenphp' ] || [ "$1" = 'php' ] || [ "$1" = 'bin/magento' ]; then
5+
if [ ! -f /etc/caddy/certs/tls.pem ]; then
6+
mkdir -p /etc/caddy/certs
7+
mkcert -install
8+
mkcert -cert-file /etc/caddy/certs/tls.pem -key-file /etc/caddy/certs/tls.key "$SERVER_NAME"
9+
fi
10+
fi
11+
12+
exec docker-php-entrypoint "$@"

.docker/php/conf/xdebug.ini

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#Disable xdebug by default and enable it only when needed
2+
xdebug.mode = off

.docker/rabbitmq/.env.dist

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
RABBITMQ_HOST=rabbitmq
2+
RABBITMQ_PORT=5672
3+
RABBITMQ_MANAGEMENT_PORT=15672
4+
RABBITMQ_DEFAULT_USER=magento
5+
RABBITMQ_DEFAULT_PASS=magento
6+
RABBITMQ_DEFAULT_VHOST=/

.docker/rabbitmq/conf/rabbitmq.conf

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vm_memory_high_watermark.absolute = 1GB

.env.dist

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# PROJECT
2+
PROJECT_NAME=docker-magento-skeleton
3+
SERVER_NAME=docker-magento-skeleton.localdev

.gitignore

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Magento 2
2+
/app/*
3+
!/app/code
4+
/dev
5+
/generated
6+
/lib
7+
/phpserver
8+
/pub
9+
/setup
10+
/var
11+
/vendor
12+
/.phpunit.cache
13+
.editorconfig
14+
.env
15+
.htaccess
16+
.htaccess.sample
17+
.php-cs-fixer.cache
18+
.php-cs-fixer.php
19+
.php-cs-fixer.dist.php
20+
.user.ini
21+
.idea
22+
auth.json
23+
auth.json.sample
24+
CHANGELOG.md
25+
COPYING.txt
26+
grunt-config.json.sample
27+
Gruntfile.js.sample
28+
LICENSE.txt
29+
LICENSE_AFL.txt
30+
nginx.conf.sample
31+
package.json.sample
32+
SECURITY.md
33+
34+
# Docker
35+
docker-compose.override.yml
36+
docker-compose.override.yaml
37+
compose.override.yml
38+
compose.override.yaml

README.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Magento on FrankenPHP
2+
3+
## Requirements
4+
5+
- [Docker](https://docs.docker.com/)
6+
- [Docker Compose](https://docs.docker.com/compose/overview/)
7+
- [Git](https://git-scm.com/)
8+
9+
## Installation
10+
11+
- copy and **configure** environment files:
12+
```
13+
cp .env.dist .env
14+
cp ./.docker/database/.env.dist ./.docker/database/.env
15+
cp ./.docker/opensearch/.env.dist ./.docker/opensearch/.env
16+
cp ./.docker/rabbitmq/.env.dist ./.docker/rabbitmq/.env
17+
```
18+
- edit the SERVER_NAME variable in the .env file and replace docker-magento-skeleton.localdev with your domain
19+
- run the docker-compose file: `docker compose up -d --remove-orphans`
20+
- use your composer files to install your project
21+
- edit the file `/etc/hosts` of your machine and add your domain like this :
22+
23+
```
24+
127.0.0.1 docker-magento-skeleton.localdev
25+
```

compose.yml

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
services:
2+
php:
3+
build:
4+
dockerfile: ./.docker/php/Dockerfile
5+
environment:
6+
CADDY_SERVER_EXTRA_DIRECTIVES: "tls /etc/caddy/certs/tls.pem /etc/caddy/certs/tls.key"
7+
env_file:
8+
- .env
9+
volumes:
10+
- ./:/var/www/html:delegated
11+
- ./.docker/php/conf/Caddyfile:/etc/caddy/Caddyfile:cached
12+
depends_on:
13+
- database
14+
- redis
15+
- opensearch
16+
ports:
17+
# HTTP
18+
- target: 80
19+
published: ${HTTP_PORT:-80}
20+
protocol: tcp
21+
# HTTPS
22+
- target: 443
23+
published: ${HTTPS_PORT:-443}
24+
protocol: tcp
25+
# HTTP/3
26+
- target: 443
27+
published: ${HTTP3_PORT:-443}
28+
protocol: udp
29+
extra_hosts:
30+
# Ensure that host.docker.internal is correctly defined on Linux
31+
- host.docker.internal:host-gateway
32+
tty: true
33+
database:
34+
image: mariadb:10.6.18
35+
env_file:
36+
- ./.docker/database/.env
37+
volumes:
38+
- db_data:/var/lib/mysql
39+
ports:
40+
- 3306:3306
41+
redis:
42+
image: redis:7.0-alpine
43+
ports:
44+
- "6379:6379"
45+
opensearch:
46+
build:
47+
dockerfile: ./.docker/opensearch/Dockerfile
48+
ports:
49+
- "9200:9200"
50+
- "9300:9300"
51+
env_file: ./.docker/opensearch/.env
52+
environment:
53+
- "discovery.type=single-node"
54+
- "cluster.routing.allocation.disk.threshold_enabled=false"
55+
- "index.blocks.read_only_allow_delete"
56+
rabbitmq:
57+
image: rabbitmq:4.0-management-alpine
58+
ports:
59+
- "15672:15672"
60+
- "5672:5672"
61+
volumes:
62+
- rabbitmqdata:/var/lib/rabbitmq:delegated
63+
- ./.docker/rabbitmq/conf/rabbitmq.conf:/etc/rabbitmq/rabbitmq.conf:delegated
64+
env_file: ./.docker/rabbitmq/.env
65+
mailcatcher:
66+
image: sj26/mailcatcher
67+
ports:
68+
- "1080:1080"
69+
- "1025:1025"
70+
volumes:
71+
db_data:
72+
rabbitmqdata:

0 commit comments

Comments
 (0)