Home > other >  Devcontainer: how to open terminal with custom commands when opening the container?
Devcontainer: how to open terminal with custom commands when opening the container?

Time:07-02

When starting my devcontainer, I need to run multiple commands to be able to work on my project. For example for my Django project, I need to run:

  1. python manage.py runserver
  2. celery -A proj worker
  3. celery -A proj beat
  4. tailwindcss -w -i input.css -o output.css

Currently, I do this manually and this is a little bit painful.

I know there is a postStartCommand that I could use, but I'd be forced to group all my commands with && and I would not be able to follow each command logs individually.

What I'd like to do is to automate what I'm currently doing by hand: open different terminal windows and run a single command in each of them, to have this result:

enter image description here

Is there a way to do that? Or any workaround? Thanks.

CodePudding user response:

You can automate things in VSCode using custom enter image description here

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558 
    // See https://code.visualstudio.com/docs/editor/tasks-appendix
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Term 1",
            "type": "process",
            "command": "/bin/bash",
            "isBackground": true, // removes the infinite spinner
            "problemMatcher": [],
            "presentation": {
                "group": "main_tasks",
                "reveal": "always",
                "panel": "new",
                "echo": false, // silence "Executing task ..."
            }
        },
        {
            "label": "Django server",
            "type": "shell",
            "command": "./manage.py runserver 127.0.0.1:8000",
            "isBackground": true,
            "presentation": {
                "group": "main_tasks",
                "reveal": "always",
                "panel": "new",
            }
        },
        {
            "label": "Celery worker",
            "type": "shell",
            "command": "celery --app dj_config worker --uid=nobody --gid=nogroup --loglevel INFO",
            "isBackground": true,
            "presentation": {
                "group": "background_tasks",
                "reveal": "never",
                "panel": "new",
                "showReuseMessage": false,
            }
        },
        {
            "label": "Celery beat",
            "type": "shell",
            "command": "celery --app dj_config beat --uid=nobody --gid=nogroup --loglevel INFO",
            "isBackground": true,
            "presentation": {
                "group": "background_tasks",
                "reveal": "never",
                "panel": "new",
                "showReuseMessage": false,
            },
        },
        {
            "label": "Tailwind watcher",
            "type": "shell",
            "command": "sleep infinity", // FIXME with real command
            "isBackground": true,
            "presentation": {
                "group": "background_tasks",
                "reveal": "never",
                "panel": "new",
                "showReuseMessage": false,
            }
        },
        {
            // This is a compound task to run them all
            "label": "Mango Terminals (David)",
            "dependsOn": [
                "Term 1",
                "Django server",
                "Tailwind watcher",
                "Celery worker",
                "Celery beat",
            ],
            "dependsOrder": "parallel", // no dependencies between tasks
            "problemMatcher": [],
        }
    ]
}


  • Related