Skip to content
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

vscode-web module doesn't apply settings.json and takes long time to install #364

Open
duchuyvp opened this issue Dec 8, 2024 · 3 comments
Labels
help wanted Extra attention is needed

Comments

@duchuyvp
Copy link

duchuyvp commented Dec 8, 2024

For context, I'm using vscode-web module on Coder template, I defined module in main.tf as follow:

module "vscode-web" {
  source   = "registry.coder.com/modules/vscode-web/coder"
  version  = "1.0.22"
  agent_id = coder_agent.main.id
  extensions = [
    "github.copilot",
    "ms-python.python",
    "ms-toolsai.jupyter",
  ]
  accept_license = true

  # my personal settings.
  settings = {
    "workbench.colorTheme"                    = "Dark Modern",
    "terminal.integrated.cursorBlinking"      = true,
    "terminal.integrated.cursorStyle"         = "line",
    "terminal.integrated.cursorStyleInactive" = "none",
    "terminal.integrated.fontSize"            = 16,
    "git.autofetch"                           = true,
    "editor.fontSize"                         = 16,
    "editor.suggestSelection"                 = "first",
    "editor.linkedEditing"                    = true,
  }

  folder    = "/workspaces"
}

First, it takes long time to install vscode on workspaces create from template, this build timeline that I capture from coder web:

Image
Image
Image
Since other modules don't take much time like vscode-web, I think it is vscode-web's problem.

And second, even I spec my personal settings.json but it's not apply on vscode-web (extensions still works well)

Help me, please. Thank you.

@matifali matifali transferred this issue from coder/terraform-provider-coder Dec 12, 2024
@coder-labeler coder-labeler bot added docs Improvements or additions to documentation help wanted Extra attention is needed labels Dec 12, 2024
@matifali
Copy link
Member

matifali commented Dec 12, 2024

Thank you for reporting the issue. We will look into it.

This looks related to #296
cc: @phorcys420

@matifali matifali removed the docs Improvements or additions to documentation label Dec 12, 2024
@phorcys420
Copy link
Member

hello @duchuyvp, very sorry for the delayed answer.
have you solved this issue?

if not, please provude us with the following:

  • Coder version
  • Template file

@duchuyvp
Copy link
Author

duchuyvp commented Jan 2, 2025

@phorcys420 thank you for noticed.

I'm using coder installed from helm chart version 2.17.3
Template file as follow:

terraform {
  required_providers {
    coder = {
      source = "coder/coder"
    }
    kubernetes = {
      source = "hashicorp/kubernetes"
    }
    envbuilder = {
      source = "coder/envbuilder"
    }
  }
}

provider "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
}
provider "envbuilder" {}

data "coder_provisioner" "me" {}
data "coder_workspace" "me" {}
data "coder_workspace_owner" "me" {}
data "coder_external_auth" "github" {
  id = "primary-github"
}


data "coder_parameter" "workspaces_volume_size" {
  name         = "workspaces_volume_size"
  display_name = "Workspaces volume size"
  description  = "Size of the `/workspaces` volume (GiB)."
  default      = "10"
  type         = "number"
  icon         = "/emojis/1f4be.png"
  mutable      = false
  validation {
    min = 1
    max = 99999
  }
  order = 3
}

data "coder_parameter" "repo" {
  description  = "Select a repository to automatically clone and start working with a devcontainer."
  display_name = "Repository (auto)"
  mutable      = true
  name         = "repo"
  order        = 4
  type         = "string"
}

data "coder_parameter" "fallback_image" {
  default      = "codercom/enterprise-base:ubuntu"
  description  = "This image runs if the devcontainer fails to build."
  display_name = "Fallback Image"
  mutable      = true
  name         = "fallback_image"
  order        = 6
}

data "coder_parameter" "devcontainer_builder" {
  description  = <<-EOF
  Image that will build the devcontainer.
  We highly recommend using a specific release as the `:latest` tag will change.
  Find the latest version of Envbuilder here: https://github.com/coder/envbuilder/pkgs/container/envbuilder
  EOF
  display_name = "Devcontainer Builder"
  mutable      = true
  name         = "devcontainer_builder"
  default      = "ghcr.io/coder/envbuilder:latest"
  order        = 7
}



data "kubernetes_secret" "cache_repo_dockerconfig_secret" {
  count = var.cache_repo_secret_name == "" ? 0 : 1
  metadata {
    name      = var.cache_repo_secret_name
    namespace = var.namespace
  }
}

locals {
  deployment_name            = "coder-${lower(data.coder_workspace.me.id)}"
  devcontainer_builder_image = data.coder_parameter.devcontainer_builder.value
  git_author_name            = coalesce(data.coder_workspace_owner.me.full_name, data.coder_workspace_owner.me.name)
  git_author_email           = data.coder_workspace_owner.me.email
  repo_url                   = data.coder_parameter.repo.value
  # The envbuilder provider requires a key-value map of environment variables.
  envbuilder_env = {
    # ENVBUILDER_GIT_URL and ENVBUILDER_CACHE_REPO will be overridden by the provider
    # if the cache repo is enabled.
    "ENVBUILDER_GIT_USERNAME" : data.coder_external_auth.github.access_token,
    "ENVBUILDER_GIT_URL" : local.repo_url,
    # "ENVBUILDER_CACHE_REPO" : var.cache_repo,
    "CODER_AGENT_TOKEN" : coder_agent.main.token,
    # Use the docker gateway if the access URL is 127.0.0.1
    "CODER_AGENT_URL" : replace(data.coder_workspace.me.access_url, "/localhost|127\\.0\\.0\\.1/", "host.docker.internal"),
    # Use the docker gateway if the access URL is 127.0.0.1
    "ENVBUILDER_INIT_SCRIPT" : replace(coder_agent.main.init_script, "/localhost|127\\.0\\.0\\.1/", "host.docker.internal"),
    "ENVBUILDER_FALLBACK_IMAGE" : data.coder_parameter.fallback_image.value,
    "ENVBUILDER_DOCKER_CONFIG_BASE64" : base64encode(try(data.kubernetes_secret.cache_repo_dockerconfig_secret[0].data[".dockerconfigjson"], "")),
    "ENVBUILDER_PUSH_IMAGE" : var.cache_repo == "" ? "" : "true",
    "ENVBUILDER_INSECURE" : "${var.insecure_cache_repo}",
    # You may need to adjust this if you get an error regarding deleting files when building the workspace.
    # For example, when testing in KinD, it was necessary to set `/product_name` and `/product_uuid` in
    # addition to `/var/run`.
    # "ENVBUILDER_IGNORE_PATHS": "/product_name,/product_uuid,/var/run",
  }
}

# Check for the presence of a prebuilt image in the cache repo
# that we can use instead.
resource "envbuilder_cached_image" "cached" {
  count         = var.cache_repo == "" ? 0 : data.coder_workspace.me.start_count
  builder_image = local.devcontainer_builder_image
  git_url       = local.repo_url
  cache_repo    = var.cache_repo
  extra_env     = local.envbuilder_env
  insecure      = var.insecure_cache_repo
}

resource "kubernetes_persistent_volume_claim" "workspaces" {
  metadata {
    name      = "coder-${lower(data.coder_workspace.me.id)}-workspaces"
    namespace = var.namespace
    labels = {
      "app.kubernetes.io/name"     = "coder-${lower(data.coder_workspace.me.id)}-workspaces"
      "app.kubernetes.io/instance" = "coder-${lower(data.coder_workspace.me.id)}-workspaces"
      "app.kubernetes.io/part-of"  = "coder"
      //Coder-specific labels.
      "com.coder.resource"       = "true"
    }
    annotations = {
      "com.coder.user.email" = data.coder_workspace_owner.me.email
    }
  }
  wait_until_bound = false
  spec {
    access_modes = ["ReadWriteOnce"]
    resources {
      requests = {
        storage = "${data.coder_parameter.workspaces_volume_size.value}Gi"
      }
    }
  }
}

resource "kubernetes_deployment" "main" {
  count = data.coder_workspace.me.start_count
  depends_on = [
    kubernetes_persistent_volume_claim.workspaces
  ]
  wait_for_rollout = false
  metadata {
    name      = local.deployment_name
    namespace = var.namespace
    labels = {
      "app.kubernetes.io/name"     = "coder-workspace"
      "app.kubernetes.io/instance" = local.deployment_name
      "app.kubernetes.io/part-of"  = "coder"
      "com.coder.resource"         = "true"
    }
    annotations = {
      "com.coder.user.email" = data.coder_workspace_owner.me.email
    }
  }

  spec {
    replicas = 1
    selector {
      match_labels = {
        "app.kubernetes.io/name"    = "coder-workspace"
        "app.kubernetes.io/part-of" = "coder"
      }
    }
    strategy {
      type = "Recreate"
    }

    template {
      metadata {
        labels = {
          "app.kubernetes.io/name"    = "coder-workspace"
          "app.kubernetes.io/part-of" = "coder"
        }
      }
      spec {
        security_context {}
        container {
          name              = "dev"
          image             = var.cache_repo == "" ? local.devcontainer_builder_image : envbuilder_cached_image.cached.0.image
          image_pull_policy = "Always"
          security_context {}
          dynamic "env" {
            for_each = nonsensitive(var.cache_repo == "" ? local.envbuilder_env : envbuilder_cached_image.cached.0.env_map)
            content {
              name  = env.key
              value = env.value
            }
          }
          volume_mount {
            mount_path = "/workspaces"
            name       = "workspaces"
            read_only  = false
          }
        }
        volume {
          name = "workspaces"
          persistent_volume_claim {
            claim_name = kubernetes_persistent_volume_claim.workspaces.metadata.0.name
            read_only  = false
          }
        }
      }
    }
  }
}

resource "coder_agent" "main" {
  arch           = data.coder_provisioner.me.arch
  os             = "linux"
  startup_script = <<-EOT
    set -e

  EOT
  dir            = "/workspaces"

  env = {
    GIT_AUTHOR_NAME     = local.git_author_name
    GIT_AUTHOR_EMAIL    = local.git_author_email
    GIT_COMMITTER_NAME  = local.git_author_name
    GIT_COMMITTER_EMAIL = local.git_author_email
  }

}


module "vscode-web" {
  source   = "registry.coder.com/modules/vscode-web/coder"
  version  = "1.0.22"
  agent_id = coder_agent.main.id
  extensions = [
    "github.copilot",
    "ms-python.python",
    "ms-toolsai.jupyter",
    "dracula-theme.theme-dracula",
    "formulahendry.code-runner",
    "github.vscode-github-actions",
    "github.vscode-pull-request-github",
    "eamodio.gitlens",
    "visualstudioexptteam.vscodeintellicode",
    "ms-python.isort",
    "ms-vscode.makefile-tools",
    "ms-vscode.cpptools",
    "davidanson.vscode-markdownlint",
    "redhat.vscode-yaml",
  ]
  accept_license = true
  settings = {
    "workbench.colorTheme"                    = "Default Dark Modern",
    "terminal.integrated.cursorBlinking"      = true,
    "terminal.integrated.cursorStyle"         = "line",
    "terminal.integrated.cursorStyleInactive" = "none",
    "terminal.integrated.fontSize"            = 16,
    "terminal.integrated.fontFamily"          = "FiraCode Nerd Font",
    "code-runner.runInTerminal"               = true,
    "code-runner.saveFileBeforeRun"           = true,
    "git.autofetch"                           = true,
    "editor.fontFamily"                       = "FiraCode Nerd Font",
    "editor.fontWeight"                       = "500",
    "editor.fontSize"                         = 16,
    "editor.fontLigatures"                    = "'ss01', 'ss02', 'ss03', 'ss04', 'ss05', 'ss06', 'zero'",
    "editor.suggestSelection"                 = "first",
    "editor.linkedEditing"                    = true,
  }

  folder = "/workspaces"
}

Additional info may helps: I was watching logs when building workspace, I see no logs line like

echo "⚙️ Creating settings file..."

And when workspace was built, there also a file at ~/.vscode-server/data/Machine/settings.json, does it already there before the run.sh script excuted?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants