Skip to content

example: add docker-image-builds + docker docs #1526

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

Merged
merged 23 commits into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixes from feedback
  • Loading branch information
bpmct committed May 18, 2022
commit a747cec844e4ef06312f13c7a544977d54ac5acc
12 changes: 6 additions & 6 deletions examples/docker-image-builds/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ Edit the validation to include the new image:

```diff
variable "docker_image" {
description = "What docker image would you like to use for your workspace?"
description = "What Docker imagewould 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!"
error_message = "Invalid Docker image!"
}
}
```
Expand Down Expand Up @@ -91,11 +91,11 @@ 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 the workspace is updated to the latest version.
the removed image until you update the workspace to the latest version.

## Updating images

Edit the Dockerfile (or related assets)
Edit the Dockerfile (or related assets):

```sh
vim images/node.Dockerfile
Expand All @@ -109,7 +109,7 @@ RUN DEBIAN_FRONTEND="noninteractive" apt-get update -y && \
apt-get install -y nodejs
```

1. Edit the template Terraform (`main.tf`)
1. Edit the Terraform template (`main.tf`)

```sh
vim main.tf
Expand Down Expand Up @@ -156,4 +156,4 @@ add the following features to your Coder template:
- Custom container spec
- More

Contributions are also welcome!
We also welcome all contributions!
6 changes: 3 additions & 3 deletions examples/docker-image-builds/images/java.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ ENV MAVEN_HOME /usr/share/maven
ENV MAVEN_CONFIG "/home/coder/.m2"

RUN mkdir -p $MAVEN_HOME $MAVEN_HOME/ref \
&& echo "Downloading maven" \
&& echo "Downloading Maven" \
&& curl -fsSL -o /tmp/apache-maven.tar.gz https://apache.osuosl.org/maven/maven-3/${MAVEN_VERSION}/binaries/apache-maven-${MAVEN_VERSION}-bin.tar.gz \
\
&& echo "Checking downloaded file hash" \
&& echo "${MAVEN_SHA512} /tmp/apache-maven.tar.gz" | sha512sum -c - \
\
&& echo "Unzipping maven" \
&& echo "Unzipping Maven" \
&& tar -xzf /tmp/apache-maven.tar.gz -C $MAVEN_HOME --strip-components=1 \
\
&& echo "Cleaning and setting links" \
Expand All @@ -38,7 +38,7 @@ ARG GRADLE_SHA512=d495bc65379d2a854d2cca843bd2eeb94f381e5a7dcae89e6ceb6ef4c58355
ENV GRADLE_HOME /usr/bin/gradle

RUN mkdir -p /usr/share/gradle /usr/share/gradle/ref \
&& echo "Downloading gradle" \
&& echo "Downloading Gradle" \
&& curl -fsSL -o /tmp/gradle.zip https://services.gradle.org/distributions/gradle-${GRADLE_VERSION}-bin.zip \
\
&& echo "Checking downloaded file hash" \
Expand Down
8 changes: 4 additions & 4 deletions examples/docker-image-builds/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ variable "step2_arch" {
description = "arch: What archicture is your Docker host on?"
validation {
condition = contains(["amd64", "arm64", "armv7"], var.step2_arch)
error_message = "Value must be amd64, arm64 or armv7."
error_message = "Value must be amd64, arm64, or armv7."
}
sensitive = true
}
Expand All @@ -54,20 +54,20 @@ resource "coder_agent" "dev" {
}

variable "docker_image" {
description = "What docker image would you like to use for your workspace?"
description = "What Docker imagewould 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)
error_message = "Invalid Docker Image!"
error_message = "Invalid Docker image!"
}

# Prevents admin errors when the image is not found
validation {
condition = fileexists("images/${var.docker_image}.Dockerfile")
error_message = "Invalid docker image. The file does not exist in the images directory."
error_message = "Invalid Docker image. The file does not exist in the images directory."
}
}

Expand Down
17 changes: 8 additions & 9 deletions examples/docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,25 @@ tags: [local, docker]

## Getting started

Pick this template in `coder templates init` and follow instructions.
Run `coder templates init` and select this template. Follow the instructions that appear.

## Adding/removing images

After building and pushing an image to an image registry (e.g DockerHub), you can make the
image available to users in the template.
After building and pushing an image to an image registry (e.g., DockerHub), you can edit the template to make the image available to users.

Edit the template:

```sh
vim main.tf
```
variable "docker_image" {
description = "What docker image would you like to use for your workspace?"
description = "What Docker imagewould you like to use for your workspace?"
default = "codercom/enterprise-base:ubuntu"
validation {
- condition = contains(["codercom/enterprise-base:ubuntu", "codercom/enterprise-node:ubuntu", "codercom/enterprise-intellij:ubuntu"], var.docker_image)
+ condition = contains(["codercom/enterprise-base:ubuntu", "codercom/enterprise-node:ubuntu", "codercom/enterprise-intellij:ubuntu", "codercom/enterprise-golang:ubuntu"], var.docker_image)

error_message = "Invalid Docker Image!"
error_message = "Invalid Docker image!"
}
}
```
Expand All @@ -38,16 +37,16 @@ Update the template:
coder template update docker
```

Images can also be removed from the validation list. Workspaces using older template versions will continue using
the removed image until the workspace is updated to the latest version.
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

To reduce drift, we recommend versioning images in your registry via tags. Update the image tag in the template:
To reduce drift, we recommend versioning images in your registry by creating tags. To update the image tag in the template:

```sh
variable "docker_image" {
description = "What docker image would you like to use for your workspace?"
description = "What Docker imagewould you like to use for your workspace?"
default = "codercom/enterprise-base:ubuntu"
validation {
- condition = contains(["my-org/base-development:v1.1", "myorg-java-development:v1.1"], var.docker_image)
Expand Down
2 changes: 1 addition & 1 deletion examples/docker/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ variable "docker_image" {
default = "codercom/enterprise-base:ubuntu"
validation {
condition = contains(["codercom/enterprise-base:ubuntu", "codercom/enterprise-node:ubuntu", "codercom/enterprise-intellij:ubuntu"], var.docker_image)
error_message = "Invalid Docker Image!"
error_message = "Invalid Docker image!"
}

}
Expand Down