Skip to content

add emacs-broadway template #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions emacs-broadway/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
name: Develop in Emacs on the Web!
description: Get started with Emacs development.
tags: [cloud, emacs]
---

# Getting started

Click on the Emacs-Broaway url within the workspace to access GUI Emacs via a browser.

Emacs is compiled to run with GDK_BACKEND=broadway on a BROADWAY_DISPLAY
It required a build of emacs with `./configure --with-pgtk --with-cairo --with-native-compilation --with-json --with-modules`

# Current Status

Based heavily on the work from @emacs-lsp : https://github.com/emacs-lsp/lsp-gitpod

<!-- Built over at: https://launchpad.net/~hippiehacker/+archive/ubuntu/emacs-broadway -->

Container source at : https://github.com/ii/emacs-coder/blob/master/Dockerfile
Includes ii's humacs.org doom config : https://github.com/humacs/.doom.d#humacs-doomd
155 changes: 155 additions & 0 deletions emacs-broadway/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
terraform {
required_providers {
coder = {
source = "coder/coder"
version = "0.6.1"
}
kubernetes = {
source = "hashicorp/kubernetes"
version = "~> 2.12.1"
}
}
}

variable "use_kubeconfig" {
type = bool
default = false
sensitive = true
description = <<-EOF
Use host kubeconfig? (true/false)

Set this to false if the Coder host is itself running as a Pod on the same
Kubernetes cluster as you are deploying workspaces to.

Set this to true if the Coder host is running outside the Kubernetes cluster
for workspaces. A valid "~/.kube/config" must be present on the Coder host.
EOF
}

variable "namespace" {
type = string
sensitive = true
description = "The namespace to create workspaces in (must exist prior to creating workspaces)"
default = "coder"
}

provider "kubernetes" {
# Authenticate via ~/.kube/config or a Coder-specific ServiceAccount, depending on admin preferences
config_path = var.use_kubeconfig == true ? "~/.kube/config" : null
}

data "coder_workspace" "me" {}

resource "coder_agent" "main" {
os = "linux"
arch = "amd64"
startup_script = <<EOT
#!/bin/bash

# home folder currently contains .emacs.d and .doom.d
# at some point later we'll move them to another folder
sudo apt-get install -y tmux ttyd libwebsockets-evlib-uv
# start broadwayd and emacs
broadwayd :5 2>&1 | tee broadwayd.log &
GDK_BACKEND=broadway BROADWAY_DISPLAY=:5 emacs 2>&1 | tee emacs.log &
# start ttyd / tmux
tmux new -d
ttyd tmux at 2>&1 | tee ttyd.log &
# install and start code-server
curl -fsSL https://code-server.dev/install.sh | sh | tee code-server-install.log
code-server --auth none --port 13337 | tee code-server-install.log &

EOT
}

# emacs-broadway
resource "coder_app" "emacs-broadway" {
subdomain = true
share = "public"
agent_id = coder_agent.main.id
slug = "emacs-broadway"
display_name = "Emacs on Broadway"
icon = "/icon/folder.svg" # let's maybe get an emacs.svg somehow
url = "http://localhost:8085" # port 8080 + BROADWAY_DISPLAY

# healthcheck {
# # don't want to disconnect current session, but hopefully this will 200OK
# url = "http://localhost:8085/"
# interval = 3
# threshold = 10
# }
}

# ttyd
resource "coder_app" "ttyd" {
subdomain = true
share = "public"
slug = "ttyd"
display_name = "ttyd for tmux"
icon = "/icon/folder.svg" # let's maybe get an emacs.svg somehow
agent_id = coder_agent.main.id
url = "http://localhost:7681" # 7681 is the default ttyd port

# healthcheck {
# # don't want to disconnect current session, but hopefully this will 200OK
# url = "http://localhost:7681/"
# interval = 3
# threshold = 10
# }
}

# tmux
resource "coder_app" "tmux" {
agent_id = coder_agent.main.id
display_name = "tmux"
slug = "tmux"
icon = "/icon/folder.svg" # let's maybe get an emacs.svg somehow
command = "tmux at"
share = "public"
subdomain = true
}

# code-server
resource "coder_app" "code-server" {
agent_id = coder_agent.main.id
display_name = "code-server"
slug = "code-server"
icon = "/icon/code.svg"
url = "http://localhost:13337?folder=/home/coder"
subdomain = true

# healthcheck {
# url = "http://localhost:13337/healthz"
# interval = 3
# threshold = 10
# }
}

resource "kubernetes_pod" "main" {
count = data.coder_workspace.me.start_count
metadata {
name = "coder-${lower(data.coder_workspace.me.owner)}-${lower(data.coder_workspace.me.name)}"
namespace = var.namespace
labels = {
name = "coder-${lower(data.coder_workspace.me.owner)}-${lower(data.coder_workspace.me.name)}"
}
}
spec {
security_context {
run_as_user = "1000"
fs_group = "1000"
}
container {
name = "dev"
image = "ghcr.io/ii/emacs-coder:latest"
command = ["sh", "-c", coder_agent.main.init_script]
security_context {
run_as_user = "1000"
}
env {
name = "CODER_AGENT_TOKEN"
value = coder_agent.main.token
}
}
}
}
16 changes: 8 additions & 8 deletions kubevirt-talos/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ terraform {
required_providers {
coder = {
source = "coder/coder"
version = "0.4.15"
version = "0.6.5"
}
kubernetes = {
source = "hashicorp/kubernetes"
version = "~> 2.12.1"
version = "~> 2.16.1"
}
}
}
Expand Down Expand Up @@ -54,12 +54,12 @@ resource "coder_agent" "main" {

# code-server
resource "coder_app" "code-server" {
agent_id = coder_agent.main.id
name = "code-server"
icon = "/icon/code.svg"
url = "http://localhost:13337?folder=/home/coder"
relative_path = true

slug = "code-server"
subdomain = true
display_name = "Code Server"
agent_id = coder_agent.main.id
icon = "/icon/code.svg"
url = "http://localhost:13337?folder=/home/coder"
healthcheck {
url = "http://localhost:13337/healthz"
interval = 3
Expand Down