yiisoft / yii2-docker

Official Docker images suitable for Yii 2.0
https://www.yiiframework.com/
BSD 3-Clause "New" or "Revised" License
381 stars 202 forks source link

yiisoftware/yii2-php:7.4-fpm + mac m1 architecture #148

Closed dsx90 closed 1 year ago

dsx90 commented 2 years ago

Can you build an image for the same architecture for m1 processors? In principle, I was able to rebuild locally by taking the original dockerfile and adding PHP_BASE_IMAGE_VERSION instead php:7.4.28-fpm@sha256:debf3848d5407dbdd45c2c01844f7ccc4e35902a0f6ff557dbc3e634b60e87e6 and getting a 10-fold increase in productivity. I think you will be able to do it more correctly.

schmunk42 commented 2 years ago

What is special about this image php:7.4.28-fpm@sha256:debf3848d5407dbdd45c2c01844f7ccc4e35902a0f6ff557dbc3e634b60e87e6 and where did you find the tag/hash?

dsx90 commented 2 years ago

https://hub.docker.com/layers/php/library/php/7.4-fpm/images/sha256-debf3848d5407dbdd45c2c01844f7ccc4e35902a0f6ff557dbc3e634b60e87e6?context=explore But the hash is not so mandatory it is demonstrated to indicate that there is an assembly for arm processors https://github.com/yiisoft/yii2-docker/issues/129 I also found this topic here and added a solution. I would be glad if you add it to the image. In my opinion, the image simply needs to be rebuilt with the updated php

schmunk42 commented 2 years ago

How can we build an image for a specific processor-arch with docker-compose?

Current build instruction: https://github.com/yiisoft/yii2-docker/blob/master/.github/workflows/docker-image.yml#L120

dsx90 commented 2 years ago

Rebuild the image by pulling up the updated base images

schmunk42 commented 2 years ago

We're doing nightly builds: https://hub.docker.com/repository/docker/yiisoftware/yii2-php/tags?page=1&ordering=last_updated - so they should be the latest images.

dsx90 commented 2 years ago

Then why here https://hub.docker.com/r/yiisoftware/yii2-php/tags only one OS/ARCH linux/amd64 architecture is supported, although in the original image https://hub.docker.com/layers/php/library/php/7.4-fpm/images/sha256-debf3848d5407dbdd45c2c01844f7ccc4e35902a0f6ff557dbc3e634b60e87e6?context=explore there are about 8 of them

schmunk42 commented 2 years ago

I have no experience with multi-platform builds.

You can either specify that in the Dockerfile https://docs.docker.com/engine/reference/builder/#from

Or docker-compose.yml https://github.com/docker/docker.github.io/blob/master/compose/compose-file/compose-file-v2.md#platform

Which one would be needed (or both)?

Which platforms should we support? CC: @yiisoft/core-developers Might use much more build resources.

Can find m1 in the list: Bildschirmfoto vom 2022-04-14 15-34-17

We also need to check if GitHub actions support other platforms.

PRs also in WIP welcome, I won't have much time for this.

dsx90 commented 2 years ago

linux/arm64/v8

lacek commented 2 years ago

multi-arch builds would be appreciated as yiisoftware/yii2-php:7.4-apache with SSL enabled won't run on M1 at the moment.

Prerequisite:

Steps to reproduce:

mkdir web
echo 'It works!' > web/index.html

# test php:7.4-apache
docker run --name test_php -d -v $PWD/web:/var/www/html/ -p 8080:80 php:7.4-apache
curl http://localhost:8080
# It works!

# test php:7.4-apache with ssl module enabled
cat <<EOF > Dockerfile-php
FROM php:7.4-apache
RUN a2enmod ssl
EOF
docker build -t test_php_ssl -f Dockerfile-php .
docker run --name test_php_ssl -d -v $PWD/web:/var/www/html/ -p 8081:80 test_php_ssl
curl http://localhost:8081
# It works!

# test yiisoftware/yii2-php:7.4-apache
docker run --name test_yii2 -d -v $PWD/web:/app/web -p 8082:80 yiisoftware/yii2-php:7.4-apache
curl http://localhost:8082
# It works!

# test yiisoftware/yii2-php:7.4-apache with ssl module enabled
cat <<EOF > Dockerfile-yii2
FROM yiisoftware/yii2-php:7.4-apache
RUN a2enmod ssl
EOF
docker build -t test_yii2_ssl -f Dockerfile-yii2 .
docker run --name test_yii2_ssl -d -v $PWD/web:/app/web -p 8083:80 test_yii2_ssl
curl http://localhost:8083
# curl: (7) Failed to connect to localhost port 8083: Connection refused
docker logs test_yii2_ssl
# usermod: no changes
# AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.4. Set the 'ServerName' directive globally to suppress this message
# [Mon Jul 11 13:41:02.758036 2022] [core:emerg] [pid 1] (95)Operation not supported: AH00023: Couldn't create the mpm-accept mutex
# (95)Operation not supported: could not create accept mutex
# AH00015: Unable to open logs

# clean up
docker rm -f test_php test_php_ssl test_yii2 test_yii2_ssl
docker rmi test_php_ssl test_yii2_ssl
schmunk42 commented 2 years ago

I'd recommend to add this to the docs: https://github.com/yiisoft/yii2-docker/tree/master/docs Can you create a PR?

We're building with GitHub Actions, so we're bound to their infrastructure.

zemkogabor commented 1 year ago

Hello!

This is how I managed to build a custom php image for several architectures:

docker buildx build -t <your_registry>/php-custom:<version> . --platform=linux/arm64,linux/amd64 --push

Reference: https://github.com/zemkogabor/php-file-service#docker

We can use the same in the github action: https://blog.thesparktree.com/docker-multi-arch-github-actions This will not work if the dockerfile contains some amd64 specific package.

yepes commented 1 year ago

any updates on this?

schmunk42 commented 1 year ago

I couldn't figure out how to do that with GH-actions, PRs still welcome.

zemkogabor commented 1 year ago

My biggest problem with the arm64 build is that it's very slow on Github. Currently, Github does not have any arm64 architecture build servers. A possible workaround is to separate the builds into separate actions, so that the amd64 can be ready quickly, while the arm64 may take more than an hour to complete. Here's the example: https://github.com/AventailLtd/docker-php/commit/14d4ed576d66972854e923236531bc5cbd066f50

Returning to the PR. If I have a bit more time, I'll try to apply buildx to the Yii2 docker, if successful locally, I'll open a PR, but I can't promise anything at the moment.

yepes commented 1 year ago

is it possible to do something on the client (developer) side to have this working? I don't have any experience on GH actions so can't help here