Skip to content

Commit

Permalink
fix: Improve docker example first user experience (#4972)
Browse files Browse the repository at this point in the history
The base ubuntu image lands the user as root, but the terraform tempalte
expected /home/coder to be used. This change adds a user with the same
name as the Coder users username and allows them to sudo.
  • Loading branch information
mafredri committed Nov 10, 2022
1 parent 4885ecc commit 570a1ff
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
17 changes: 16 additions & 1 deletion examples/templates/docker/build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
FROM ubuntu

RUN apt-get update && apt-get install -y curl wget git vim golang
RUN apt-get update \
&& apt-get install -y \
curl \
git \
golang \
sudo \
vim \
wget \
&& rm -rf /var/lib/apt/lists/*

ARG USER=coder
RUN useradd --groups sudo --no-create-home ${USER} \
&& echo "${USER} ALL=(ALL) NOPASSWD:ALL" >/etc/sudoers.d/${USER} \
&& chmod 0440 /etc/sudoers.d/${USER}
USER ${USER}
WORKDIR /home/${USER}
11 changes: 9 additions & 2 deletions examples/templates/docker/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ terraform {
}
}

locals {
username = data.coder_workspace.me.owner
}

data "coder_provisioner" "me" {
}

Expand Down Expand Up @@ -46,7 +50,7 @@ resource "coder_app" "code-server" {
agent_id = coder_agent.main.id
slug = "code-server"
display_name = "code-server"
url = "http://localhost:13337/?folder=/home/coder"
url = "http://localhost:13337/?folder=/home/${local.username}"
icon = "/icon/code.svg"
subdomain = false
share = "owner"
Expand Down Expand Up @@ -91,6 +95,9 @@ resource "docker_image" "main" {
name = "coder-${data.coder_workspace.me.id}"
build {
path = "./build"
build_arg = {
USER = local.username
}
}
triggers = {
dir_sha1 = sha1(join("", [for f in fileset(path.module, "build/*") : filesha1(f)]))
Expand All @@ -112,7 +119,7 @@ resource "docker_container" "workspace" {
ip = "host-gateway"
}
volumes {
container_path = "/home/coder/"
container_path = "/home/${local.username}"
volume_name = docker_volume.home_volume.name
read_only = false
}
Expand Down

0 comments on commit 570a1ff

Please sign in to comment.