diff --git a/Makefile b/Makefile index 6accef31c5432..2835780761fc4 100644 --- a/Makefile +++ b/Makefile @@ -172,7 +172,7 @@ endef # calling this manually. $(CODER_ALL_BINARIES): go.mod go.sum \ $(shell find . -not -path './vendor/*' -type f -name '*.go') \ - $(shell find ./examples/templates) + $(shell find ./templates/quickstart) $(get-mode-os-arch-ext) if [[ "$$os" != "windows" ]] && [[ "$$ext" != "" ]]; then diff --git a/cli/templateinit.go b/cli/templateinit.go index ad936024a9f11..9c2075964493c 100644 --- a/cli/templateinit.go +++ b/cli/templateinit.go @@ -8,8 +8,8 @@ import ( "github.com/spf13/cobra" "github.com/coder/coder/cli/cliui" - "github.com/coder/coder/examples" "github.com/coder/coder/provisionersdk" + examples "github.com/coder/coder/templates" ) func templateInit() *cobra.Command { diff --git a/coderd/users.go b/coderd/users.go index 5b56509786d6c..6f792123694da 100644 --- a/coderd/users.go +++ b/coderd/users.go @@ -27,7 +27,7 @@ import ( "github.com/coder/coder/coderd/userpassword" "github.com/coder/coder/coderd/util/slice" "github.com/coder/coder/codersdk" - "github.com/coder/coder/examples" + examples "github.com/coder/coder/templates" ) // Returns whether the initial user has been created or not. diff --git a/examples/lima/README.md b/docs/recipes/lima/README.md similarity index 100% rename from examples/lima/README.md rename to docs/recipes/lima/README.md diff --git a/examples/lima/coder.yaml b/docs/recipes/lima/coder.yaml similarity index 100% rename from examples/lima/coder.yaml rename to docs/recipes/lima/coder.yaml diff --git a/examples/templates/bare/README.md b/examples/templates/bare/README.md deleted file mode 100644 index fff556b7e0a2e..0000000000000 --- a/examples/templates/bare/README.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -name: Bare (custom template) -description: Use this template as a starting point for writing custom templates with Terraform -tags: [bare] ---- - -See diff --git a/examples/templates/bare/main.tf b/examples/templates/bare/main.tf deleted file mode 100644 index b51b3e777c3e9..0000000000000 --- a/examples/templates/bare/main.tf +++ /dev/null @@ -1,58 +0,0 @@ -terraform { - required_providers { - coder = { - source = "coder/coder" - } - } -} - -# This example does not provision any resources. Use this -# template as a starting point for writing custom templates -# using any Terraform resource/provider. -# -# See: https://coder.com/docs/coder-oss/latest/templates - -data "coder_workspace" "me" { -} - -resource "coder_agent" "main" { - os = "linux" - arch = "amd64" - auth = "token" -} - -resource "null_resource" "fake-compute" { - # When a workspace is stopped, this resource is destroyed. - count = data.coder_workspace.me.transition == "start" ? 1 : 0 - - provisioner "local-exec" { - command = "echo 🔊 ${data.coder_workspace.me.owner} has started a workspace named ${data.coder_workspace.me.name}" - } - - # Run the Coder agent init script on resources - # to access web apps and SSH: - # - # export CODER_AGENT_TOKEN=${coder_agent.main.token} - # ${coder_agent.main.init_script} -} - -resource "null_resource" "fake-disk" { - # This resource will remain even when workspaces are restarted. - count = 1 -} - -resource "coder_app" "fake-app" { - # Access :8080 in the workspace from the Coder dashboard. - name = "VS Code" - icon = "/icon/code.svg" - agent_id = "fake-compute" - url = "http://localhost:8080" - subdomain = false - share = "owner" - - healthcheck { - url = "http://localhost:8080/healthz" - interval = 3 - threshold = 10 - } -} diff --git a/examples/templates/docker-code-server/README.md b/examples/templates/docker-code-server/README.md deleted file mode 100644 index 6d9045ad2d84e..0000000000000 --- a/examples/templates/docker-code-server/README.md +++ /dev/null @@ -1,25 +0,0 @@ ---- -name: Develop code-server in Docker -description: Run code-server in a Docker development environment -tags: [local, docker] ---- - -# code-server in Docker - -## Getting started - -Run `coder templates init` and select this template. Follow the instructions that appear. - -## Supported Parameters - -You can create a file containing parameters and pass the argument -`--parameter-file` to `coder templates create`. -See `params.sample.yaml` for more information. - -This template has the following predefined parameters: - -- `docker_host`: Path to (or address of) the Docker socket. - > You can determine the correct value for this by running - > `docker context ls`. -- `docker_arch`: Architecture of the host running Docker. - This can be `amd64`, `arm64`, or `armv7`. diff --git a/examples/templates/docker-code-server/main.tf b/examples/templates/docker-code-server/main.tf deleted file mode 100644 index 2e4f4f5b488bc..0000000000000 --- a/examples/templates/docker-code-server/main.tf +++ /dev/null @@ -1,78 +0,0 @@ -terraform { - required_providers { - coder = { - source = "coder/coder" - version = "0.5.3" - } - docker = { - source = "kreuzwerker/docker" - version = "~> 2.20.2" - } - } -} - -data "coder_provisioner" "me" { -} - -provider "docker" { -} - -data "coder_workspace" "me" { -} - -resource "coder_agent" "main" { - arch = data.coder_provisioner.me.arch - os = "linux" - startup_script = "code-server --auth none" - - # These environment variables allow you to make Git commits right away after creating a - # workspace. Note that they take precedence over configuration defined in ~/.gitconfig! - # You can remove this block if you'd prefer to configure Git manually or using - # dotfiles. (see docs/dotfiles.md) - env = { - GIT_AUTHOR_NAME = "${data.coder_workspace.me.owner}" - GIT_COMMITTER_NAME = "${data.coder_workspace.me.owner}" - GIT_AUTHOR_EMAIL = "${data.coder_workspace.me.owner_email}" - GIT_COMMITTER_EMAIL = "${data.coder_workspace.me.owner_email}" - } -} - -resource "coder_app" "code-server" { - agent_id = coder_agent.main.id - name = "code-server" - url = "http://localhost:8080/?folder=/home/coder" - icon = "/icon/code.svg" - subdomain = false - share = "owner" - - healthcheck { - url = "http://localhost:8080/healthz" - interval = 3 - threshold = 10 - } -} - -resource "docker_volume" "home_volume" { - name = "coder-${data.coder_workspace.me.owner}-${data.coder_workspace.me.name}-root" -} - -resource "docker_container" "workspace" { - count = data.coder_workspace.me.start_count - image = "codercom/code-server:latest" - # Uses lower() to avoid Docker restriction on container names. - name = "coder-${data.coder_workspace.me.owner}-${lower(data.coder_workspace.me.name)}" - hostname = lower(data.coder_workspace.me.name) - dns = ["1.1.1.1"] - # Use the docker gateway if the access URL is 127.0.0.1 - entrypoint = ["sh", "-c", replace(coder_agent.main.init_script, "/localhost|127\\.0\\.0\\.1/", "host.docker.internal")] - env = ["CODER_AGENT_TOKEN=${coder_agent.main.token}"] - host { - host = "host.docker.internal" - ip = "host-gateway" - } - volumes { - container_path = "/home/coder/" - volume_name = docker_volume.home_volume.name - read_only = false - } -} diff --git a/examples/templates/docker-code-server/params.sample.yaml b/examples/templates/docker-code-server/params.sample.yaml deleted file mode 100644 index 580e0ed137d30..0000000000000 --- a/examples/templates/docker-code-server/params.sample.yaml +++ /dev/null @@ -1,2 +0,0 @@ -docker_host: "unix:///var/run/docker.sock" -docker_arch: "amd64" diff --git a/examples/templates/gcp-vm-container/README.md b/examples/templates/gcp-vm-container/README.md deleted file mode 100644 index 72c5d20fc9b7f..0000000000000 --- a/examples/templates/gcp-vm-container/README.md +++ /dev/null @@ -1,51 +0,0 @@ ---- -name: Develop in a container on a Google Cloud VM -description: Get started with Linux development on Google Cloud. -tags: [cloud, google, container] ---- - -# gcp-vm-container - -To get started, run `coder templates init`. When prompted, select this template, -and follow the on-screen instructions to proceed. - -## Authentication - -This template assumes that coderd is run in an environment that is authenticated -with Google Cloud. For example, run `gcloud auth application-default login` to -import credentials on the system and user running coderd. For other ways to -authenticate [consult the Terraform -docs](https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/getting_started#adding-credentials). - -## Service account - -Coder requires a Google Cloud Service Account to provision workspaces. To create -a service account: - -1. Navigate to the [CGP - console](https://console.cloud.google.com/projectselector/iam-admin/serviceaccounts/create), - and select your Cloud project (if you have more than one project associated - with your account) - -1. Provide a service account name (this name is used to generate the service - account ID) - -1. Click **Create and continue**, and choose the following IAM roles to grant to - the service account: - - Compute Admin - - Service Account User - - Click **Continue**. - -1. Click on the created key, and navigate to the **Keys** tab. - -1. Click **Add key** > **Create new key**. - -1. Generate a **JSON private key**, which will be what you provide to Coder - during the setup process. - -## code-server - -`code-server` is installed via the `startup_script` argument in the `coder_agent` -resource block. The `coder_app` resource is defined to access `code-server` through -the dashboard UI over `localhost:13337`. diff --git a/examples/templates/gcp-vm-container/main.tf b/examples/templates/gcp-vm-container/main.tf deleted file mode 100644 index 753a2535fe0a9..0000000000000 --- a/examples/templates/gcp-vm-container/main.tf +++ /dev/null @@ -1,123 +0,0 @@ -terraform { - required_providers { - coder = { - source = "coder/coder" - version = "0.5.3" - } - google = { - source = "hashicorp/google" - version = "~> 4.34.0" - } - } -} - -variable "project_id" { - description = "Which Google Compute Project should your workspace live in?" -} - -variable "zone" { - description = "What region should your workspace live in?" - default = "us-central1-a" - validation { - condition = contains(["northamerica-northeast1-a", "us-central1-a", "us-west2-c", "europe-west4-b", "southamerica-east1-a"], var.zone) - error_message = "Invalid zone!" - } -} - -provider "google" { - zone = var.zone - project = var.project_id -} - -data "google_compute_default_service_account" "default" { -} - -data "coder_workspace" "me" { -} - -resource "coder_agent" "main" { - auth = "google-instance-identity" - arch = "amd64" - os = "linux" - startup_script = <