Thanks to visit codestin.com
Credit goes to github.com

Skip to content

docs: simplify Docker quickstart #4257

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 5 commits into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ site/**/*.typegen.ts
site/build-storybook.log

# Build
build/
dist/
/build/
/dist/
site/out/

*.tfstate
Expand Down
1 change: 1 addition & 0 deletions coderd/database/migrations/000054_email_case.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP INDEX users_email_lower_idx;
7 changes: 4 additions & 3 deletions docs/admin/audit-logs.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Audit Logs

This is an enterprise feature that allows **Admins** and **Auditors** to monitor what is happening in their deployment.
Audit Logs allows **Admins** and **Auditors** to monitor user operations in
their deployment.

## Tracked Events

This feature tracks **create, update and delete** events for the following resources:
We track **create, update and delete** events for the following resources:

- GitSSHKey
- Template
Expand All @@ -31,4 +32,4 @@ The supported filters are:

## Enabling this feature

This feature is autoenabled for all enterprise deployments. An Admin can contact us to purchase a license [here](https://coder.com/contact?note=I%20want%20to%20upgrade%20my%20license).
This feature is autoenabled for all enterprise deployments. Admins may contact us to purchase a license [here](https://coder.com/contact?note=I%20want%20to%20upgrade%20my%20license).
Binary file modified docs/images/quickstart/docker/create-workspace.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 18 additions & 39 deletions docs/quickstart/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,54 +15,29 @@ Coder with Docker has the following advantages:

1. [Install and launch Coder](../install)

You will specify `CODER_ACCESS_URL=http://localhost:7080` since we're using
local Docker workspaces exclusively. `CODER_ACCESS_URL` is the external URL
to access Coder. The rest of the Docker quickstart guide will assume that
this is your Access URL.

You will also specify `CODER_ADDRESS=0.0.0.0:7080` which is the address to
serve the API and dashboard.
Next, we export the `CODER_ADDRESS` and `CODER_ACCESS_URL` environment
variables. We can use localhost for the Access URL since the workspaces
all run on the same machine. `CODER_ADDRESS` is where coder server binds
Copy link
Contributor

Choose a reason for hiding this comment

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

😍

Copy link
Member Author

Choose a reason for hiding this comment

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

I did it!

while `CODER_ACCESS_URL` is where it's accessed. We use `:7080` to bind
to all interfaces.

```bash
coder server --address $CODER_ADDRESS --access-url $CODER_ACCESS_URL
$ export CODER_ADDRESS=:7080
$ export CODER_ACCESS_URL=http://localhost:7080
$ coder server --address $CODER_ADDRESS --access-url $CODER_ACCESS_URL
```

1. Run `coder login http://localhost:7080` in a new terminal and follow the
interactive instructions to create your user.

1. Pull the example template:
1. Pull the "Docker" example template using the interactive `coder templates init`:

```bash
echo "docker" | coder templates init
cd docker
# You should see a `main.tf` file in this directory
```

1. Open up `main.tf` in your preferred editor to edit the images

You can skip this step if you're fine with our default, generic OS images.

Search for the following section in `main.tf`:

```hcl
...
variable "docker_image" {
description = "Which Docker image would you like to use for your workspace?"
# The codercom/enterprise-* images are only built for amd64
default = "codercom/enterprise-base:ubuntu"
validation {
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!"
}
}
...
$ coder templates init
$ cd docker
```

And edit the strings in `condition = contains([...])` and `default = ...`
with your preferred images.

1. Push up the template to Coder with `coder templates create`
1. Push up the template with `coder templates create`
1. Open the dashboard in your browser (http://localhost:7080) to create your
first workspace:

Expand All @@ -72,16 +47,20 @@ Coder with Docker has the following advantages:

<img src="../images/quickstart/docker/create-workspace.png">

Now wait a few moments for the workspace to build... After the first build
Now wait a few moments for the workspace to build... After the first build,
the image is cached and subsequent builds will take a few seconds.

1. All done!
1. Your workspace is ready to go!

<img src="../images/quickstart/docker/ides.png">

Open up a web application or [SSH in](../ides.md#ssh-configuration).

1. If you want to modify the Docker image or template, edit the files in the
previously created `./docker` directory, then run `coder templates push`.

## Next Steps

- [Port-forward](../networking/port-forwarding.md.md)
- [Learn more about template configuration](../templates.md)
- [Configure more IDEs](../ides/web-ides.md)
58 changes: 2 additions & 56 deletions examples/templates/docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,70 +9,16 @@ tags: [local, docker]
To get started, run `coder templates init`. When prompted, select this template.
Follow the on-screen instructions to proceed.

## Adding/removing images
## Editing the image

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

```sh
# Open the template
vim main.tf
```

Modify your file to match the following:

```diff
variable "docker_image" {
description = "What Docker image would 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)
+ "codercom/enterprise-intellij:ubuntu", "codercom/enterprise-golang:ubuntu"], var.docker_image)
error_message = "Invalid Docker image!"
}
}
```

Update the template:

```sh
coder template push docker
```

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.
Edit the `Dockerfile` and run `coder templates push` to update workspaces.

## code-server

`code-server` is installed via the `startup_script` argument in the `coder_agent`
resource block. The `coder_app` resource is defined to access `code-server` through
the dashboard UI over `localhost:13337`.

## Updating images

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?"
default = "codercom/enterprise-base:ubuntu"
validation {
- condition = contains(["my-org/base-development:v1.1", "myorg-java-development:v1.1"], var.docker_image)
+ condition = contains(["my-org/base-development:v1.1", "myorg-java-development:v1.2"], var.docker_image)

error_message = "Invalid Docker image!"
}
}
```

Optional: Update workspaces to the latest template version:

```sh
coder ls
coder update [workspace name]
```

## Extending this template

See the [kreuzwerker/docker](https://registry.terraform.io/providers/kreuzwerker/docker) Terraform provider documentation to
Expand Down
3 changes: 3 additions & 0 deletions examples/templates/docker/build/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM ubuntu

RUN apt-get update && apt-get install -y curl wget git vim golang
43 changes: 19 additions & 24 deletions examples/templates/docker/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ terraform {
}
docker = {
source = "kreuzwerker/docker"
version = "~> 2.20.2"
version = "~> 2.22"
}
}
}
Expand Down Expand Up @@ -55,32 +55,37 @@ resource "coder_app" "code-server" {
}


variable "docker_image" {
description = "Which Docker image would you like to use for your workspace?"
# The codercom/enterprise-* images are only built for amd64
default = "codercom/enterprise-base:ubuntu"
validation {
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!"
}
}

resource "docker_volume" "home_volume" {
name = "coder-${data.coder_workspace.me.owner}-${lower(data.coder_workspace.me.name)}-home"
}


resource "docker_image" "main" {
name = "coder-${data.coder_workspace.me.id}"
build {
path = "./build"
}
triggers = {
dir_sha1 = sha1(join("", [for f in fileset(path.module, "build/*") : filesha1(f)]))
}
}

resource "docker_container" "workspace" {
count = data.coder_workspace.me.start_count
image = var.docker_image
image = docker_image.main.name
# Uses lower() to avoid Docker restriction on container names.
name = "coder-${data.coder_workspace.me.owner}-${lower(data.coder_workspace.me.name)}"
# Hostname makes the shell more user friendly: coder@my-workspace:~$
hostname = lower(data.coder_workspace.me.name)
dns = ["1.1.1.1"]
# Use the docker gateway if the access URL is 127.0.0.1
command = [
"sh", "-c", replace(coder_agent.main.init_script, "localhost", "host.docker.internal")]
"sh", "-c",
<<EOT
trap '[ $? -ne 0 ] && echo === Agent script exited with non-zero code. Sleeping infinitely to preserve logs... && sleep infinity' EXIT
${replace(coder_agent.main.init_script, "localhost", "host.docker.internal")}
EOT
]
env = ["CODER_AGENT_TOKEN=${coder_agent.main.token}"]
host {
host = "host.docker.internal"
Expand All @@ -92,13 +97,3 @@ resource "docker_container" "workspace" {
read_only = false
}
}

resource "coder_metadata" "container_info" {
count = data.coder_workspace.me.start_count
resource_id = docker_container.workspace[0].id

item {
key = "image"
value = var.docker_image
}
}