- Notifications
You must be signed in to change notification settings - Fork927
example: add and document dotfiles usage#2046
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
3 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
5 changes: 5 additions & 0 deletionsdocs/workspaces.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletionsexamples/templates/docker-with-dotfiles/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
name: Develop in Docker with a dotfiles URL | ||
description: Run workspaces on a Docker host using registry images | ||
tags: [local, docker] | ||
--- | ||
# docker-with-dotfiles | ||
This is an example for deploying workspaces with a prompt for the users' dotfiles repo URI. | ||
## Getting started | ||
Run `coder templates init` and select this template. Follow the instructions that appear. | ||
## How it works | ||
During workspace creation, Coder prompts you to specify a dotfiles URL via a Terraform variable. Once the workspace starts, the Coder agent runs `coder dotfiles` via the startup script: | ||
```hcl | ||
variable "dotfiles_uri" { | ||
description = <<-EOF | ||
Dotfiles repo URI (optional) | ||
see https://dotfiles.github.io | ||
EOF | ||
# The codercom/enterprise-* images are only built for amd64 | ||
default = "" | ||
} | ||
resource "coder_agent" "dev" { | ||
... | ||
startup_script = var.dotfiles_uri != "" ? "/tmp/tmp.coder*/coder dotfiles -y ${var.dotfiles_uri}" : null | ||
bpmct marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
} | ||
``` | ||
# Managing images and workspaces | ||
Refer to the documentation in the [Docker template](../docker/README.md). |
68 changes: 68 additions & 0 deletionsexamples/templates/docker-with-dotfiles/main.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# Note: this example demonstrates the use of | ||
# dotfiles with Coder templates. | ||
# The Docker aspect of the template only works | ||
# with MacOS/Linux amd64 systems. See the full | ||
# Docker example for details | ||
terraform { | ||
required_providers { | ||
coder = { | ||
source = "coder/coder" | ||
version = "0.4.1" | ||
} | ||
docker = { | ||
source = "kreuzwerker/docker" | ||
version = "~> 2.16.0" | ||
} | ||
} | ||
} | ||
provider "docker" { | ||
host = "unix:///var/run/docker.sock" | ||
} | ||
provider "coder" { | ||
} | ||
data "coder_workspace" "me" { | ||
} | ||
variable "dotfiles_uri" { | ||
description = <<-EOF | ||
Dotfiles repo URI (optional) | ||
see https://dotfiles.github.io | ||
EOF | ||
default = "" | ||
} | ||
resource "coder_agent" "dev" { | ||
arch = "amd64" | ||
os = "linux" | ||
startup_script = var.dotfiles_uri != "" ? "coder dotfiles -y ${var.dotfiles_uri}" : null | ||
} | ||
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/enterprise-base:ubuntu" | ||
# Uses lower() to avoid Docker restriction on container names. | ||
name = "coder-${data.coder_workspace.me.owner}-${lower(data.coder_workspace.me.name)}" | ||
dns = ["1.1.1.1"] | ||
# Refer to Docker host when Coder is on localhost | ||
command = ["sh", "-c", replace(coder_agent.dev.init_script, "127.0.0.1", "host.docker.internal")] | ||
env = ["CODER_AGENT_TOKEN=${coder_agent.dev.token}"] | ||
host { | ||
host = "host.docker.internal" | ||
ip = "host-gateway" | ||
} | ||
volumes { | ||
container_path = "/home/coder/" | ||
volume_name = docker_volume.home_volume.name | ||
read_only = false | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.