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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(code-server): add code-server offline support #184

Merged
merged 10 commits into from
Mar 19, 2024

Conversation

michaelbrewer
Copy link
Contributor

@michaelbrewer michaelbrewer commented Mar 12, 2024

Changes

  • Add "used_cached" which uses the cached copy of code-server if found, otherwise installs it from Github along with any extensions
  • Add "offline" which uses the offline copy of code-server, and if not found returns an error
  • Both modes applies any settings
  • Both modes can not be used at the same time
  • offline mode does not allow for extensions to be installed

Checklist

  • Implement use_cached mode
  • Implement offline mode
  • Add more notes on offline support and reference other code documentation
  • Add validation checks
  • Add terraform unit tests
  • Add bash unit tests
  • Update docs to reference guides on air-gapped installs

Documentation examples

By default the module looks for code-server at /tmp/code-server but this can be changed with install_prefix.

Run an existing copy of code-server if found, otherwise download from GitHub:

module "code-server" {
  source     = "registry.coder.com/modules/code-server/coder"
  version    = "1.0.8"
  agent_id   = coder_agent.example.id
  use_cached = true
  extensions = ["dracula-theme.theme-dracula", "ms-azuretools.vscode-docker"]
}

Just run code-server in the background, don't fetch it from GitHub:

module "code-server" {
  source   = "registry.coder.com/modules/code-server/coder"
  version  = "1.0.8"
  agent_id = coder_agent.example.id
  offline  = true
}

Test cases

When offline is true and there is no copy of code-server is found

module "code-server" {
  source     = "registry.coder.com/modules/code-server/coder"
  version    = "1.0.8"
  agent_id   = coder_agent.example.id
  offline    = true
}

Then expect runtime error

Failed to find a copy of code-server

When use_cached is true and there is no copy of code-server is found

module "code-server" {
  source     = "registry.coder.com/modules/code-server/coder"
  version    = "1.0.8"
  agent_id   = coder_agent.example.id
  use_cached = true
  extensions = ["dracula-theme.theme-dracula", "ms-azuretools.vscode-docker"]
}

Then expect code-server to be installed

Installing code-server!
馃コ code-server has been installed in /home/local/.code-server
馃З Installing extension dracula-theme.theme-dracula...
馃З Installing extension ms-azuretools.vscode-docker...
馃懛 Running code-server in the background...
Check logs at /tmp/code-server.log!

When use_cached is true and offline is true

module "code-server" {
  source     = "registry.coder.com/modules/code-server/coder"
  version    = "1.0.8"
  agent_id   = coder_agent.example.id
  offline    = true
  use_cached = true
}

Then expect terraform validation error

Offline and Use Cached can not be used together

When offline is true and extensions are set

module "code-server" {
  source     = "registry.coder.com/modules/code-server/coder"
  version    = "1.0.8"
  agent_id   = coder_agent.example.id
  offline    = true
  extensions = ["dracula-theme.theme-dracula", "ms-azuretools.vscode-docker"]
}

Then expect terraform validation error

Offline mode does not allow extensions to be installed

When offline or use_cached is true and a copy of code-server is found then just run code-server in background

馃コ Found a copy of code-server
馃懛 Running code-server in the background...
Check logs at /tmp/code-server.log!

Notes on air-gapped installations

Some cases for running offline installs of code-server with extensions, is for performance reasons, or because the egress controls on the workspace is tightly controlled or is completely air-gapped.

There is also cases where the coder terraform provisioner is also air-gapped, for which you might have modules hosted on an air-gapped terraform enterprise, other methods are in the coder documentation. It might also be useful to link to the coder offline docs

related to #181

@michaelbrewer
Copy link
Contributor Author

@matifali - this is a draft PR to add support for "offline" and maybe an option for download caching (so it only installed on first launch)

@code-asher
Copy link
Member

Is this ready for review or should I wait until it comes out of draft?

@michaelbrewer
Copy link
Contributor Author

Is this ready for review or should I wait until it comes out of draft?

It's a draft, as I want to see if it makes sense to add an option to use cached installed too

@michaelbrewer michaelbrewer marked this pull request as ready for review March 15, 2024 00:30
@michaelbrewer
Copy link
Contributor Author

@code-asher it's ready to look at.

I did observe a weird behavior, when running from a cached version the "code-server" is available sooner, but the window is blank intialy. Also when it is open resizing the window does not repaint.

Copy link
Member

@code-asher code-asher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I did not notice anything abnormal with the window when I ran with a cached copy.

code-server/README.md Show resolved Hide resolved
michaelbrewer and others added 3 commits March 15, 2024 14:34
Co-authored-by: Asher <ash@coder.com>
Changes:
- Update docs to include use_cached mode
- Add validation checks
- Add support for use_cached mode
Copy link
Member

@code-asher code-asher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! I just have a question about a variable name in an error message.

code-server/main.tf Show resolved Hide resolved
code-server/main.tf Show resolved Hide resolved
@code-asher code-asher merged commit fc91462 into coder:main Mar 19, 2024
2 checks passed
@michaelbrewer michaelbrewer deleted the feat/code-server-offline branch March 19, 2024 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants