Skip to content

Add template-specific command execution for Docker containers#45

Open
Copilot wants to merge 5 commits intomainfrom
copilot/add-common-docker-commands
Open

Add template-specific command execution for Docker containers#45
Copilot wants to merge 5 commits intomainfrom
copilot/add-common-docker-commands

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Dec 10, 2025

Description

Adds one-click command execution for running containers based on their detected template type. Commands are pre-configured per template (Django, Flask, FastAPI, React, Node.js, Python, Go) and validated against a whitelist before execution.

Core Changes

Template Detection & Commands

  • Auto-detects template from Dockerfile content (keywords: django, flask, uvicorn, node, etc.)
  • TEMPLATE_COMMANDS dict in models.py defines allowed commands per template
  • Build.detected_template and Build.available_commands properties

Execution Pipeline

  • exec_command_in_container() in docker_utils.py: runs docker exec with 120s timeout
  • execute_container_command view: validates command against template's whitelist, rejects unauthorized commands
  • /builds/<build_id>/execute-command/ POST endpoint

UI

  • Quick Commands card in build_detail.html when container is running
  • Real-time output display with exit code badges
  • Template type badge in container list
  • Uses textContent and FormData to prevent XSS

Command Examples

Django: python manage.py test, python manage.py migrate, python manage.py check --deploy
Flask: python -m pytest -v, pip list
React: npm test -- --watchAll=false, npm run build
Node.js: npm test, npm run lint, node --version

Security

  • Commands validated against template whitelist - arbitrary execution blocked
  • XSS prevented via DOM manipulation instead of innerHTML
  • All command attempts logged with warning for unauthorized attempts
  • CodeQL scan: 0 vulnerabilities

Type of Change

  • New feature (non-breaking change that adds functionality)
  • Test addition/modification

How Has This Been Tested?

  • Unit tests
  • Manual testing

Test Configuration:

  • Python version: 3.12
  • Django version: 5.0+
  • Operating System: Linux

Tests Added:

  • Template detection for all supported types
  • Command whitelist validation
  • Authorized vs unauthorized command execution
  • XSS prevention verification

Checklist

  • My code follows the style guidelines of this project (PEP 8, Black formatting)
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings or errors
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Related Issues

Addresses issue requesting common commands for Docker templates.

Additional Notes

Command execution requires:

  1. Container status = running
  2. Command in template's whitelist
  3. User authenticated

Failed commands return exit code and error output. Timeout prevents resource exhaustion.

Original prompt

This section details on the original issue you should resolve

<issue_title>Ajouter des commandes supplémentaires communes pour chaque template de Docker</issue_title>
<issue_description>Par exemple, pour le template de Django, il pourrait y avoir des boutons pour effectuer une liste de commande courante, comme python manage.py test, disponible pour être lancée sur tous les docker actifs qui suivent ce template.

Suggère des commandes supplémentaires pour le template django (autre que runserver) et suggères-en aussi pour les autres templates. </issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 4 commits December 10, 2025 02:07
Co-authored-by: vbrunelle <27235114+vbrunelle@users.noreply.github.com>
Co-authored-by: vbrunelle <27235114+vbrunelle@users.noreply.github.com>
Co-authored-by: vbrunelle <27235114+vbrunelle@users.noreply.github.com>
Co-authored-by: vbrunelle <27235114+vbrunelle@users.noreply.github.com>
Copilot AI changed the title [WIP] Add common commands for Docker templates Add template-specific command execution for Docker containers Dec 10, 2025
Copilot AI requested a review from vbrunelle December 10, 2025 02:21
@vbrunelle vbrunelle marked this pull request as ready for review December 10, 2025 02:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ajouter des commandes supplémentaires communes pour chaque template de Docker

2 participants