* Pass workspace owner email address to provisioner * Remove owner_email and owner_username fields from agent metadata * Add Git environment variables to example templates * Remove "owner_name" field from provisioner metadata, use username instead * Remove Git configuration from most templates, add documentation * Proofreading/typo fixes from @mafredri * Update example templates to latest version of terraform-provider-coder
name, description, tags
name | description | tags | ||
---|---|---|---|---|
Develop in Docker with custom image builds | Build images and run workspaces on the Docker host with no image registry required |
|
docker-image-builds
This example bundles Dockerfiles with the Coder template, allowing the Docker host to build images itself instead of relying on an external registry.
For large use cases, we recommend building images using CI/CD pipelines and registries instead of at workspace runtime. However, this example is practical for tinkering and iterating on Dockerfiles.
Getting started
Run coder templates init
. When prompted, select this template, and follow the
on-screen instructions to proceed.
Adding images
Create a Dockerfile (e.g images/golang.Dockerfile
):
vim images/golang.Dockerfile
# Start from base image (built on Docker host)
FROM coder-base:latest
# Install everything as root
USER root
# Install go
RUN curl -L "https://dl.google.com/go/go1.18.1.linux-amd64.tar.gz" | tar -C /usr/local -xzvf -
# Setup go env vars
ENV GOROOT /usr/local/go
ENV PATH $PATH:$GOROOT/bin
ENV GOPATH /home/coder/go
ENV GOBIN $GOPATH/bin
ENV PATH $PATH:$GOBIN
# Set back to coder user
USER coder
Edit the Terraform template (main.tf
):
vim main.tf
Edit the validation to include the new image:
variable "docker_image" {
description = "What Docker image would you like to use for your workspace?"
default = "base"
# List of images available for the user to choose from.
# Delete this condition to give users free text input.
validation {
- condition = contains(["base", "java", "node"], var.docker_image)
+ condition = contains(["base", "java", "node", "golang], var.docker_image)
error_message = "Invalid Docker image!"
}
}
Bump the image tag to a new version:
resource "docker_image" "coder_image" {
name = "coder-base-${data.coder_workspace.me.owner}-${lower(data.coder_workspace.me.name)}"
build {
path = "./images/"
dockerfile = "${var.docker_image}.Dockerfile"
- tag = ["coder-${var.docker_image}:v0.1"]
+ tag = ["coder-${var.docker_image}:v0.2"]
}
# Keep alive for other workspaces to use upon deletion
keep_locally = true
}
Update the template:
coder template update docker-image-builds
You can also remove images from the validation list. Workspaces using older template versions will continue using the removed image until you update the workspace to the latest version.
Updating images
Edit the Dockerfile (or related assets):
vim images/node.Dockerfile
# Install Node
- RUN curl -sL https://deb.nodesource.com/setup_14.x | bash -
+ RUN curl -sL https://deb.nodesource.com/setup_16.x | bash -
RUN DEBIAN_FRONTEND="noninteractive" apt-get update -y && \
apt-get install -y nodejs
- Edit the Terraform template (
main.tf
)
vim main.tf
Bump the image tag to a new version:
resource "docker_image" "coder_image" {
name = "coder-base-${data.coder_workspace.me.owner}-${lower(data.coder_workspace.me.name)}"
build {
path = "./images/"
dockerfile = "${var.docker_image}.Dockerfile"
- tag = ["coder-${var.docker_image}:v0.1"]
+ tag = ["coder-${var.docker_image}:v0.2"]
}
# Keep alive for other workspaces to use upon deletion
keep_locally = true
}
Update the template:
coder template update docker-image-builds
Optional: Update workspaces to the latest template version
coder ls
coder update [workspace name]
Extending this template
See the kreuzwerker/docker Terraform provider documentation to add the following features to your Coder template:
- SSH/TCP docker host
- Build args
- Volume mounts
- Custom container spec
- More
We also welcome all contributions!