laravel / sail

Docker files for running a basic Laravel application.
https://laravel.com/docs/sail
MIT License
1.63k stars 468 forks source link

Unable to use Sail with GitHub Codespaces #550

Closed garrettw closed 1 year ago

garrettw commented 1 year ago

Description:

My repo: https://github.com/garrettw/laravel-skeleton

Not sure if this is the right place to report this bug, but I found someone else that had this error yesterday and they said changing their Dockerfile container config fixed the problem -- so I thought I'd start here and see if anyone knew what part of this setup might be incompatible with Codespaces.

I am trying to create a new codespace based on the devcontainer file that Laravel Sail generated -- I haven't modified the docker-compose file. When I create the codespace, the build fails. Below is the creation log.

I have a hunch as to what might be going on... maybe Codespaces doesn't support multi-container compose files and just wants to throw everything in a single container. Haven't tested this theory yet. Don't think that's it... found evidence around the web of people being able to run multi-container setups. Also I'm seeing something about a docker-in-docker setup... is that the only way to get this working?

=================================================================================
2023-02-15 00:30:46.246Z: Configuration starting...
2023-02-15 00:30:46.252Z: Cloning...

=================================================================================
2023-02-15 00:30:46.274Z: Creating container...
2023-02-15 00:30:46.276Z: $ devcontainer up --id-label Type=codespaces --workspace-folder /var/lib/docker/codespacemount/workspace/laravel-skeleton --mount type=bind,source=/.codespaces/agent/mount/cache,target=/vscode --user-data-folder /var/lib/docker/codespacemount/.persistedshare --container-data-folder .vscode-remote/data/Machine --container-system-data-folder /var/vscode-remote --log-level trace --log-format json --update-remote-user-uid-default never --mount-workspace-git-root false --skip-non-blocking-commands --skip-post-create --remove-existing-container --config "/var/lib/docker/codespacemount/workspace/laravel-skeleton/.devcontainer/devcontainer.json" --override-config /root/.codespaces/shared/merged_devcontainer.json --default-user-env-probe loginInteractiveShell --container-session-data-folder /workspaces/.codespaces/.persistedshare/devcontainers-cli/cache
2023-02-15 00:30:46.505Z: @devcontainers/cli 0.28.0. Node.js v14.21.2. linux 5.4.0-1103-azure x64.
2023-02-15 00:30:47.668Z: Error: Command failed: docker-compose -f /var/lib/docker/codespacemount/workspace/laravel-skeleton/docker-compose.yml -f /var/lib/docker/codespacemount/.persistedshare/docker-compose.codespaces.yml config
2023-02-15 00:30:47.670Z:     at vc (/usr/lib/node_modules/@microsoft/vscode-dev-containers-cli/dist/spec-node/devContainersSpecCLI.js:1906:867)
2023-02-15 00:30:47.671Z:     at processTicksAndRejections (internal/process/task_queues.js:95:5)
2023-02-15 00:30:47.673Z:     at async rie (/usr/lib/node_modules/@microsoft/vscode-dev-containers-cli/dist/spec-node/devContainersSpecCLI.js:1872:1370)
2023-02-15 00:30:47.674Z:     at async tie (/usr/lib/node_modules/@microsoft/vscode-dev-containers-cli/dist/spec-node/devContainersSpecCLI.js:1854:2396)
2023-02-15 00:30:47.678Z: {"outcome":"error","message":"Command failed: docker-compose -f /var/lib/docker/codespacemount/workspace/laravel-skeleton/docker-compose.yml -f /var/lib/docker/codespacemount/.persistedshare/docker-compose.codespaces.yml config","description":"An error occurred retrieving the Docker Compose configuration."}
2023-02-15 00:30:47.680Z:     at async Fie (/usr/lib/node_modules/@microsoft/vscode-dev-containers-cli/dist/spec-node/devContainersSpecCLI.js:1921:2266)
2023-02-15 00:30:47.689Z:     at async $f (/usr/lib/node_modules/@microsoft/vscode-dev-containers-cli/dist/spec-node/devContainersSpecCLI.js:1921:3239)
2023-02-15 00:30:47.695Z:     at async eoe (/usr/lib/node_modules/@microsoft/vscode-dev-containers-cli/dist/spec-node/devContainersSpecCLI.js:2045:17247)
2023-02-15 00:30:47.699Z:     at async Qse (/usr/lib/node_modules/@microsoft/vscode-dev-containers-cli/dist/spec-node/devContainersSpecCLI.js:2045:16993)
2023-02-15 00:30:47.702Z: devcontainer process exited with exit code 1

====================================== ERROR ====================================
2023-02-15 00:30:47.704Z: Failed to create container.
=================================================================================
2023-02-15 00:30:47.707Z: Error: Command failed: docker-compose -f /var/lib/docker/codespacemount/workspace/laravel-skeleton/docker-compose.yml -f /var/lib/docker/codespacemount/.persistedshare/docker-compose.codespaces.yml config
2023-02-15 00:30:47.710Z: Error Code: 1302

====================================== ERROR ====================================
2023-02-15 00:30:47.713Z: Container creation failed.
=================================================================================
2023-02-15 00:30:47.715Z: 

===================================== WARNING ===================================
2023-02-15 00:30:47.718Z: Creating recovery container.
=================================================================================

=================================================================================
2023-02-15 00:30:48.127Z: Creating container...
2023-02-15 00:30:48.130Z: $ devcontainer up --id-label Type=codespaces --workspace-folder /var/lib/docker/codespacemount/workspace/laravel-skeleton --mount type=bind,source=/.codespaces/agent/mount/cache,target=/vscode --user-data-folder /var/lib/docker/codespacemount/.persistedshare --container-data-folder .vscode-remote/data/Machine --container-system-data-folder /var/vscode-remote --log-level trace --log-format json --update-remote-user-uid-default never --mount-workspace-git-root false --skip-non-blocking-commands --skip-post-create --config "/var/lib/docker/codespacemount/workspace/laravel-skeleton/.devcontainer/devcontainer.json" --override-config /root/.codespaces/shared/merged_devcontainer.json --default-user-env-probe loginInteractiveShell --container-session-data-folder /workspaces/.codespaces/.persistedshare/devcontainers-cli/cache
2023-02-15 00:30:48.340Z: @devcontainers/cli 0.28.0. Node.js v14.21.2. linux 5.4.0-1103-azure x64.
2023-02-15 00:31:03.747Z: $alpine -c echo Container started
2023-02-15 00:31:04.057Z: Container started
2023-02-15 00:31:04.386Z: Outcome: success User: vscode WorkspaceFolder: /workspaces/laravel-skeleton
2023-02-15 00:31:04.393Z: devcontainer process exited with exit code 0

=================================================================================
2023-02-15 00:31:05.800Z: Running blocking commands...
2023-02-15 00:31:05.802Z: $ devcontainer up --id-label Type=codespaces --workspace-folder /var/lib/docker/codespacemount/workspace/laravel-skeleton --mount type=bind,source=/.codespaces/agent/mount/cache,target=/vscode --user-data-folder /var/lib/docker/codespacemount/.persistedshare --container-data-folder .vscode-remote/data/Machine --container-system-data-folder /var/vscode-remote --log-level trace --log-format json --update-remote-user-uid-default never --mount-workspace-git-root false --skip-non-blocking-commands --expect-existing-container --config "/var/lib/docker/codespacemount/workspace/laravel-skeleton/.devcontainer/devcontainer.json" --override-config /root/.codespaces/shared/merged_devcontainer.json --default-user-env-probe loginInteractiveShell --container-session-data-folder /workspaces/.codespaces/.persistedshare/devcontainers-cli/cache
2023-02-15 00:31:06.013Z: @devcontainers/cli 0.28.0. Node.js v14.21.2. linux 5.4.0-1103-azure x64.
2023-02-15 00:31:06.270Z: Outcome: success User: vscode WorkspaceFolder: /workspaces/laravel-skeleton
2023-02-15 00:31:06.342Z: devcontainer process exited with exit code 0

=================================================================================
2023-02-15 00:31:06.427Z: Configuring codespace...

=================================================================================
2023-02-15 00:31:06.457Z: Finished configuring codespace.
driesvints commented 1 year ago

Isn't this a duplicate of https://github.com/laravel/sail/issues/541 ?

garrettw commented 1 year ago

No, the nature of the error is different, but I can try commenting out the mysql volume and see what it does.

github-actions[bot] commented 1 year ago

Thank you for reporting this issue!

As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub.

If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team.

Thank you!

garrettw commented 1 year ago

Crossposted to Codespaces discussion board. https://github.com/orgs/community/discussions/48069

Firdavs9512 commented 1 year ago

Laravel sail error for: php artisan sail:install

#0 80.67 Setting up python3.10-minimal (3.10.6-1~22.04.2) ...
#0 81.03 [Errno 13] Permission denied: '/usr/lib/python3.10/__pycache__/__future__.cpython-310.pyc.139764667144704'dpkg: error processing package python3.10-minimal (--configure):
#0 81.03  installed python3.10-minimal package post-installation script subprocess returned error exit status 1
#0 81.47 Errors were encountered while processing:
#0 81.47  python3.10-minimal
#0 81.50 E: Sub-process /usr/bin/dpkg returned an error code (1)
------
jbreuer95 commented 1 year ago

I think the first mayor problem is that the docker-compose.yml is referencing a file that is in the vendor folder that doesnt exist yet

context: ./vendor/laravel/sail/runtimes/8.2
ItsReddi commented 1 year ago

In this case the issue is not only codespaces not working. Because the devcontainer is not self-containing. The issue is the same as mentioned in docs if you want to you sail in a project that already exists you need to install sail via composer first if you freshly cloned the project.

That's the same issue that codespaces has.

So the devcontainer should be changed do be self-containing & not rely on any "vendor" stuff that cannot exist if you clone your repository.

First fix could be to publish the runtime images on hub and reference them as image in docker-compose.yaml instead of building from vendor.

or running php artisan sail:publish

Anyway... the devcontainer.json setup is not "newcomer" friendly

garrettw commented 1 year ago

@jbreuer95 Good catch!

@ItsReddi Thanks for your insights as well. This was actually a fresh project including Sail, not adding Sail to an existing project, but you are still correct about the rest.

I will see if I can figure out some workaround based on this info.

ijpatricio commented 1 year ago

Hey @garrettw , if you want to install composer dependencies with Docker, while not having composer installed, do this:

docker run --rm -u "$(id -u):$(id -g)" -v "$(pwd):/app" -w /app composer:2 composer install --ignore-platform-reqs

Also, I'll try to look at your repo, since you left the link 👍

ijpatricio commented 1 year ago

Ok, so a few issues:

The thing got working. Kind of. Because then it also needs the other usual steps, like .env file, composer install, key:generate, storage:link, etc

image

I've recently contributed an example on Gitpod which is solves the same problem as Codespaces, and I have set it up here: https://github.com/gitpod-samples/template-php-laravel-mysql/blob/main/.gitpod.yml

There is a multitude of things to do to put it to work, and I don't know Codespaces enough to do the other steps right now.

But be assured, there is nothing wrong with the current Sail repo. Wether it has a template ready for Codespaces, it's a separate discussion.

The link I provided should be of guidance. Have a nice one!

ijpatricio commented 1 year ago

Further more, you can have a go in your browser, just by visiting: https://gitpod.io/#https://github.com/gitpod-samples/template-php-laravel-mysql

image

nunomaduro commented 1 year ago

@garrettw Can you check @ijpatricio's solution? Thanks!

garrettw commented 1 year ago

@ijpatricio @nunomaduro The solution that I have settled on for the moment, which seems to work at least well enough to get the containers going, is committing the entire laravel/sail repo into a subfolder in my repo (which required renaming its .git folder to make it work). It's certainly not ideal, but in the future I will probably look into doing what you have done, running composer as a prerequisite, if it is possible/workable with Codespaces.

Daniel-Mendes commented 1 year ago

Ok, so a few issues:

  • When the environment starts, it's like starting empty, with the source code of the repo. So, vendor directory is not there. What I did here was to publish sail assets locally: php artisan sail:publish
  • This is not enough, because Sail is expected to be brought up by the executable ./vendor/bin/sail. Inside, in its magic, it will figure out what user_id and group_id to use. What I did here was to default in the docker-compose.yml to 1000:1000, since Codespaces is running docker compose up not by ./vendor/bin/sail up and its magic. image

The thing got working. Kind of. Because then it also needs the other usual steps, like .env file, composer install, key:generate, storage:link, etc

image

I've recently contributed an example on Gitpod which is solves the same problem as Codespaces, and I have set it up here: https://github.com/gitpod-samples/template-php-laravel-mysql/blob/main/.gitpod.yml

There is a multitude of things to do to put it to work, and I don't know Codespaces enough to do the other steps right now.

But be assured, there is nothing wrong with the current Sail repo. Wether it has a template ready for Codespaces, it's a separate discussion.

The link I provided should be of guidance. Have a nice one!

I've followed this instructions and added the Laravel magic in .devcontainer/devcontainer.json :

 "postCreateCommand": "chown -R 1000:1000 /var/www/html && cp .env.example .env && composer install && php artisan key:generate && php artisan storage:link --force && php artisan migrate --force --seed && npm install",
 "postStartCommand": "npm run dev",

It works !

ijpatricio commented 1 year ago

Woohoo, glad it did!

garrettw commented 1 year ago

@Daniel-Mendes awesome! One question though -- do you have it working with the standard docker-compose.yml that comes with the repo?

Daniel-Mendes commented 1 year ago

@Daniel-Mendes awesome! One question though -- do you have it working with the standard docker-compose.yml that comes with the repo?

I had to change vendor/ call to the published version in the repo and changed '${WWWGROUP:-1000}'

docker-compose.yml

version: "3"
services:
    laravel.test:
        build:
            context: ./docker/8.2
            dockerfile: Dockerfile
            args:
                WWWGROUP: "${WWWGROUP:-1000}"
        image: sail-8.2/app
        extra_hosts:
            - "host.docker.internal:host-gateway"
        ports:
            - "${APP_PORT:-80}:80"
            - "${VITE_PORT:-5173}:${VITE_PORT:-5173}"
        environment:
            WWWUSER: "${WWWUSER:-1000}"
            LARAVEL_SAIL: 1
            IGNITION_LOCAL_SITES_PATH: "${PWD}"
        volumes:
            - ".:/var/www/html"
        networks:
            - sail
        depends_on:
            - mysql
            - phpmyadmin
            - redis
            - mailpit
            - minio
            - soketi
    mysql:
        image: "mysql/mysql-server:8.0"
        ports:
            - "${FORWARD_DB_PORT:-3306}:3306"
        environment:
            MYSQL_ROOT_PASSWORD: "${DB_PASSWORD}"
            MYSQL_ROOT_HOST: "%"
            MYSQL_DATABASE: "${DB_DATABASE}"
            MYSQL_USER: "${DB_USERNAME}"
            MYSQL_PASSWORD: "${DB_PASSWORD}"
            MYSQL_ALLOW_EMPTY_PASSWORD: 1
        volumes:
            - "sail-mysql:/var/lib/mysql"
            - "./docker/mysql/create-testing-database.sh:/docker-entrypoint-initdb.d/create-testing-database.sh"
        networks:
            - sail
        healthcheck:
            test:
                - CMD
                - mysqladmin
                - ping
                - "-p${DB_PASSWORD}"
            retries: 3
            timeout: 5s
    phpmyadmin:
        image: "phpmyadmin:latest"
        ports:
            - 8080:80
        networks:
            - sail
        environment:
            PMA_ARBITRARY: 1
    redis:
        image: "redis:alpine"
        ports:
            - "${FORWARD_REDIS_PORT:-6379}:6379"
        volumes:
            - "sail-redis:/data"
        networks:
            - sail
        healthcheck:
            test:
                - CMD
                - redis-cli
                - ping
            retries: 3
            timeout: 5s
    mailpit:
        image: "axllent/mailpit:latest"
        ports:
            - "${FORWARD_MAILPIT_PORT:-1025}:1025"
            - "${FORWARD_MAILPIT_DASHBOARD_PORT:-8025}:8025"
        networks:
            - sail
    minio:
        image: "minio/minio:latest"
        ports:
            - "${FORWARD_MINIO_PORT:-9000}:9000"
            - "${FORWARD_MINIO_CONSOLE_PORT:-8900}:8900"
        environment:
            MINIO_ROOT_USER: sail
            MINIO_ROOT_PASSWORD: password
        volumes:
            - "sail-minio:/data/minio"
        networks:
            - sail
        command: 'minio server /data/minio --console-address ":8900"'
        healthcheck:
            test:
                - CMD
                - curl
                - "-f"
                - "http://localhost:9000/minio/health/live"
            retries: 3
            timeout: 5s
    soketi:
        image: "quay.io/soketi/soketi:latest-16-alpine"
        environment:
            SOKETI_DEBUG: "${SOKETI_DEBUG:-1}"
            SOKETI_METRICS_SERVER_PORT: "9601"
            SOKETI_DEFAULT_APP_ID: "${PUSHER_APP_ID}"
            SOKETI_DEFAULT_APP_KEY: "${PUSHER_APP_KEY}"
            SOKETI_DEFAULT_APP_SECRET: "${PUSHER_APP_SECRET}"
        ports:
            - "${PUSHER_PORT:-6001}:6001"
            - "${PUSHER_METRICS_PORT:-9601}:9601"
        networks:
            - sail
networks:
    sail:
        driver: bridge
volumes:
    sail-mysql:
        driver: local
    sail-redis:
        driver: local
    sail-minio:
        driver: local

.devcontainer/devcontainer.json

// https://aka.ms/devcontainer.json
{
    "name": "Laravel Sail",
    "dockerComposeFile": [
        "../docker-compose.yml"
    ],
    "service": "laravel.test",
    "workspaceFolder": "/var/www/html",
    "customizations": {
        "vscode": {
            "extensions": [
                "onecentlin.laravel-extension-pack",
                "Vue.volar",
                "nhedger.inertia",
                "dbaeumer.vscode-eslint",
                "esbenp.prettier-vscode",
            ],
            "settings": {
                "editor.formatOnSave": true,
                "editor.codeActionsOnSave": {
                    "source.fixAll.eslint": true
                },
                "files.autoSave": "onFocusChange",
                "[vue]": {
                    "editor.defaultFormatter": "esbenp.prettier-vscode"
                },
                "[javascript]": {
                    "editor.defaultFormatter": "esbenp.prettier-vscode"
                }
            }
        }
    },
    "remoteUser": "sail",
    "postCreateCommand": "chown -R 1000:1000 /var/www/html && cp .env.example .env && composer install && php artisan key:generate && php artisan storage:link --force && php artisan migrate --force --seed && npm install",
    "postStartCommand": "npm run dev",
    "forwardPorts": [
        80,
        8025,
        8080,
        6001,
        5173,
        8900
    ],
    "portsAttributes": {
        "80": {
            "label": "Application",
            "onAutoForward": "notify"
        },
        "8025": {
            "label": "Mailpit"
        },
        "8080": {
            "label": "phpMyAdmin"
        },
        "5173": {
            "label": "Vite (hmr)"
        },
        "6001": {
            "label": "Soketi"
        },
        "8900": {
            "label": "Minio"
        }
    }
}
garrettw commented 1 year ago

@Daniel-Mendes oh ok, so this doesn't change my inclusion of the sail repo inside of my own -- just adds the extra Laravel sprinkles that were missing.

Edit: I did some Googling and I see now what sail:publish does. As that seems more idiomatic, I'll go that route.