Skip to content

Dev Container and making api-platform more friendly to new users #2472

@ili101

Description

@ili101

Description
I'm trying to use API platform for the first time. So far it took me 2 days just to set the basics up (mostly because the 3.0.10 Dockerfile issue, #2471, some Docker problems, trying to set up XDEBUG, understanding the basics and so).
I prefer using VSCode and Docker and not PhpStorm as I develop in multiple languages and I don't want a different IDE for every thing I do.
And with Devcontainer I don't need PHP or anything installed on my OS, it also can take care of all the configurations for you.

Example
I managed to get the basic working in here https://github.com/ili101/api-platform/tree/Devcontainer
To use this and get a working development environment basically all you need is:

  1. Make sure you have VSCode and Docker installed.
  2. git clone the code.
  3. open VSCode on the folder, it will popup a massage asking if you want to open the detected Dev Container, yes.
  4. you are set up with PHP Intelephense, PHP Debug and Symfony Extensions, to line debug just F5 and and a brakepoint as xdebug is set up.

Some considerations I encountered are:

  1. In the exiting api Dockerfile only the api folder is mapped (to /srv/app/), it's not comfortable to develop without the full repo in your IDE. to bypassed this by mapping the root of the repo to /workspace (so basically api is mapped twice, and I needed to point xdebug to the new mapped folder otherwise it will only work if you put the breakpoints on /srv/app/ and not /workspace).
    Another option instead of mapping twice is to map the root to /srv but as you currently "rename" "api" to "app" the stuff pointing to /srv/app/ will need to point to /srv/api/ instead.
  2. the Alpine Linux is a bit slim and less comfortable/compatible to develop on as a dev environment, maybe it will be better to create a separate api Dockerfile in the /devcontainer folder that is based on something like mcr.microsoft.com/devcontainers/php:1-8.2-bullseye.
    For example the devcontainer.json "features" option (auto install optional stuff in your container) do not work on Alpine.

For reference I found that Laravel also have a way to set devcontainer for you automaticly with curl -s "https://laravel.build/example-app?with=mysql,redis&devcontainer.

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions