diff --git a/emacs-broadway/README.md b/emacs-broadway/README.md new file mode 100644 index 0000000..4de520f --- /dev/null +++ b/emacs-broadway/README.md @@ -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 + + + +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 diff --git a/emacs-broadway/main.tf b/emacs-broadway/main.tf new file mode 100644 index 0000000..b397aac --- /dev/null +++ b/emacs-broadway/main.tf @@ -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 = <&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 + } + } + } +} diff --git a/kubevirt-talos/cluster.tf b/kubevirt-talos/cluster.tf index c230bd9..df4acf9 100644 --- a/kubevirt-talos/cluster.tf +++ b/kubevirt-talos/cluster.tf @@ -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" } } } @@ -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