Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Dockerfile for development #945

Open
wants to merge 2 commits into
base: 2.0
Choose a base branch
from

Conversation

Head0nF1re
Copy link

What is the reason for this PR?

  • Dockerfile to build an image with the FakerPHP dev dependencies.

  • It doesn't impact end users, it just improves the DX (Developer Experience) for anyone that wants to contribute to the repo without having to worry about installing any dependency (e.g. php, composer, make) on the host machine.

You just need to:

  1. Build the image: docker build -t php8.3-composer .
  2. Add an alias: alias php8.3="docker run -it --rm -v .:/app -w /app php8.3-composer"
  3. Use it: php8.3 make cs

Note:

  • The script that is added with ADD is meant to facilitate the installation of extensions. You can verify that the script is even mentioned in the README of the offical PHP image:

If you are having difficulty figuring out which Debian or Alpine packages need to be installed before docker-php-ext-install, then have a look at the install-php-extensions project⁠. This script builds upon the docker-php-ext-* scripts and simplifies the installation of PHP extensions by automatically adding and removing Debian (apt) and Alpine (apk) packages.

  • The image defaults to PHP version 8.3 since there seems to be a dependency that requires a max of 8.3.X. Composer defaults to latest. You can override these defaults using docker build --build-args, allowing you to have multiple versions to work with (by setting multiple alias).

Let me know what you think, I will add some info to the README if you find this useful.

- Dockerfile to build an image with the FakerPHP dev dependencies.
  Allows devs to work on the repo without having to install any
  dependencies (e.g. php, composer, make) on the host machine.
Dockerfile Outdated
gzip \
unzip

ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use the same mechanic here as with composer: copying the script from the docker image

Copy link
Author

@Head0nF1re Head0nF1re Feb 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it would be fine. ADD needs to download the file each time to calculate the hash and decide if it should invalidate the cache, using the image would skip the downloading part which is better.

We just need to add some info in the README warning about potentially stale images and the need to use build --pull as needed. Could also use something like watchtower but since this is just for local development I don't see a need

Copy link
Author

@Head0nF1re Head0nF1re Feb 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the ADD and added the extension-installer image

- Add extension-install image instead of using ADD.
- Remove gzip since it's not needed.
- Change USERNAME to FakerPHP.
@pimjansen
Copy link

Is it an idea to also integrate our tooling to run via docker instead? Since right now, what is a solid way to run stuff without complex cli commands?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants