codesandbox / codesandbox-client

An online IDE for rapid web development
https://codesandbox.io
Other
13.03k stars 2.27k forks source link

Dev Container with the dockerComposeFile option doesn't work #8193

Closed antogno closed 10 months ago

antogno commented 10 months ago

🐛 bug report

Preflight Checklist

Description of the problem

I'm trying to import antogno/pesapi in CodeSandbox but the Dev Container just doesn't start. I suppose it's because of the dockerComposeFile option which I've never seen used in any of the examples I found online.

The devcontainer.json looks like this:

{
    "name": "Pro Evolution Soccer 6 API",
    "dockerComposeFile": ["../docker-compose.yml"],
    "service": "app",
    "workspaceFolder": "/app",
    "customizations": {
        "vscode": {
            "extensions": [
                "eamodio.gitlens",
                "esbenp.prettier-vscode",
                "Prisma.prisma",
                "GraphQL.vscode-graphql",
                "bierner.markdown-preview-github-styles"
            ],
            "settings": {
                "editor.defaultFormatter": "esbenp.prettier-vscode",
                "editor.formatOnSave": true,
                "editor.rulers": [80, 120],
                "editor.stickyScroll.enabled": true,
                "files.associations": {
                    ".env.example": "properties"
                }
            }
        }
    }
}

And this is docker-compose.yml:

version: '3'

services:
  app:
    image: node:20.8.0
    container_name: app
    volumes:
      - .:/app
    ports:
      - ${APP_PORT}:4000
    environment:
      NODE_ENV: development
    command: ['sleep', 'infinity']
    depends_on:
      - db
    restart: unless-stopped
    networks:
      - pesapi
    env_file:
      - .env
  db:
    image: mysql:8.1.0
    container_name: db
    volumes:
      - db:/var/lib/mysql
    environment:
      MYSQL_RANDOM_ROOT_PASSWORD: yes
      MYSQL_USER: ${DB_USER}
      MYSQL_PASSWORD: ${DB_PASSWORD}
      MYSQL_DATABASE: ${DB_NAME}
    restart: unless-stopped
    networks:
      - pesapi
    env_file:
      - .env
volumes:
  db:
networks:
  pesapi:

If I try to import this repository and I choose to use its Dev Container configuration, it gives me these errors:

[CODESANDBOX] Devcontainer detected
[CODESANDBOX] Running devcontainer
[3 ms] @devcontainers/cli 0.50.2. Node.js v16.17.0. linux 6.1.43 x64.
[511 ms] Start: Run: docker-compose -f /project/pesapi/docker-compose.yml -f /tmp/csb-devcontainers-pitcher-host/docker-compose.override.yml --profile * config
[551 ms] 
[552 ms] time="2023-11-21T06:54:32Z" level=warning msg="The \"PORT\" variable is not set. Defaulting to a blank string."
Failed to load /project/pesapi/.env: open /project/pesapi/.env: no such file or directory

[552 ms] Exit code 14
Error: Command failed: docker-compose -f /project/pesapi/docker-compose.yml -f /tmp/csb-devcontainers-pitcher-host/docker-compose.override.yml --profile * config
    at CI (/usr/local/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:460:889)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async AAA (/usr/local/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:427:1367)
    at async $$ (/usr/local/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:409:3165)
    at async mAA (/usr/local/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:479:3833)
    at async LC (/usr/local/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:479:4775)
    at async jeA (/usr/local/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:611:12219)
    at async _eA (/usr/local/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:611:11960)
{"outcome":"error","message":"Command failed: docker-compose -f /project/pesapi/docker-compose.yml -f /tmp/csb-devcontainers-pitcher-host/docker-compose.override.yml --profile * config","description":"An error occurred retrieving the Docker Compose configuration."}
Failed to run containers Command failed with exit code 1: devcontainer up --workspace-folder=/project/pesapi --override-config=/tmp/csb-devcontainers-pitcher-host/.devcontainer.json --remove-existing-container --skip-post-attach --skip-post-create --additional-features="{\"ghcr.io/codesandbox/devcontainer-features/codesandbox:0.1.4\":{}}" --mount=type=bind,source=/project/pesapi,target=/project/pesapi --mount=type=bind,source=/project/home/pitcher-host/.cache,target=/root/.cache --mount=type=bind,source=/project/home/pitcher-host/.docker/run/docker.sock,target=/var/run/docker.sock --mount=type=bind,source=/usr/local/bin/lsp/,target=/usr/local/bin/lsp/ --mount=type=bind,source=/run/user/1001/pitcher/,target=/var/run/pitcher/ --mount=type=bind,source=/pitcher/pitcher/out/pitcher-fs-indexer/fs-server,target=/usr/local/bin/fs-server

Setting the env variable PORT solves one of the two errors:

[CODESANDBOX] Devcontainer detected
[CODESANDBOX] Running devcontainer
[2 ms] @devcontainers/cli 0.50.2. Node.js v16.17.0. linux 6.1.43 x64.
[556 ms] Start: Run: docker-compose -f /project/pesapi/docker-compose.yml -f /tmp/csb-devcontainers-pitcher-host/docker-compose.override.yml --profile * config
[607 ms] 
[608 ms] Failed to load /project/pesapi/.env: open /project/pesapi/.env: no such file or directory

[608 ms] Exit code 14
Error: Command failed: docker-compose -f /project/pesapi/docker-compose.yml -f /tmp/csb-devcontainers-pitcher-host/docker-compose.override.yml --profile * config
    at CI (/usr/local/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:460:889)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async AAA (/usr/local/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:427:1367)
    at async $$ (/usr/local/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:409:3165)
    at async mAA (/usr/local/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:479:3833)
    at async LC (/usr/local/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:479:4775)
    at async jeA (/usr/local/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:611:12219)
    at async _eA (/usr/local/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:611:11960)
{"outcome":"error","message":"Command failed: docker-compose -f /project/pesapi/docker-compose.yml -f /tmp/csb-devcontainers-pitcher-host/docker-compose.override.yml --profile * config","description":"An error occurred retrieving the Docker Compose configuration."}
Failed to run containers Command failed with exit code 1: devcontainer up --workspace-folder=/project/pesapi --override-config=/tmp/csb-devcontainers-pitcher-host/.devcontainer.json --remove-existing-container --skip-post-attach --skip-post-create --additional-features="{\"ghcr.io/codesandbox/devcontainer-features/codesandbox:0.1.4\":{}}" --mount=type=bind,source=/project/pesapi,target=/project/pesapi --mount=type=bind,source=/project/home/pitcher-host/.cache,target=/root/.cache --mount=type=bind,source=/project/home/pitcher-host/.docker/run/docker.sock,target=/var/run/docker.sock --mount=type=bind,source=/usr/local/bin/lsp/,target=/usr/local/bin/lsp/ --mount=type=bind,source=/run/user/1001/pitcher/,target=/var/run/pitcher/ --mount=type=bind,source=/pitcher/pitcher/out/pitcher-fs-indexer/fs-server,target=/usr/local/bin/fs-server

Removing the env_file property from docker-compose.yml solves the other one, but then:

[CODESANDBOX] Devcontainer detected
[CODESANDBOX] Running devcontainer
[3 ms] @devcontainers/cli 0.50.2. Node.js v16.17.0. linux 6.1.43 x64.
[451 ms] Start: Run: docker-compose -f /project/pesapi/docker-compose.yml -f /tmp/csb-devcontainers-pitcher-host/docker-compose.override.yml --profile * config
[527 ms] Start: Run: docker-compose -f /project/pesapi/docker-compose.yml -f /tmp/csb-devcontainers-pitcher-host/docker-compose.override.yml --profile * config
[583 ms] name: pesapi
services:
  app:
    command:
      - sleep
      - infinity
    container_name: app
    depends_on:
      db:
        condition: service_started
        required: true
    environment:
      NODE_ENV: development
    image: node:20.8.0
    networks:
      pesapi: null
    ports:
      - mode: ingress
        target: 4000
        published: "4000"
        protocol: tcp
    restart: unless-stopped
    volumes:
      - type: bind
        source: /project/pesapi
        target: /app
        bind:
          create_host_path: true
  app_csb:
    command:
      - sleep
      - infinity
    container_name: devcontainer
    depends_on:
      db:
        condition: service_started
        required: true
    environment:
      _: /usr/bin/pitcher
      APP_PORT: "4000"
      CODESANDBOX_HOST: 7m7wdt-4000.csb.app
      CSB: "true"
      CSB_BASE_PREVIEW_HOST: csb.app
      DB_NAME: pes
      DB_PASSWORD: password
      DB_URL: mysql://pes:password@db:3306/pes?schema=public
      DB_USER: pes
      FNM_ARCH: x64
      FNM_COREPACK_ENABLED: "false"
      FNM_DIR: /usr/share/fnm
      FNM_LOGLEVEL: info
      FNM_MULTISHELL_PATH: /project/home/pitcher-host/.local/state/fnm_multishells/1176_1700550793966
      FNM_NODE_DIST_MIRROR: https://nodejs.org/dist
      FNM_RESOLVE_ENGINES: "false"
      FNM_VERSION_FILE_STRATEGY: local
      HOSTNAME: 7m7wdt
      LC_CTYPE: C.UTF-8
      LOGNAME: pitcher-host
      NPM_CONFIG_CACHE: /root/.cache/npm
      NPM_CONFIG_STORE_DIR: /root/.cache/pnpm
      OLDPWD: /project/pesapi
      PERMISSION_WATCHER_VERSION: 0.1.3
      PITCHER_API_BASE_URL: https://codesandbox.io/api
      PITCHER_BIN_PATH: /pitcher/pitcher.cjs
      PITCHER_CLIENTS_WSS_PORT: "82"
      PITCHER_ENV: production
      PITCHER_MANAGER_WSS_PORT: "81"
      PITCHER_WORKSPACE_PATH: /project/pesapi
      PNPM_VERSION: 7.1.0
      PORT: "4000"
      PROJECT_GID: "1001"
      SHLVL: "0"
      SUPERVISOR_ENABLED: "1"
      SUPERVISOR_GROUP_NAME: pitcher-agent
      SUPERVISOR_PROCESS_NAME: pitcher-agent
      SUPERVISOR_SERVER_URL: unix:///var/run/supervisord.sock
      TERM: xterm-256color
      WATCHMAN_VERSION: 2022.05.30.00
      WORKSPACE_PATH: /project/pesapi
      YARN_CACHE_FOLDER: /root/.cache/yarn
      ZSH_DISABLE_COMPFIX: "true"
    image: localhost/codesandbox/devcontainer:latest
    networks:
      pesapi: null
    ports:
      - mode: ingress
        target: 4000
        published: "4000"
        protocol: tcp
    restart: unless-stopped
    uts: host
    volumes:
      - type: bind
        source: /project/pesapi
        target: /app
        bind:
          create_host_path: true
  db:
    container_name: db
    environment:
      MYSQL_DATABASE: pes
      MYSQL_PASSWORD: password
      MYSQL_RANDOM_ROOT_PASSWORD: "yes"
      MYSQL_USER: pes
    image: mysql:8.1.0
    networks:
      pesapi: null
    restart: unless-stopped
    volumes:
      - type: volume
        source: db
        target: /var/lib/mysql
        volume: {}
networks:
  pesapi:
    name: pesapi_pesapi
volumes:
  db:
    name: pesapi_db
[586 ms] Start: Run: docker inspect --type image localhost/codesandbox/devcontainer:latest
[606 ms] Sending as plain HTTP request
[609 ms] Error fetching image details: connect ECONNREFUSED 127.0.0.1:80
[609 ms] Start: Run: docker pull localhost/codesandbox/devcontainer:latest
Error response from daemon: Get "http://localhost/v2/": dial tcp 127.0.0.1:80: connect: connection refused
[643 ms] []
[644 ms] Error response from daemon: No such image: localhost/codesandbox/devcontainer:latest

Error: Command failed: docker inspect --type image localhost/codesandbox/devcontainer:latest
    at $$ (/usr/local/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:409:3567)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async mAA (/usr/local/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:479:3833)
    at async LC (/usr/local/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:479:4775)
    at async jeA (/usr/local/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:611:12219)
    at async _eA (/usr/local/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:611:11960)
{"outcome":"error","message":"Command failed: docker inspect --type image localhost/codesandbox/devcontainer:latest","description":"An error occurred setting up the container."}
Failed to run containers Command failed with exit code 1: devcontainer up --workspace-folder=/project/pesapi --override-config=/tmp/csb-devcontainers-pitcher-host/.devcontainer.json --remove-existing-container --skip-post-attach --skip-post-create --additional-features="{\"ghcr.io/codesandbox/devcontainer-features/codesandbox:0.1.4\":{}}" --mount=type=bind,source=/project/pesapi,target=/project/pesapi --mount=type=bind,source=/project/home/pitcher-host/.cache,target=/root/.cache --mount=type=bind,source=/project/home/pitcher-host/.docker/run/docker.sock,target=/var/run/docker.sock --mount=type=bind,source=/usr/local/bin/lsp/,target=/usr/local/bin/lsp/ --mount=type=bind,source=/run/user/1001/pitcher/,target=/var/run/pitcher/ --mount=type=bind,source=/pitcher/pitcher/out/pitcher-fs-indexer/fs-server,target=/usr/local/bin/fs-server

How has this issue affected you? What are you trying to accomplish?

It just seems to me that using the dockerComposeFile option is not yet supported. Am I wrong?

To Reproduce

Import antogno/pesapi in CodeSandbox and choose the Use the current configuration option when configuring the microVM environment.

Your Environment

Software Name/Version
Сodesandbox codesandbox.io
Browser Firefox 119.0
Operating System macOS 14.1.1
mojojoji commented 10 months ago

These issues should be fixed now. Restarting the branch (CodeSandbox logo menu on top left > Restart branch) should pull the version with the fixes.

Can you restart the branch and confirm that if it works now?

antogno commented 10 months ago

After the update I had some problems with the mysql:8.1.0 image - switching to mysql:8.2.0 solved them and now everything works correctly. Thanks!