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 <kyle@air.local>
This commit is contained in:
Kyle Carberry 2022-08-10 09:45:05 -05:00 committed by GitHub
parent 758eb21b36
commit fd73d6dd0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 22 additions and 128 deletions

View File

@ -1153,7 +1153,7 @@ func startBuiltinPostgres(ctx context.Context, cfg config.Root, logger slog.Logg
stdlibLogger := slog.Stdlib(ctx, logger.Named("postgres"), slog.LevelDebug)
ep := embeddedpostgres.NewDatabase(
embeddedpostgres.DefaultConfig().
Version(embeddedpostgres.V13).
Version(embeddedpostgres.V14).
BinariesPath(filepath.Join(cfg.PostgresPath(), "bin")).
DataPath(filepath.Join(cfg.PostgresPath(), "data")).
RuntimePath(filepath.Join(cfg.PostgresPath(), "runtime")).

View File

@ -2,41 +2,26 @@ terraform {
required_providers {
coder = {
source = "coder/coder"
version = "0.4.3"
version = "0.4.5"
}
docker = {
source = "kreuzwerker/docker"
version = "~> 2.16.0"
version = "~> 2.20.2"
}
}
}
variable "docker_host" {
description = "Specify location of Docker socket (check `docker context ls` if you're not sure)"
sensitive = true
}
variable "docker_arch" {
description = "Specify architecture of docker host (amd64, arm64, or armv7)"
validation {
condition = contains(["amd64", "arm64", "armv7"], var.docker_arch)
error_message = "Value must be amd64, arm64, or armv7."
}
sensitive = true
}
provider "coder" {
data "coder_provisioner" "me" {
}
provider "docker" {
host = var.docker_host
}
data "coder_workspace" "me" {
}
resource "coder_agent" "main" {
arch = var.docker_arch
arch = data.coder_provisioner.me.arch
os = "linux"
startup_script = "code-server --auth none"

View File

@ -3,65 +3,26 @@ terraform {
required_providers {
coder = {
source = "coder/coder"
version = "0.4.3"
version = "0.4.5"
}
docker = {
source = "kreuzwerker/docker"
version = "~> 2.16.0"
version = "~> 2.20.2"
}
}
}
# Admin parameters
variable "step1_docker_host_warning" {
description = <<-EOF
Is Docker running on the Coder host?
This template will use the Docker socket present on
the Coder host, which is not necessarily your local machine.
You can specify a different host in the template file and
suppress this warning.
EOF
validation {
condition = contains(["Continue using /var/run/docker.sock on the Coder host"], var.step1_docker_host_warning)
error_message = "Cancelling template create."
}
sensitive = true
}
variable "step2_arch" {
description = "arch: What architecture is your Docker host on?"
validation {
condition = contains(["amd64", "arm64", "armv7"], var.step2_arch)
error_message = "Value must be amd64, arm64, or armv7."
}
sensitive = true
}
variable "step3_OS" {
description = <<-EOF
What operating system is your Coder host on?
EOF
validation {
condition = contains(["MacOS", "Windows", "Linux"], var.step3_OS)
error_message = "Value must be MacOS, Windows, or Linux."
}
sensitive = true
data "coder_provisioner" "me" {
}
provider "docker" {
host = var.step3_OS == "Windows" ? "npipe:////.//pipe//docker_engine" : "unix:///var/run/docker.sock"
}
provider "coder" {
}
data "coder_workspace" "me" {
}
resource "coder_agent" "main" {
arch = var.step2_arch
arch = data.coder_provisioner.me.arch
os = "linux"
}

View File

@ -9,20 +9,19 @@ terraform {
required_providers {
coder = {
source = "coder/coder"
version = "0.4.3"
version = "0.4.5"
}
docker = {
source = "kreuzwerker/docker"
version = "~> 2.16.0"
version = "~> 2.20.2"
}
}
}
provider "docker" {
host = "unix:///var/run/docker.sock"
data "coder_provisioner" "me" {
}
provider "coder" {
provider "docker" {
}
data "coder_workspace" "me" {
@ -38,13 +37,13 @@ variable "dotfiles_uri" {
}
resource "coder_agent" "main" {
arch = "amd64"
arch = data.coder_provisioner.me.arch
os = "linux"
startup_script = var.dotfiles_uri != "" ? "coder dotfiles -y ${var.dotfiles_uri}" : null
}
resource "docker_volume" "home_volume" {
name = "coder-${data.coder_workspace.me.owner}-${data.coder_workspace.me.name}-root"
name = "coder-${data.coder_workspace.me.owner}-${lower(data.coder_workspace.me.name)}-root"
}
resource "docker_container" "workspace" {

View File

@ -2,71 +2,26 @@ terraform {
required_providers {
coder = {
source = "coder/coder"
version = "0.4.3"
version = "0.4.5"
}
docker = {
source = "kreuzwerker/docker"
version = "~> 2.16.0"
version = "~> 2.20.2"
}
}
}
# Admin parameters
# Comment this out if you are specifying a different docker
# host on the "docker" provider below.
variable "step1_docker_host_warning" {
description = <<-EOF
This template will use the Docker socket present on
the Coder host, which is not necessarily your local machine.
You can specify a different host in the template file and
suppress this warning.
EOF
validation {
condition = contains(["Continue using /var/run/docker.sock on the Coder host"], var.step1_docker_host_warning)
error_message = "Cancelling template create."
}
sensitive = true
}
variable "step2_arch" {
description = <<-EOF
arch: What architecture is your Docker host on?
note: codercom/enterprise-* images are only built for amd64
EOF
validation {
condition = contains(["amd64", "arm64", "armv7"], var.step2_arch)
error_message = "Value must be amd64, arm64, or armv7."
}
sensitive = true
}
variable "step3_OS" {
description = <<-EOF
What operating system is your Coder host on?
EOF
validation {
condition = contains(["MacOS", "Windows", "Linux"], var.step3_OS)
error_message = "Value must be MacOS, Windows, or Linux."
}
sensitive = true
data "coder_provisioner" "me" {
}
provider "docker" {
host = var.step3_OS == "Windows" ? "npipe:////.//pipe//docker_engine" : "unix:///var/run/docker.sock"
}
provider "coder" {
}
data "coder_workspace" "me" {
}
resource "coder_agent" "main" {
arch = var.step2_arch
arch = data.coder_provisioner.me.arch
os = "linux"
startup_script = <<EOF
#!/bin/sh
@ -104,11 +59,10 @@ variable "docker_image" {
"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}-${data.coder_workspace.me.name}-home"
name = "coder-${data.coder_workspace.me.owner}-${lower(data.coder_workspace.me.name)}-home"
}
resource "docker_container" "workspace" {
@ -121,12 +75,7 @@ resource "docker_container" "workspace" {
dns = ["1.1.1.1"]
# Use the docker gateway if the access URL is 127.0.0.1
command = [
"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
]
"sh", "-c", replace(coder_agent.main.init_script, "localhost", "host.docker.internal")]
env = ["CODER_AGENT_TOKEN=${coder_agent.main.token}"]
host {
host = "host.docker.internal"

View File

@ -19,13 +19,13 @@
bat
drpc.defaultPackage.${system}
exa
getopt
git
go-migrate
go_1_19
golangci-lint
gopls
gotestsum
helm
jq
nfpm
nodePackages.typescript