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

Skip to content

Commit fd73d6d

Browse files
kylecarbsKyle Carberry
and
Kyle Carberry
authored
fix: Reduce variables needed for Docker template (#3442)
* fix: Reduce variables needed for Docker template This should make initial setup a bit simpler! * Fix for M2 Macbooks PostgreSQL 13 doesn't support the M series architecture. * Fix name <-> id swap * Update Docker provider to remove host requirement Co-authored-by: Kyle Carberry <[email protected]>
1 parent 758eb21 commit fd73d6d

File tree

6 files changed

+22
-128
lines changed

6 files changed

+22
-128
lines changed

cli/server.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1153,7 +1153,7 @@ func startBuiltinPostgres(ctx context.Context, cfg config.Root, logger slog.Logg
11531153
stdlibLogger := slog.Stdlib(ctx, logger.Named("postgres"), slog.LevelDebug)
11541154
ep := embeddedpostgres.NewDatabase(
11551155
embeddedpostgres.DefaultConfig().
1156-
Version(embeddedpostgres.V13).
1156+
Version(embeddedpostgres.V14).
11571157
BinariesPath(filepath.Join(cfg.PostgresPath(), "bin")).
11581158
DataPath(filepath.Join(cfg.PostgresPath(), "data")).
11591159
RuntimePath(filepath.Join(cfg.PostgresPath(), "runtime")).

examples/templates/docker-code-server/main.tf

+4-19
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,26 @@ terraform {
22
required_providers {
33
coder = {
44
source = "coder/coder"
5-
version = "0.4.3"
5+
version = "0.4.5"
66
}
77
docker = {
88
source = "kreuzwerker/docker"
9-
version = "~> 2.16.0"
9+
version = "~> 2.20.2"
1010
}
1111
}
1212
}
1313

14-
variable "docker_host" {
15-
description = "Specify location of Docker socket (check `docker context ls` if you're not sure)"
16-
sensitive = true
17-
}
18-
19-
variable "docker_arch" {
20-
description = "Specify architecture of docker host (amd64, arm64, or armv7)"
21-
validation {
22-
condition = contains(["amd64", "arm64", "armv7"], var.docker_arch)
23-
error_message = "Value must be amd64, arm64, or armv7."
24-
}
25-
sensitive = true
26-
}
27-
28-
provider "coder" {
14+
data "coder_provisioner" "me" {
2915
}
3016

3117
provider "docker" {
32-
host = var.docker_host
3318
}
3419

3520
data "coder_workspace" "me" {
3621
}
3722

3823
resource "coder_agent" "main" {
39-
arch = var.docker_arch
24+
arch = data.coder_provisioner.me.arch
4025
os = "linux"
4126
startup_script = "code-server --auth none"
4227

examples/templates/docker-image-builds/main.tf

+4-43
Original file line numberDiff line numberDiff line change
@@ -3,65 +3,26 @@ terraform {
33
required_providers {
44
coder = {
55
source = "coder/coder"
6-
version = "0.4.3"
6+
version = "0.4.5"
77
}
88
docker = {
99
source = "kreuzwerker/docker"
10-
version = "~> 2.16.0"
10+
version = "~> 2.20.2"
1111
}
1212
}
1313
}
1414

15-
# Admin parameters
16-
variable "step1_docker_host_warning" {
17-
description = <<-EOF
18-
Is Docker running on the Coder host?
19-
20-
This template will use the Docker socket present on
21-
the Coder host, which is not necessarily your local machine.
22-
23-
You can specify a different host in the template file and
24-
suppress this warning.
25-
EOF
26-
validation {
27-
condition = contains(["Continue using /var/run/docker.sock on the Coder host"], var.step1_docker_host_warning)
28-
error_message = "Cancelling template create."
29-
}
30-
31-
sensitive = true
32-
}
33-
variable "step2_arch" {
34-
description = "arch: What architecture is your Docker host on?"
35-
validation {
36-
condition = contains(["amd64", "arm64", "armv7"], var.step2_arch)
37-
error_message = "Value must be amd64, arm64, or armv7."
38-
}
39-
sensitive = true
40-
}
41-
variable "step3_OS" {
42-
description = <<-EOF
43-
What operating system is your Coder host on?
44-
EOF
45-
46-
validation {
47-
condition = contains(["MacOS", "Windows", "Linux"], var.step3_OS)
48-
error_message = "Value must be MacOS, Windows, or Linux."
49-
}
50-
sensitive = true
15+
data "coder_provisioner" "me" {
5116
}
5217

5318
provider "docker" {
54-
host = var.step3_OS == "Windows" ? "npipe:////.//pipe//docker_engine" : "unix:///var/run/docker.sock"
55-
}
56-
57-
provider "coder" {
5819
}
5920

6021
data "coder_workspace" "me" {
6122
}
6223

6324
resource "coder_agent" "main" {
64-
arch = var.step2_arch
25+
arch = data.coder_provisioner.me.arch
6526
os = "linux"
6627
}
6728

examples/templates/docker-with-dotfiles/main.tf

+6-7
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,19 @@ terraform {
99
required_providers {
1010
coder = {
1111
source = "coder/coder"
12-
version = "0.4.3"
12+
version = "0.4.5"
1313
}
1414
docker = {
1515
source = "kreuzwerker/docker"
16-
version = "~> 2.16.0"
16+
version = "~> 2.20.2"
1717
}
1818
}
1919
}
2020

21-
provider "docker" {
22-
host = "unix:///var/run/docker.sock"
21+
data "coder_provisioner" "me" {
2322
}
2423

25-
provider "coder" {
24+
provider "docker" {
2625
}
2726

2827
data "coder_workspace" "me" {
@@ -38,13 +37,13 @@ variable "dotfiles_uri" {
3837
}
3938

4039
resource "coder_agent" "main" {
41-
arch = "amd64"
40+
arch = data.coder_provisioner.me.arch
4241
os = "linux"
4342
startup_script = var.dotfiles_uri != "" ? "coder dotfiles -y ${var.dotfiles_uri}" : null
4443
}
4544

4645
resource "docker_volume" "home_volume" {
47-
name = "coder-${data.coder_workspace.me.owner}-${data.coder_workspace.me.name}-root"
46+
name = "coder-${data.coder_workspace.me.owner}-${lower(data.coder_workspace.me.name)}-root"
4847
}
4948

5049
resource "docker_container" "workspace" {

examples/templates/docker/main.tf

+6-57
Original file line numberDiff line numberDiff line change
@@ -2,71 +2,26 @@ terraform {
22
required_providers {
33
coder = {
44
source = "coder/coder"
5-
version = "0.4.3"
5+
version = "0.4.5"
66
}
77
docker = {
88
source = "kreuzwerker/docker"
9-
version = "~> 2.16.0"
9+
version = "~> 2.20.2"
1010
}
1111
}
1212
}
1313

14-
# Admin parameters
15-
16-
# Comment this out if you are specifying a different docker
17-
# host on the "docker" provider below.
18-
variable "step1_docker_host_warning" {
19-
description = <<-EOF
20-
This template will use the Docker socket present on
21-
the Coder host, which is not necessarily your local machine.
22-
23-
You can specify a different host in the template file and
24-
suppress this warning.
25-
EOF
26-
validation {
27-
condition = contains(["Continue using /var/run/docker.sock on the Coder host"], var.step1_docker_host_warning)
28-
error_message = "Cancelling template create."
29-
}
30-
31-
sensitive = true
32-
}
33-
variable "step2_arch" {
34-
description = <<-EOF
35-
arch: What architecture is your Docker host on?
36-
37-
note: codercom/enterprise-* images are only built for amd64
38-
EOF
39-
40-
validation {
41-
condition = contains(["amd64", "arm64", "armv7"], var.step2_arch)
42-
error_message = "Value must be amd64, arm64, or armv7."
43-
}
44-
sensitive = true
45-
}
46-
variable "step3_OS" {
47-
description = <<-EOF
48-
What operating system is your Coder host on?
49-
EOF
50-
51-
validation {
52-
condition = contains(["MacOS", "Windows", "Linux"], var.step3_OS)
53-
error_message = "Value must be MacOS, Windows, or Linux."
54-
}
55-
sensitive = true
14+
data "coder_provisioner" "me" {
5615
}
5716

5817
provider "docker" {
59-
host = var.step3_OS == "Windows" ? "npipe:////.//pipe//docker_engine" : "unix:///var/run/docker.sock"
60-
}
61-
62-
provider "coder" {
6318
}
6419

6520
data "coder_workspace" "me" {
6621
}
6722

6823
resource "coder_agent" "main" {
69-
arch = var.step2_arch
24+
arch = data.coder_provisioner.me.arch
7025
os = "linux"
7126
startup_script = <<EOF
7227
#!/bin/sh
@@ -104,11 +59,10 @@ variable "docker_image" {
10459
"codercom/enterprise-intellij:ubuntu", "codercom/enterprise-golang:ubuntu"], var.docker_image)
10560
error_message = "Invalid Docker image!"
10661
}
107-
10862
}
10963

11064
resource "docker_volume" "home_volume" {
111-
name = "coder-${data.coder_workspace.me.owner}-${data.coder_workspace.me.name}-home"
65+
name = "coder-${data.coder_workspace.me.owner}-${lower(data.coder_workspace.me.name)}-home"
11266
}
11367

11468
resource "docker_container" "workspace" {
@@ -121,12 +75,7 @@ resource "docker_container" "workspace" {
12175
dns = ["1.1.1.1"]
12276
# Use the docker gateway if the access URL is 127.0.0.1
12377
command = [
124-
"sh", "-c",
125-
<<EOT
126-
trap '[ $? -ne 0 ] && echo === Agent script exited with non-zero code. Sleeping infinitely to preserve logs... && sleep infinity' EXIT
127-
${replace(coder_agent.main.init_script, "localhost", "host.docker.internal")}
128-
EOT
129-
]
78+
"sh", "-c", replace(coder_agent.main.init_script, "localhost", "host.docker.internal")]
13079
env = ["CODER_AGENT_TOKEN=${coder_agent.main.token}"]
13180
host {
13281
host = "host.docker.internal"

flake.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919
bat
2020
drpc.defaultPackage.${system}
2121
exa
22+
getopt
2223
git
2324
go-migrate
2425
go_1_19
2526
golangci-lint
2627
gopls
2728
gotestsum
28-
helm
2929
jq
3030
nfpm
3131
nodePackages.typescript

0 commit comments

Comments
 (0)