ディレクトリ構成
php/app は後で symfony app が生成される
.devcontainer は手動で作成しても良いがdocker-composeから作るほうが簡単
workspace
┣ .devcontainer
┃ ┣ devcontainer.json
┃ ┗ docker-compose.yml
┣ mysql
┃ ┣ conf.d
┃ ┃ ┗ default.conf
┃ ┣ init.d
┃ ┃ ┣ 01-schema.sql
┃ ┃ ┗ 02-data.sql
┃ ┗ .env
┣ nginx
┃ ┣ config
┃ ┃ ┗ default.conf
┃ ┗ public
┣ php
┃ ┣ app
┃ ┗ Dockerfile
┗ docker-compose.yml
nginx
php-fpm への接続と静的ファイルのハンドリングを設定する
server {
index index.php index.html;
server_name localhost;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /app/public;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location /build {
alias /app/public/build;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass app:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
php fpm
symfony,laravel等、composerが必須だしyarn とか webpackとか使う場合は node.js が必要なのでデフォルトの php-fpmイメージにそれらを追加する。
FROM php:8-fpm
ARG UID=1000
ARG GID=1000
RUN useradd -m -u ${UID} docker
# Node.jsをインストール
RUN curl -sL https://deb.nodesource.com/setup_16.x | bash -
RUN apt-get install -y nodejs
# yarnをインストール
RUN apt remove cmdtest && apt remove yarn
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
RUN apt-get update \
&& apt-get install yarn \
&& docker-php-ext-install pdo_mysql \
&& apt install -y git unzip
USER ${UID}:${GID}
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
uid を変更するのは composer でファイル生成したとファイルのオーナーがコンテナ内部のrootになってしまうのを避けるため。
docker-composer.yml
version: '3'
services:
web:
image: nginx:latest
ports:
- "80:80"
volumes:
- ./php/app:/app
- ./nginx/public:/var/www/html
- ./nginx/config/default.conf:/etc/nginx/conf.d/default.conf
depends_on:
- app
database:
image: mysql:8.0
restart: always
ports:
- "3306:3306"
volumes:
- ./mysql/conf.d:/etc/mysql/conf.d
- ./mysql/init.d:/docker-entrypoint-initdb.d
env_file: ./mysql/.env
app:
build: ./php
volumes:
- ./php/app:/app
".env" は git等scm には入れない。代わりに env.sampleとか無難なファイルを作る
nginx からアプリケーションの静的ファイルを参照させるため、php/appをvolumesで共有する。
symfony appllication
symfony のインストラクションに従う
doctrine の設定
Entityの型マッピングとか(geometory,year,...)する
doctrine:
dbal:
driver: 'pdo_mysql'
server_version: '8.0'
charset: utf8mb4
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
url: '%env(resolve:DATABASE_URL)%'
types:
geometry: CrEOF\Spatial\DBAL\Types\GeometryType
point: CrEOF\Spatial\DBAL\Types\Geometry\PointType
polygon: CrEOF\Spatial\DBAL\Types\Geometry\PolygonType
linestring: CrEOF\Spatial\DBAL\Types\Geometry\LineStringType
mapping_types:
enum: string
year: integer
orm:
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
dql:
numeric_functions:
numeric_functions:
st_contains: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\STContains
contains: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Contains
st_area: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Area
st_geomfromtext: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\GeomFromText
st_intersects: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\STIntersects
st_buffer: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\STBuffer
point: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Point
entity 生成
一応データベースからエンティティのリバース生成はできるが、 public getter,setter は自前で書く必要がある
css,js の設定
これとか参照
https://symfony.com/doc/current/frontend/encore/installation.html
sass制御は別途 packageに追加する
bootstrap とか
参照
https://symfony.com/doc/current/frontend/encore/bootstrap.html
その他
コンテナのリビルドとか割と不安定っぽい。