Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .docker/mysql/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM mysql:9.5

COPY docker-entrypoint-initdb.d /docker-entrypoint-initdb.d
COPY conf.d/collation.cnf /etc/mysql/conf.d/collation.cnf
COPY my.cnf /etc/my.cnf
9 changes: 9 additions & 0 deletions .docker/mysql/conf.d/collation.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[client]
default-character-set = utf8mb4

[mysql]
default-character-set = utf8mb4

[mysqld]
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
4 changes: 4 additions & 0 deletions .docker/mysql/docker-entrypoint-initdb.d/01-databases.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- GRANT PRIVILEGES
CREATE USER IF NOT EXISTS 'dbuser'@'%' IDENTIFIED BY 'dbpassword';
GRANT ALL ON main.* TO 'dbuser'@'%';
FLUSH PRIVILEGES;
23 changes: 23 additions & 0 deletions .docker/mysql/my.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[mysqld]
max_connections = 5
disable-log-bin = 1
performance-schema = 0

innodb_buffer_pool_size = 1G
innodb_flush_log_at_trx_commit = 2
innodb_read_io_threads = 12
innodb_write_io_threads = 12
innodb_stats_on_metadata = 0
innodb_file_per_table = 1

thread_cache_size = 8
table_definition_cache = 65536
table_open_cache = 65536

tmp_table_size = 64M
max_heap_table_size = 64M

read_buffer_size = 256K
join_buffer_size = 512K
sort_buffer_size = 512K
read_rnd_buffer_size = 512K
3 changes: 3 additions & 0 deletions .docker/postgresql/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM postgres:16-alpine3.21

COPY initdb /docker-entrypoint-initdb.d
8 changes: 8 additions & 0 deletions .docker/postgresql/conf/pg_hba.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# TYPE DATABASE USER ADDRESS METHOD
local all all trust
host all all 127.0.0.1/32 trust
host all all ::1/128 trust
host all all 172.17.0.1/16 trust
host all all 172.18.0.1/16 trust
host all all 10.0.0.0/8 trust
host all all all md5
2 changes: 2 additions & 0 deletions .docker/postgresql/initdb/init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Create a new logical database
CREATE DATABASE maincopy;
42 changes: 33 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ARGS = $(filter-out $@,$(MAKECMDGOALS))
DOCKER_RUN = docker run --init -it --rm -u ${USER} -v "$$(pwd):/app" -w /app

# https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
.PHONY: help tests fix check
.PHONY: help tests fix check example
.DEFAULT_GOAL := help

help: ## Display this help screen
Expand Down Expand Up @@ -61,14 +61,9 @@ rector: ## rector
ghcr.io/kuaukutsu/php:${PHP_VERSION}-cli \
./vendor/bin/rector

fix: ## run fix tools
make phpcbf
make rector
fix: phpcbf rector ## run fix tools

check: ## run analysis tools
make phpcs
make psalm
make phpstan
check: phpcs psalm phpstan ## run analysis tools

infection:
docker build \
Expand Down Expand Up @@ -115,7 +110,36 @@ tests:

## Application

app:
cli:
$(DOCKER_RUN) -w /app/example \
ghcr.io/kuaukutsu/php:${PHP_VERSION}-cli \
sh -l

example:
VERSION=$(VERSION) USER=$(USER) \
docker compose run --rm -u $(USER) -w /example app sh -l
make stop

stop: ## Stop server
docker compose -f ./docker-compose.yml stop

down: stop
docker compose -f ./docker-compose.yml down --remove-orphans

remove: down _image_remove _container_remove _volume_remove

_image_remove:
docker image rm -f \
migrator-app \
migrator-postgres \
migrator-mysql

_container_remove:
docker rm -f \
migrator_postgres \
migrator_mysql

_volume_remove:
docker volume rm -f \
migrator_pg_data \
migrator_mysql_data
120 changes: 120 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
x-default-logging: &default-logging
driver: local
options:
max-size: "5m"
max-file: "3"

x-volumes:
src: &vol-src
type: bind
source: ./src
target: /src

example: &vol-example
type: bind
source: ./example
target: /example

vendor: &vol-vendor
type: bind
source: ./vendor
target: /vendor
read_only: true

name: migrator
services:
app:
container_name: migrator_app
build:
context: .docker/php/cli
target: devel
args:
UID: ${USER:-1} # ID:1 daemon, support: linux, mac
WORKDIR: "/example"
depends_on:
postgres:
condition: service_healthy
mysql:
condition: service_healthy
networks:
- migrator
volumes:
- *vol-src
- *vol-example
- *vol-vendor
logging: *default-logging

postgres:
container_name: migrator_postgres
build:
context: .docker/postgresql
deploy:
resources:
limits:
cpus: "1.0"
memory: 512M
reservations:
cpus: "0.5"
memory: 256M
ports:
- "5435:5432"
environment:
- POSTGRES_DB=main
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
networks:
- migrator
volumes:
- pg_data:/var/lib/postgresql/data
healthcheck:
test: "pg_isready -U \"$$POSTGRES_USER\" -d \"$$POSTGRES_DB\""
interval: 5s
timeout: 5s
retries: 5
start_period: 2s
start_interval: 1s
logging: *default-logging

mysql:
container_name: migrator_mysql
build:
context: .docker/mysql
cap_add:
- SYS_NICE # CAP_SYS_NICE
deploy:
resources:
limits:
cpus: "1.0"
memory: 512M
reservations:
cpus: "0.5"
memory: 256M
ports:
- "3306:3306"
networks:
- migrator
command: [
'--character-set-server=utf8mb4',
'--collation-server=utf8mb4_unicode_ci'
]
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: main
MYSQL_USER: dbuser
MYSQL_PASSWORD: dbpassword
volumes:
- mysql_data:/var/lib/mysql
healthcheck:
test: [ "CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-proot" ]
interval: 10s
timeout: 5s
retries: 5
start_period: 10s
logging: *default-logging

volumes:
pg_data:
mysql_data:

networks:
migrator:
Loading