Skip to content
Open
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
4 changes: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ FORCE_HTTPS=true
LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_HOST=mariadb
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
Expand Down Expand Up @@ -65,3 +65,5 @@ PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

FORWARD_DB_PORT=9306
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ Homestead.json
# Version
.version
composer.phar

.phpunit.cache
42 changes: 42 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Misc
.DEFAULT_GOAL = help
.PHONY: backend/lang
MAKEFLAGS += --no-print-directory

# Executables (local)
DOCKER_COMPOSE = docker compose -f docker-compose.yml -f docker-compose-helpers.yml --env-file .env
PHP_CONTAINER = $(DOCKER_COMPOSE) exec --user="www-data:www-data" fpm

## —— ⎈🎵 🐳 The PhotoBook Makefile 🐳 🎵⎈ ————————————————————————————————————————
help: ## Outputs this help screen
@grep -E '^([\w\d/]+:)?([a-zA-Z0-9/_-]+:.*?##.*$$)|(^##)' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":"}{printf "\033[32m%-25s\033[0m %s\n", $$2, $$3}' | sed -e 's/\[32m##/[33m/'

up: ## Start project
./scripts/traefik.sh
@$(DOCKER_COMPOSE) up --detach --force-recreate
@cat info.txt

down: backend/down ## Stop project

sh: ## Connect to the PHP container with sh
@$(PHP_CONTAINER) sh

phpunit: ## Run phpunit
@$(PHP_CONTAINER) ./vendor/bin/phpunit

lint: ## Run linter
@$(PHP_CONTAINER) composer lint

build-images: ## Build the docker images required by this project
@$(DOCKER_COMPOSE) build

setup: build-images setup/configuration up setup/run-initial-commands up ## Setup and start the project

setup/configuration: ## Make sure this environment configuration is present
cp .env.example .env

setup/run-initial-commands: ## Setup this environment after its first startup
sleep 10
@$(PHP_CONTAINER) php artisan key:generate
@$(PHP_CONTAINER) php artisan migrate
@$(PHP_CONTAINER) php artisan db:seed
13 changes: 13 additions & 0 deletions docker-compose-helpers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
services:
app_setup:
build:
context: docker/php-fpm
depends_on:
- fpm
- webserver
volumes:
- "app-php-socket:/var/run"
- '.:/var/www/html'
entrypoint: /bin/sh -c "composer install; php artisan migrate; php artisan storage:link"
networks:
- common
84 changes: 84 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
services:
webserver:
build:
context: docker/caddy
depends_on:
- fpm
restart: unless-stopped
environment:
DOMAIN: photobook.localhost
volumes:
- '.:/var/www/html'
- "app-php-socket:/var/run"
- "app-caddy-data:/data"
- "app-caddy-config:/config"
- "./docker/caddy/Caddyfile:/etc/caddy/Caddyfile"
networks:
- engency_service_gateway
- common
healthcheck:
test: [ "CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:2019/metrics" ]
interval: 10s
timeout: 5s
retries: 3
labels:
- traefik.enable=true
- traefik.docker.network=engency_service_gateway
- traefik.http.services.webserver.loadbalancer.server.port=80
- traefik.http.routers.webserver.entrypoints=web
- traefik.http.routers.webserver.rule=Host(`photobook.localhost`)
- traefik.tcp.routers.webserver-ssl.entrypoints=websecure
- traefik.tcp.routers.webserver-ssl.rule=HostSNI(`photobook.localhost`)
- traefik.tcp.routers.webserver-ssl.tls.passthrough=true
- traefik.tcp.services.webserver-ssl.loadbalancer.server.port=443
fpm:
build:
context: docker/php-fpm
volumes:
- "app-php-socket:/var/run"
- '.:/var/www/html'
environment:
XDEBUG_MODE: '${XDEBUG_MODE:-debug,coverage}'
XDEBUG_CONFIG: '${XDEBUG_CONFIG:-client_host=host.docker.internal log_level=0}'
PHP_IDE_CONFIG: serverName=fpm
TZ: "UTC"
networks:
- common
extra_hosts:
- "host.docker.internal:host-gateway"
depends_on:
- mariadb
restart: on-failure
mariadb:
image: mariadb:12.3
ports:
- '${FORWARD_DB_PORT:-3306}:3306'
environment:
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
MYSQL_ROOT_HOST: "%"
MYSQL_DATABASE: '${DB_DATABASE}'
MYSQL_USER: '${DB_USERNAME}'
MYSQL_PASSWORD: '${DB_PASSWORD}'
TZ: "UTC"
volumes:
- 'app-mysql:/var/lib/mysql'
networks:
- common
restart: "no"
healthcheck:
interval: 30s
retries: 3
test:
[ "CMD", "healthcheck.sh", "--su-mysql", "--connect", "--innodb_initialized" ]
timeout: 5s
volumes:
app-mysql:
driver: local
app-php-socket:
app-caddy-data:
app-caddy-config:
networks:
common:
driver: bridge
engency_service_gateway:
external: true
39 changes: 39 additions & 0 deletions docker/caddy/Caddyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{$DOMAIN} {
log
header -Server
header Cross-Origin-Opener-Policy "same-origin"
header Cross-Origin-Resource-Policy "same-site"

handle {
root * /var/www/html/public
request_body {
max_size 10MB
}
php_fastcgi unix//var/run/php8-fpm.sock
encode zstd gzip
file_server
}

tls internal
}

:80 {
log
header -Server
header Cross-Origin-Opener-Policy "same-origin"
header Cross-Origin-Resource-Policy "same-site"

handle {
root * /var/www/html/public
request_body {
max_size 10MB
}
php_fastcgi unix//var/run/php8-fpm.sock
encode zstd gzip
file_server
}
}

:2019 {
metrics /metrics
}
15 changes: 15 additions & 0 deletions docker/caddy/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ARG CADDY_VERSION=2.10.2

FROM caddy:${CADDY_VERSION}-builder-alpine AS caddy_builder

RUN xcaddy build

FROM caddy:${CADDY_VERSION}

WORKDIR /var/www/html

COPY --from=caddy_builder /usr/bin/caddy /usr/bin/caddy

COPY ./startup.sh /var/www/startup.sh

CMD ["/var/www/startup.sh"]
3 changes: 3 additions & 0 deletions docker/caddy/startup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

caddy run --config /etc/caddy/Caddyfile --adapter caddyfile
49 changes: 49 additions & 0 deletions docker/php-fpm/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
FROM php:8.3-fpm-alpine

RUN apk add git

WORKDIR /var/www/html
ENV PATH /var/www/html:$PATH

RUN apk add --no-cache libzip-dev unzip libzip-dev libmcrypt-dev wget \
&& docker-php-ext-install pdo pdo_mysql zip exif pcntl bcmath

RUN apk add --no-cache shadow
RUN usermod -u 1000 www-data
RUN groupmod --gid 1000 www-data
RUN chown -R www-data:www-data /var/www

ENV COMPOSER_HOME /tmp
ENV COMPOSER_VERSION 2.10.1

RUN curl --silent --fail --location --retry 3 --output /tmp/installer.php --url https://raw.githubusercontent.com/composer/getcomposer.org/a5874d7ceecca18772d44ed19e7da5fd267ba0a4/web/installer \
&& php -r " \
\$signature = 'e0012edf3e80b6978849f5eff0d4b4e4c79ff1609dd1e613307e16318854d24ae64f26d17af3ef0bf7cfb710ca74755a'; \
\$hash = hash('sha384', file_get_contents('/tmp/installer.php')); \
if (!hash_equals(\$signature, \$hash)) { \
unlink('/tmp/installer.php'); \
echo 'Integrity check failed, installer is either corrupt or worse.' . PHP_EOL; \
exit(1); \
}" \
&& php /tmp/installer.php --no-ansi --install-dir=/usr/bin --filename=composer --version=${COMPOSER_VERSION} \
&& composer --ansi --version --no-interaction \
&& rm -f /tmp/installer.php

COPY ./www.conf /usr/local/etc/php-fpm.d/www.conf

# Install XDebug
ARG XDEBUG_VERSION="3.5.1"
ARG XDEBUG_CONFIG="client_host=172.17.0.1"
ARG PHP_IDE_CONFIG="serverName=fpm"

COPY xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini

RUN apk add --update linux-headers
RUN apk add --no-cache $PHPIZE_DEPS \
&& pecl install xdebug \
&& docker-php-ext-enable xdebug \
&& apk del $PHPIZE_DEPS

# Install GD
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/
RUN install-php-extensions gd
Loading