0

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.

David Dahan
  • 10,576
  • 11
  • 64
  • 137

2 Answers2

2

As a complement to @Dorin Botan good answer, here is my configuration in tasks.json, using 2 groups of terminals like this:

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": [],
        }
    ]
}


David Dahan
  • 10,576
  • 11
  • 64
  • 137
1

You can automate things in VSCode using custom tasks.

Your scenario is a bit tricky though, so, I'd suggest:

  • Create 3 separate tasks that open a terminal and execute one of the commands that you need. Check this answer for an example of how it's done.
  • Create a compound task that runs the 3 tasks above.
Dorin Botan
  • 1,224
  • 8
  • 19