trigger.dev icon indicating copy to clipboard operation
trigger.dev copied to clipboard

feat: Add Support for Alternative Container Runtimes (Podman, containerd)

Open zvictor opened this issue 11 months ago • 2 comments

Description:

Please add support for alternative container runtimes like Podman and containerd to trigger.dev. This will make the tool more flexible and accessible to a wider range of users. Some users prefer Podman for rootless execution, or use containerd in Kubernetes environments.

Problem:

Currently, trigger.dev requires Docker, which isn't ideal for everyone. Current blockers include:

Proposed Solution:

Allow users to specify their preferred container runtime. This could be done with:

  • An environment variable (e.g., TRIGGER_CONTAINER_RUNTIME=podman).
  • A setting in a config file.

The CLI would then use this setting instead of directly calling docker.

Relevant Discussions:

  • https://discord.com/channels/1066956501299777596/1066956844553207828/1249760386186608800
  • https://discord.com/channels/1066956501299777596/1066956844553207828/1338088351160471593

zvictor avatar Feb 09 '25 10:02 zvictor

These are the changes I had to make to https://github.com/triggerdotdev/docker in order to work with Podman with relative success:

diff --git a/docker-compose.worker.yml b/docker-compose.worker.yml
index 477e0b6..c3abbc6 100644
--- a/docker-compose.worker.yml
+++ b/docker-compose.worker.yml
@@ -12,7 +12,7 @@ services:
     image: ghcr.io/triggerdotdev/provider/docker:${TRIGGER_IMAGE_TAG:-v3}
     restart: ${RESTART_POLICY:-unless-stopped}
     volumes:
-      - /var/run/docker.sock:/var/run/docker.sock
+      - $XDG_RUNTIME_DIR/podman/podman.sock:/var/run/docker.sock
     user: root
     networks:
       - default
@@ -28,7 +28,7 @@ services:
     image: ghcr.io/triggerdotdev/coordinator:${TRIGGER_IMAGE_TAG:-v3}
     restart: ${RESTART_POLICY:-unless-stopped}
     volumes:
-      - /var/run/docker.sock:/var/run/docker.sock
+      - $XDG_RUNTIME_DIR/podman/podman.sock:/var/run/docker.sock
     user: root
     networks:
       - default
diff --git a/docker-compose.yml b/docker-compose.yml
index 424f912..8043dcb 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -19,6 +19,8 @@ networks:
 
 services:
   webapp:
+    name: trigger-network
+    driver: bridge
     image: ghcr.io/triggerdotdev/trigger.dev:${TRIGGER_IMAGE_TAG:-v3}
     restart: ${RESTART_POLICY:-unless-stopped}
     env_file:
@@ -28,8 +30,10 @@ services:
     ports:
       - ${WEBAPP_PUBLISH_IP:-127.0.0.1}:3040:3030
     depends_on:
-      - postgres
-      - redis
+      postgres:
+        condition: service_healthy
+      redis:
+        condition: service_started
     networks:
       - webapp
 
@@ -47,6 +51,15 @@ services:
     command:
       - -c
       - wal_level=logical
+      - -c
+      - fsync=off
+      - -c
+      - full_page_writes=off
+    healthcheck:
+      test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB:-postgres}"]
+      interval: 5s
+      timeout: 5s
+      retries: 10
 
   redis:
     image: redis:${REDIS_IMAGE_TAG:-7}
@@ -59,10 +72,13 @@ services:
       - ${DOCKER_PUBLISH_IP:-127.0.0.1}:6389:6379
 
   docker-provider:
     image: ghcr.io/triggerdotdev/provider/docker:${TRIGGER_IMAGE_TAG:-v3}
     restart: ${RESTART_POLICY:-unless-stopped}
     volumes:
-      - /var/run/docker.sock:/var/run/docker.sock
+      - $XDG_RUNTIME_DIR/podman/podman.sock:/var/run/docker.sock
     user: root
     networks:
       - webapp
@@ -80,7 +96,7 @@ services:
     image: ghcr.io/triggerdotdev/coordinator:${TRIGGER_IMAGE_TAG:-v3}
     restart: ${RESTART_POLICY:-unless-stopped}
     volumes:
-      - /var/run/docker.sock:/var/run/docker.sock
+      - $XDG_RUNTIME_DIR/podman/podman.sock:/var/run/docker.sock
     user: root
     networks:
       - webapp
@@ -98,10 +114,29 @@ services:
     image: electricsql/electric:${ELECTRIC_IMAGE_TAG:-latest}
     restart: ${RESTART_POLICY:-unless-stopped}
     environment:
-      DATABASE_URL: ${DATABASE_URL}?sslmode=disable
+      DATABASE_URL: "postgresql://postgres:postgres@postgres:5432/postgres?sslmode=disable"
     networks:
       - webapp
     depends_on:
-      - postgres
+      postgres:
+        condition: service_healthy
     ports:
       - ${DOCKER_PUBLISH_IP:-127.0.0.1}:3061:3000
diff --git a/lib.sh b/lib.sh
index 660801f..0131db0 100644
--- a/lib.sh
+++ b/lib.sh
@@ -1,12 +1,12 @@
 #!/bin/sh
 
 docker_compose() {
-    if docker compose >/dev/null 2>&1; then
+    if podman compose >/dev/null 2>&1; then
         set -x
-        docker compose "$@"
-    elif command -v docker-compose >/dev/null 2>&1; then
+        podman compose "$@"
+    elif command -v podman-compose >/dev/null 2>&1; then
         set -x
-        docker-compose "$@"
+        podman-compose "$@"
     else
         echo Please install docker compose: https://docs.docker.com/compose/install/
     fi
diff --git a/start.sh b/start.sh
index 16a8b68..2f0402c 100755
--- a/start.sh
+++ b/start.sh
@@ -55,4 +55,4 @@ else
     extra_args="-p=trigger-$kind"
 fi
 
-docker_compose -f "$compose_file" "$extra_args" up "$@"
+docker_compose -f "$compose_file" "$extra_args" up "$@" --build

zvictor avatar Feb 09 '25 10:02 zvictor

For anyone interested, I made a repo containing the changes I mentioned before together with a backup system: https://github.com/zvictor/triger.dev-podman

zvictor avatar Feb 27 '25 19:02 zvictor

The work you did above is great 👍

As the Docker repo is just an example of how to self-host I don't think this is really an issue, it's more a request for us giving more examples of how to deploy.

You probably want to check out our new v4 self-hosting stuff as well: https://trigger.dev/docs/self-hosting/overview

matt-aitken avatar Aug 08 '25 13:08 matt-aitken