Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

provision: Add native support for GitHub Codespaces.

Sachin Kumar2d44200fc741
diff --git a/.devcontainer.json b/.devcontainer.json
new file mode 100644
index 00000000000..1ed745750e4
--- /dev/null
+++ b/.devcontainer.json
@@ -0,0 +1,40 @@
+{
+ // Base development container for contributing to Zulip.
+ "name": "Zulip",
+ "image": "mcr.microsoft.com/devcontainers/base:debian-12",
+ "features": {
+ "ghcr.io/devcontainers/features/git:1": {},
+ "ghcr.io/devcontainers/features/github-cli:1": {},
+ "ghcr.io/devcontainers/features/python:1": {}
+ },
+ // Editor defaults and extensions to keep local/devcontainer behavior consistent.
+ "customizations": {
+ "vscode": {
+ "extensions": [
+ "ms-python.python",
+ "ms-python.vscode-pylance",
+ "esbenp.prettier-vscode",
+ "dbaeumer.vscode-eslint"
+ ],
+ "settings": {
+ "python.createEnvironment": false,
+ "python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python",
+ "[python]": {
+ "editor.formatOnSave": true,
+ "editor.defaultFormatter": "ms-python.python"
+ }
+ }
+ }
+ },
+ // Run Zulip's devcontainer/codespace provisioning script after container creation.
+ "postCreateCommand": "bash tools/setup/provision-codespace",
+ // Forward Zulip's internal development services and PostgreSQL.
+ "forwardPorts": [9991],
+ "portsAttributes": {
+ // Development server proxy entrypoint for the web app.
+ "9991": {
+ "label": "Development Server Proxy",
+ "onAutoForward": "notify"
+ }
+ }
+}
diff --git a/tools/lib/provision_inner.py b/tools/lib/provision_inner.py
index 7f31d4fa7e4..c9dafa115d7 100755
--- a/tools/lib/provision_inner.py
+++ b/tools/lib/provision_inner.py
@@ -324,6 +324,13 @@ def main(options: argparse.Namespace) -> int:
destroy_leaked_test_databases,
)
+ if os.environ.get("CODESPACES") == "true":
+ print("Starting background services explicitly for GitHub Codespaces...")
+ run_as_root(["service", "postgresql", "start"])
+ run_as_root(["service", "rabbitmq-server", "start"])
+ run_as_root(["service", "redis-server", "start"])
+ run_as_root(["service", "memcached", "start"])
+
assert settings.RABBITMQ_PASSWORD is not None
if options.is_force or need_to_run_configure_rabbitmq([settings.RABBITMQ_PASSWORD]):
run_as_root(["scripts/setup/configure-rabbitmq"])
diff --git a/tools/setup/provision-codespace b/tools/setup/provision-codespace
new file mode 100755
index 00000000000..1f1f4b7fe1a
--- /dev/null
+++ b/tools/setup/provision-codespace
@@ -0,0 +1,22 @@
+#!/usr/bin/env bash
+
+set -euo pipefail
+
+# 1) Give passwordless sudo access to the 'vscode' user for postgres.
+sudo sh -c "echo 'vscode ALL=(postgres) NOPASSWD: ALL' > /etc/sudoers.d/vscode_postgres"
+
+# 2) Add 127.0.0.1 \\$(hostname) to /etc/hosts.
+if ! grep -qE "^127\.0\.0\.1[[:space:]]+$(hostname)([[:space:]]|$)" /etc/hosts; then
+ echo "127.0.0.1 $(hostname)" | sudo tee -a /etc/hosts >/dev/null
+fi
+
+# 3) Unset variables to prevent PyICU conflicts.
+unset VIRTUAL_ENV
+unset CONDA_PREFIX
+unset CONDA_DEFAULT_ENV
+unset CONDA_PROMPT_MODIFIER
+unset CONDA_EXE
+unset CE_CONDA
+
+# 4) Finally, execute Zulip provisioning.
+./tools/provision