Skip to content

Commit 45ae69e

Browse files
authored
Use official FrankenPHP images + update makefile (#357)
1 parent c8550d3 commit 45ae69e

7 files changed

Lines changed: 113 additions & 104 deletions

File tree

.github/workflows/static.yml

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,32 @@ name: static analysis
2626

2727
jobs:
2828
psalm:
29-
uses: yiisoft/actions/.github/workflows/psalm.yml@master
30-
with:
31-
os: >-
32-
['ubuntu-latest']
33-
php: >-
34-
['8.2', '8.3', '8.4']
29+
name: PHP ${{ matrix.php }}-${{ matrix.os }}
3530

31+
runs-on: ${{ matrix.os }}
32+
33+
strategy:
34+
matrix:
35+
os:
36+
- ubuntu-latest
37+
php:
38+
- "8.2"
39+
- "8.3"
40+
- "8.4"
41+
42+
steps:
43+
- name: Checkout
44+
uses: actions/checkout@v4
45+
46+
- name: Install PHP with extensions
47+
uses: shivammathur/setup-php@v2
48+
with:
49+
coverage: none
50+
php-version: ${{ matrix.php }}
51+
tools: composer:v2, cs2pr
52+
53+
- name: Install Composer dependencies
54+
uses: ramsey/composer-install@v3
55+
56+
- name: Static analysis
57+
run: vendor/bin/psalm --shepherd --stats --output-format=checkstyle --no-cache --php-version=${{ matrix.php }} | cs2pr --graceful-warnings --colorize

Makefile

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,70 @@
11
.DEFAULT_GOAL := help
22

3-
# Run silent.
4-
MAKEFLAGS += --silent
5-
6-
RUN_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
7-
$(eval $(RUN_ARGS):;@:)
3+
CLI_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
4+
$(eval $(CLI_ARGS):;@:)
85

96
include docker/.env
107

11-
# Current user ID and group ID.
8+
# Current user ID and group ID
129
export UID=$(shell id -u)
1310
export GID=$(shell id -g)
1411

1512
export COMPOSE_PROJECT_NAME=${STACK_NAME}
13+
DOCKER_COMPOSE_DEV := docker compose -f docker/compose.yml -f docker/compose.dev.yml
14+
DOCKER_COMPOSE_TEST := docker compose -f docker/compose.yml -f docker/compose.test.yml
1615

17-
up: ## Up the dev environment.
18-
docker compose -f docker/compose.yml -f docker/compose.dev.yml up -d --remove-orphans
19-
20-
up-build: ## Up the dev environment rebuilding images.
21-
docker compose -f docker/compose.yml -f docker/compose.dev.yml up -d --remove-orphans --build
22-
23-
down: ## Down the dev environment.
24-
docker compose -f docker/compose.yml -f docker/compose.dev.yml down --remove-orphans
16+
#
17+
# Development
18+
#
2519

26-
exec: ## Run a command within the existing container.
27-
docker compose -f docker/compose.yml -f docker/compose.dev.yml exec app $(CMD) $(RUN_ARGS)
20+
build: ## Build docker images
21+
$(DOCKER_COMPOSE_DEV) build $(CLI_ARGS)
2822

29-
run: ## Run a command within a temporary container.
30-
docker compose -f docker/compose.yml -f docker/compose.dev.yml run --rm --entrypoint $(CMD) app $(RUN_ARGS)
23+
up: ## Up the dev environment
24+
$(DOCKER_COMPOSE_DEV) up -d --remove-orphans
3125

32-
run-test: ## Run a command in testing environment.
33-
docker compose -f docker/compose.yml -f docker/compose.test.yml run --rm --entrypoint $(CMD) app $(RUN_ARGS)
26+
down: ## Down the dev environment
27+
$(DOCKER_COMPOSE_DEV) down --remove-orphans
3428

35-
shell: CMD="/bin/sh" ## Get into container shell.
36-
shell: exec
29+
shell: ## Get into container shell
30+
$(DOCKER_COMPOSE_DEV) exec app /bin/sh
3731

38-
yii: CMD="./yii" ## Execute Yii command.
39-
yii: run
32+
yii: ## Execute Yii command
33+
$(DOCKER_COMPOSE_DEV) run --rm app ./yii $(CLI_ARGS)
34+
.PHONY: yii
4035

41-
composer: CMD="composer" ## Run Composer.
42-
composer: run
36+
composer: ## Run Composer
37+
$(DOCKER_COMPOSE_DEV) run --rm app composer $(CLI_ARGS)
4338

44-
codecept: CMD="./vendor/bin/codecept" ## Run Codeception.
45-
codecept: run-test
39+
codecept: ## Run Codeception
40+
$(DOCKER_COMPOSE_TEST) run --rm app ./vendor/bin/codecept $(CLI_ARGS)
4641

47-
psalm: CMD="./vendor/bin/psalm" ## Run Psalm.
48-
psalm: run
42+
psalm: ## Run Psalm
43+
$(DOCKER_COMPOSE_DEV) run --rm app ./vendor/bin/psalm $(CLI_ARGS)
4944

50-
rector: CMD="./vendor/bin/rector" ## Run Rector.
51-
rector: run
45+
rector: ## Run Rector
46+
$(DOCKER_COMPOSE_DEV) run --rm app ./vendor/bin/rector $(CLI_ARGS)
5247

5348
cs-fix:
54-
docker compose -f docker/compose.yml -f docker/compose.dev.yml run --rm --entrypoint ./vendor/bin/php-cs-fixer app fix --config=.php-cs-fixer.php --diff
49+
$(DOCKER_COMPOSE_DEV) run --rm app ./vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php --diff
5550

56-
build-prod: ## Build an image.
51+
#
52+
# Production
53+
#
54+
55+
prod-build: ## PROD | Build an image
5756
docker build --file docker/Dockerfile --target prod --pull -t ${IMAGE}:${IMAGE_TAG} .
5857

59-
push-prod: ## Push image to repository.
58+
prod-push: ## PROD | Push image to repository
6059
docker push ${IMAGE}:${IMAGE_TAG}
6160

62-
deploy-prod: ## Deploy to production.
61+
prod-deploy: ## PROD | Deploy to production
6362
docker -H ${PROD_SSH} stack deploy --with-registry-auth -d -c docker/compose.yml -c docker/compose.prod.yml ${STACK_NAME}
6463

64+
#
65+
# Other
66+
#
67+
6568
# Output the help for each task, see https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
66-
.PHONY: help
6769
help: ## This help.
6870
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)

docker/.env

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
STACK_NAME=app
22

3+
#
4+
# Development
5+
#
6+
7+
DEV_PORT=80
8+
# XDEBUG_MODE=develop,debug
9+
10+
#
11+
# Production
12+
#
13+
314
PROD_HOST=app.example.com
415
PROD_SSH="ssh://docker-web"
516

617
IMAGE=app
718
IMAGE_TAG=latest
8-
9-
DEV_PORT=80
10-
11-
# XDEBUG_MODE=develop,debug

docker/Dockerfile

Lines changed: 32 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,46 @@
1-
FROM composer/composer:latest-bin AS composer
1+
FROM composer/composer:2-bin AS composer
2+
3+
FROM dunglas/frankenphp:1-php8.2-bookworm AS base
4+
5+
RUN apt update && apt -y install \
6+
unzip
7+
8+
RUN install-php-extensions \
9+
opcache \
10+
mbstring \
11+
intl \
12+
dom \
13+
ctype \
14+
curl \
15+
phar \
16+
openssl \
17+
xml \
18+
xmlwriter \
19+
simplexml \
20+
pdo
21+
22+
#
23+
# Development
24+
#
225

3-
FROM ghcr.io/shyim/wolfi-php/frankenphp:8.2 AS base
4-
ARG UID=10001
5-
ARG GID=10001
6-
RUN <<SH
7-
set -eo pipefail
8-
set -x
9-
10-
# Add www-data group and user.
11-
addgroup -g ${GID} -S www-data
12-
adduser -u ${UID} -D -S -G www-data www-data
13-
14-
# Set volume permissions.
15-
mkdir -p /data /config /app/runtime && \
16-
chown -R www-data:www-data /data /config /app/runtime
26+
FROM base AS dev
27+
RUN install-php-extensions \
28+
xdebug
29+
COPY --from=composer /composer /usr/bin/composer
30+
USER www-data
1731

18-
# Install extra packages.
19-
apk add --no-cache \
20-
php-frankenphp-8.2-opcache \
21-
php-frankenphp-8.2-mbstring \
22-
php-frankenphp-8.2-intl \
23-
php-frankenphp-8.2-dom \
24-
php-frankenphp-8.2-ctype \
25-
php-frankenphp-8.2-curl \
26-
php-frankenphp-8.2-phar \
27-
php-frankenphp-8.2-openssl \
28-
php-frankenphp-8.2-xml \
29-
php-frankenphp-8.2-xmlwriter \
30-
php-frankenphp-8.2-simplexml \
31-
php-frankenphp-8.2-pdo
32-
SH
32+
#
33+
# Production
34+
#
3335

3436
FROM base AS prod-builder
3537
COPY --from=composer /composer /usr/bin/composer
36-
3738
COPY .. /app
38-
3939
RUN --mount=type=cache,target=/tmp/cache \
40-
<<SH
41-
set -eo pipefail
42-
set -x
43-
4440
composer install --no-dev --no-progress --no-interaction --classmap-authoritative && \
4541
rm composer.lock composer.json
46-
SH
4742

4843
FROM base AS prod
4944
ENV APP_ENV=prod
50-
5145
COPY --from=prod-builder --chown=www-data:www-data /app /app
5246
USER www-data
53-
54-
FROM base AS dev
55-
RUN <<SH
56-
set -eo pipefail
57-
set -x
58-
59-
# Install extra packages for dev only.
60-
apk add --no-cache \
61-
php-frankenphp-8.2-xdebug
62-
SH
63-
64-
COPY --from=composer /composer /usr/bin/composer
65-
USER www-data

docker/compose.dev.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ services:
44
dockerfile: docker/Dockerfile
55
context: ..
66
target: dev
7-
args:
8-
UID: ${UID}
9-
GID: ${GID}
7+
user: ${UID}:${GID}
108
environment:
119
XDEBUG_MODE: "${XDEBUG_MODE:-develop}"
1210
APP_ENV: "${APP_ENV:-dev}"

docker/compose.test.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ services:
44
dockerfile: docker/Dockerfile
55
context: ..
66
target: dev
7-
args:
8-
UID: ${UID}
9-
GID: ${GID}
7+
user: ${UID}:${GID}
108
environment:
119
XDEBUG_MODE: "off"
1210
APP_ENV: "test"

psalm.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
findUnusedCode="false"
66
ensureOverrideAttribute="false"
77
strictBinaryOperands="false"
8+
cacheDirectory="/app/runtime/psalm-cache"
89
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
910
xmlns="https://getpsalm.org/schema/config"
1011
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"

0 commit comments

Comments
 (0)