Skip to content

Conversation

zeriyoshi
Copy link
Contributor

@zeriyoshi zeriyoshi commented Aug 2, 2024

Add initial Development Containers support.

This is an enhancement to the development environment and does not affect the implementation of PHP itself in anyway.

It brings the following benefits:

  • Simplifies building a development environment.
  • Be able to develop using GitHub Codespaces.

Includes experimental PostgreSQL support using docker compose, Support for other built-in extensions is difficult for me to determine and therefore not included.

Usage

Local Visual Studio Code

  1. Open repository directory
  2. Click Open Folder in Container
  3. Choose php-dev (for Local)

GitHub Codespaces

  1. Click <> Code button
  2. Choose Codespaces tab
  3. Click + link

(Default 2-core is quite slow, so ... -> New with options... to customize the configuration)

If necessary, I would like to solicit feedback on this PR on Internals ML.

KentarouTakeda added a commit to KentarouTakeda/docker-php-src that referenced this pull request Aug 5, 2024
@zeriyoshi zeriyoshi marked this pull request as ready for review August 6, 2024 02:21
@petk
Copy link
Member

petk commented Aug 6, 2024

I should test this a bit but the .vscode directory will be most likely in many cases additionally changed locally by the developer's VS code editor which will make it a bit difficult to use the Git repository. The .vscode directory probably shouldn't be committed to the php-src repo.

@cmb69
Copy link
Member

cmb69 commented Aug 6, 2024

The .vscode directory probably shouldn't be committed to the php-src repo.

Indeed. That could easily overwrite the developer's local settings (it would overwrite my settings.json, for instance).

And I wonder why .devcontainer should be added to php-src. Isn't that something every developer may use and configure as appropriate for them?

@zeriyoshi
Copy link
Contributor Author

Indeed. I removed the .vscode directory and added it to gitignore.

@cmb69
I'm considering whether we could promote more contributions by making it easier to set up the build environment for php-src. Additionally, I thought it might be convenient if the devcontainer definition is included in the repo, as it would allow development to start using GitHub Codespaces with just a web browser.

However, I understand there may be various opinions on whether to include the devcontainer definition in the repo. Personally, I would find it helpful even if it's just added to the .gitignore file.

@petk
Copy link
Member

petk commented Aug 7, 2024

Indeed. I removed the .vscode directory and added it to gitignore.

Rather add it to the local .gitignore file defined in your Git configuration (~/.gitconfig). See this explanation in Gitignore:

# These files are generated during building or development and are intentionally
# untracked to ignore by Git. For other development environment specific files,
# such as editor configuration, a good practice is to exclude them using the
# .git/info/exclude in the cloned repository or a global .gitignore file.

This was done intentionally, because the macOS has more files to be ignored, and other editors have other similar directories. This is very common practice in Git repositories.

About Devcontainers I think idea is ok. I'll test this a bit...

@zeriyoshi
Copy link
Contributor Author

zeriyoshi commented Aug 8, 2024

OK. .gitignore was reverted.

Rather add it to the local .gitignore file defined in your Git configuration (~/.gitconfig). See this explanation in Gitignore:

Essentially, I prefer to include .vscode/ and other editor configuration files under git version control in my repositories, so I'd like to manually exclude these files.

@zeriyoshi
Copy link
Contributor Author

How about including an EditorConfig configuration file? While php-src basically adopts tab indentation with a width of 4, many recent editors default to space indentation, so this might be helpful. Since EditorConfig is editor-independent, it might be a good idea to include it.

@petk
Copy link
Member

petk commented Aug 8, 2024

How about including an EditorConfig configuration file? While php-src basically adopts tab indentation with a width of 4, many recent editors default to space indentation, so this might be helpful. Since EditorConfig is editor-independent, it might be a good idea to include it.

The .editorconfig file is in php-src already.

@zeriyoshi
Copy link
Contributor Author

@petk
I was so foolish, how embarrassing! Thank you very much 😭

@zeriyoshi
Copy link
Contributor Author

Currently, it appears that PHP tests on GitHub Actions are being conducted on Ubuntu 22.04. The environment included in this PR is based on Debian 12 Bookworm. Would it be more appropriate to use an Ubuntu-based environment?

Personally, I prefer to choose Debian because Ubuntu's mirrors for architectures other than amd64 are poor. When setting up the environment from Japan on arm64 macOS, it takes an extremely long time with Ubuntu.

@cmb69
Copy link
Member

cmb69 commented Aug 17, 2024

It might actually be good to not confine to a certain distro, so using Debian here seems like a win.

@ilnytskyi
Copy link

ilnytskyi commented Oct 29, 2024

This might be good to add default debugging options and tools as well

I once played with VSCode and docker, I managed to prepere a config like this for attaching to php build-in web server e.g. that was started via php -S and running and profiling from CLI (but only managed to hardcode it to /home/www/src/apps/test.php file.)

Maybe should be adjusted to use "${relativeFile}", as described in https://php.github.io/php-src/introduction/ides/visual-studio-code.html#gdb

Additionally it might be nice to include some tracer with timeline view features. Valgrind's view are too sampled, but uftrace seemed to work well for profiling and reverse engineering https://github.com/namhyung/uftrace just enough to drop trace file into chrome or any other compatible viewer.

My VSCode config.

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "C++ GDB Attach in docker container",
            "type": "cppdbg",
            "request": "attach",
            "program": "/root/php-bin/DEBUG/bin/php",
            "processId": "${command:pickRemoteProcess}",
            "pipeTransport": {
                "pipeCwd": "${workspaceRoot}",
                "pipeProgram": "docker",
                "pipeArgs": [
                    "compose",
                    "exec", 
                    "-i",
                    "cdev_src", 
                    "sh",
                    "-c"
                ],
                "debuggerPath": "/usr/bin/gdb"
            },
            "sourceFileMap": {
                "/home/www/src": "${workspaceFolder}/src"
            },
            "logging": { "trace": false, "traceResponse": false },

                "MIMode": "gdb",
                "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description":  "Set Disassembly Flavor to Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                },
                {
                    "description":  "Load PHP debug functions",
                    "text": "source /home/www/src/php-src/.gdbinit",
                    "ignoreFailures": false
                }
                ]
            },
            {
                "name": "GDB Launch test.php in Docker Container",
                "type": "cppdbg",
                "request": "launch",
                "program": "~/php-bin/DEBUG/bin/php",
                "args": ["/home/www/src/apps/test.php"],
                "stopAtEntry": false,
                "cwd": "/home/www/src",
                "pipeTransport": {
                    "pipeCwd": "${workspaceRoot}",
                    "pipeProgram": "docker",
                    "pipeArgs": [
                        "compose",
                        "exec",
                        "-i",
                        "-u",
                        "www",
                        "cdev_src",
                        "sh",
                        "-c"
                    ],
                    "debuggerPath": "/usr/bin/gdb"
                },
                "sourceFileMap": {
                    "/home/www/src": "${workspaceFolder}/src"
                },
                "logging": {
                    "trace": false,
                    "traceResponse": false
                },
                "MIMode": "gdb",
                "setupCommands": [
                    {
                        "description": "Enable pretty-printing for gdb",
                        "text": "-enable-pretty-printing",
                        "ignoreFailures": true
                    },
                    {
                        "description": "Set Disassembly Flavor to Intel",
                        "text": "-gdb-set disassembly-flavor intel",
                        "ignoreFailures": true
                    },
                    {
                        "description": "Load PHP debug functions",
                        "text": "source /home/www/src/php-src/.gdbinit",
                        "ignoreFailures": false
                    }
                ]
            }
    ]
}

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.

4 participants