Skip to content

chore(examples): Add login_before_ready and startup_script_timeout #5880

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 13 commits into from
Jan 27, 2023
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
18 changes: 10 additions & 8 deletions dogfood/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
coder = {
source = "coder/coder"
version = "0.6.0"
version = "0.6.10"
}
docker = {
source = "kreuzwerker/docker"
Expand Down Expand Up @@ -58,11 +58,13 @@ provider "coder" {}
data "coder_workspace" "me" {}

resource "coder_agent" "dev" {
arch = "amd64"
os = "linux"
startup_script = <<EOF
#!/bin/sh
set -x
arch = "amd64"
os = "linux"

login_before_ready = false
startup_script_timeout = 60
startup_script = <<-EOT
set -ex
# install and start code-server
curl -fsSL https://code-server.dev/install.sh | sh -s -- --version 4.8.3
code-server --auth none --port 13337 &
Expand All @@ -73,11 +75,11 @@ resource "coder_agent" "dev" {
coder dotfiles "$DOTFILES_URI" -y 2>&1 | tee -a ~/.personalize.log
fi
if [ -x ~/personalize ]; then
~/personalize | tee -a ~/.personalize.log
~/personalize 2>&1 | tee -a ~/.personalize.log
elif [ -f ~/personalize ]; then
echo "~/personalize is not executable, skipping..." | tee -a ~/.personalize.log
fi
EOF
EOT
}

resource "coder_app" "code-server" {
Expand Down
22 changes: 13 additions & 9 deletions examples/templates/aws-ecs-container/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ terraform {
}
coder = {
source = "coder/coder"
version = "0.6.6"
version = "0.6.10"
}
}
}
Expand Down Expand Up @@ -92,15 +92,19 @@ resource "aws_ecs_service" "workspace" {
data "coder_workspace" "me" {}

resource "coder_agent" "coder" {
arch = "amd64"
auth = "token"
os = "linux"
dir = "/home/coder"
startup_script = <<EOT
#!/bin/bash
Copy link
Member Author

Choose a reason for hiding this comment

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

Removed all shebangs because I didn't want users to get the wrong idea that we obey the shebang. In unix, we should run script via /bin/bash if it has this header, but we don't. Likewise for #!/bin/sh we should use /bin/sh, but we don't.

arch = "amd64"
auth = "token"
os = "linux"
dir = "/home/coder"

login_before_ready = false
startup_script_timeout = 180
startup_script = <<-EOT
set -e

# install and start code-server
curl -fsSL https://code-server.dev/install.sh | sh -s -- --version 4.8.3 | tee code-server-install.log
Copy link
Member Author

@mafredri mafredri Jan 26, 2023

Choose a reason for hiding this comment

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

Removed tee here because install log is already available in agent startup script log (and before this refactor, this file was overwritten by the following tee.

code-server --auth none --port 13337 | tee code-server-install.log &
curl -fsSL https://code-server.dev/install.sh | sh -s -- --version 4.8.3
code-server --auth none --port 13337 >/tmp/code-server.log 2>&1 &
Copy link
Member Author

Choose a reason for hiding this comment

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

Redirecting both stdout and stderr for log. Could also use 2>&1 | tee /tmp/code-server.log if preferable.

EOT
}

Expand Down
19 changes: 11 additions & 8 deletions examples/templates/aws-linux/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
coder = {
source = "coder/coder"
version = "0.6.6"
version = "0.6.10"
}
}
}
Expand Down Expand Up @@ -73,15 +73,18 @@ data "aws_ami" "ubuntu" {
}

resource "coder_agent" "main" {
arch = "amd64"
auth = "aws-instance-identity"
os = "linux"
startup_script = <<EOT
#!/bin/bash
arch = "amd64"
auth = "aws-instance-identity"
os = "linux"

login_before_ready = false
startup_script_timeout = 180
startup_script = <<-EOT
set -e

# install and start code-server
curl -fsSL https://code-server.dev/install.sh | sh -s -- --version 4.8.3 | tee code-server-install.log
code-server --auth none --port 13337 | tee code-server-install.log &
curl -fsSL https://code-server.dev/install.sh | sh -s -- --version 4.8.3
code-server --auth none --port 13337 >/tmp/code-server.log 2>&1 &
EOT
}

Expand Down
4 changes: 3 additions & 1 deletion examples/templates/aws-windows/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
coder = {
source = "coder/coder"
version = "0.6.6"
version = "0.6.10"
}
}
}
Expand Down Expand Up @@ -73,6 +73,8 @@ resource "coder_agent" "main" {
arch = "amd64"
auth = "aws-instance-identity"
os = "windows"

login_before_ready = false
}

locals {
Expand Down
4 changes: 3 additions & 1 deletion examples/templates/azure-linux/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
coder = {
source = "coder/coder"
version = "0.6.6"
version = "0.6.10"
}
azurerm = {
source = "hashicorp/azurerm"
Expand Down Expand Up @@ -83,6 +83,8 @@ resource "coder_agent" "main" {
arch = "amd64"
os = "linux"
auth = "azure-instance-identity"

login_before_ready = false
}

locals {
Expand Down
4 changes: 3 additions & 1 deletion examples/templates/do-linux/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
coder = {
source = "coder/coder"
version = "0.6.6"
version = "0.6.10"
}
digitalocean = {
source = "digitalocean/digitalocean"
Expand Down Expand Up @@ -96,6 +96,8 @@ data "coder_workspace" "me" {}
resource "coder_agent" "main" {
os = "linux"
arch = "amd64"

login_before_ready = false
}

resource "digitalocean_volume" "home_volume" {
Expand Down
14 changes: 10 additions & 4 deletions examples/templates/docker-code-server/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
coder = {
source = "coder/coder"
version = "0.6.6"
version = "0.6.10"
}
docker = {
source = "kreuzwerker/docker"
Expand All @@ -21,9 +21,15 @@ data "coder_workspace" "me" {
}

resource "coder_agent" "main" {
arch = data.coder_provisioner.me.arch
os = "linux"
startup_script = "code-server --auth none"
arch = data.coder_provisioner.me.arch
os = "linux"

login_before_ready = false
startup_script_timeout = 180
startup_script = <<-EOT
set -e
code-server --auth none >/tmp/code-server.log 2>&1 &
EOT

# These environment variables allow you to make Git commits right away after creating a
# workspace. Note that they take precedence over configuration defined in ~/.gitconfig!
Expand Down
17 changes: 10 additions & 7 deletions examples/templates/docker-image-builds/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ terraform {
required_providers {
coder = {
source = "coder/coder"
version = "0.6.6"
version = "0.6.10"
}
docker = {
source = "kreuzwerker/docker"
Expand All @@ -22,14 +22,17 @@ data "coder_workspace" "me" {
}

resource "coder_agent" "main" {
arch = data.coder_provisioner.me.arch
os = "linux"
startup_script = <<EOT
#!/bin/bash
arch = data.coder_provisioner.me.arch
os = "linux"

login_before_ready = false
startup_script_timeout = 180
startup_script = <<-EOT
set -e

# install and start code-server
curl -fsSL https://code-server.dev/install.sh | sh -s -- --version 4.8.3 | tee code-server-install.log
code-server --auth none --port 13337 | tee code-server-install.log &
curl -fsSL https://code-server.dev/install.sh | sh -s -- --version 4.8.3
code-server --auth none --port 13337 >/tmp/code-server.log 2>&1 &
EOT
}

Expand Down
18 changes: 14 additions & 4 deletions examples/templates/docker-with-dotfiles/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ terraform {
required_providers {
coder = {
source = "coder/coder"
version = "0.6.6"
version = "0.6.10"
}
docker = {
source = "kreuzwerker/docker"
Expand Down Expand Up @@ -41,9 +41,19 @@ variable "dotfiles_uri" {
}

resource "coder_agent" "main" {
arch = data.coder_provisioner.me.arch
os = "linux"
startup_script = var.dotfiles_uri != "" ? "coder dotfiles -y ${var.dotfiles_uri}" : null
arch = data.coder_provisioner.me.arch
os = "linux"

login_before_ready = false
startup_script_timeout = 180
env = { "DOTFILES_URI" = var.dotfiles_uri != "" ? var.dotfiles_uri : null }
startup_script = <<-EOT
set -e
if [ -n "$DOTFILES_URI" ]; then
echo "Installing dotfiles from $DOTFILES_URI"
coder dotfiles -y "$DOTFILES_URI"
fi
EOT
}

resource "docker_volume" "home_volume" {
Expand Down
2 changes: 1 addition & 1 deletion examples/templates/docker/build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ RUN apt-get update \
&& rm -rf /var/lib/apt/lists/*

ARG USER=coder
RUN useradd --groups sudo --no-create-home ${USER} \
RUN useradd --groups sudo --no-create-home --shell /bin/bash ${USER} \
&& echo "${USER} ALL=(ALL) NOPASSWD:ALL" >/etc/sudoers.d/${USER} \
&& chmod 0440 /etc/sudoers.d/${USER}
USER ${USER}
Expand Down
18 changes: 11 additions & 7 deletions examples/templates/docker/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
coder = {
source = "coder/coder"
version = "0.6.6"
version = "0.6.10"
}
docker = {
source = "kreuzwerker/docker"
Expand All @@ -25,14 +25,18 @@ data "coder_workspace" "me" {
}

resource "coder_agent" "main" {
arch = data.coder_provisioner.me.arch
os = "linux"
startup_script = <<EOF
#!/bin/sh
arch = data.coder_provisioner.me.arch
os = "linux"

login_before_ready = false
startup_script_timeout = 180
startup_script = <<-EOT
set -e

# install and start code-server
curl -fsSL https://code-server.dev/install.sh | sh -s -- --version 4.8.3
code-server --auth none --port 13337
EOF
code-server --auth none --port 13337 >/tmp/code-server.log 2>&1 &
EOT

# These environment variables allow you to make Git commits right away after creating a
# workspace. Note that they take precedence over configuration defined in ~/.gitconfig!
Expand Down
19 changes: 11 additions & 8 deletions examples/templates/gcp-linux/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
coder = {
source = "coder/coder"
version = "0.6.6"
version = "0.6.10"
}
google = {
source = "hashicorp/google"
Expand Down Expand Up @@ -46,15 +46,18 @@ resource "google_compute_disk" "root" {
}

resource "coder_agent" "main" {
auth = "google-instance-identity"
arch = "amd64"
os = "linux"
startup_script = <<EOT
#!/bin/bash
auth = "google-instance-identity"
arch = "amd64"
os = "linux"

login_before_ready = false
startup_script_timeout = 180
startup_script = <<-EOT
set -e

# install and start code-server
curl -fsSL https://code-server.dev/install.sh | sh -s -- --version 4.8.3 | tee code-server-install.log
code-server --auth none --port 13337 | tee code-server-install.log &
curl -fsSL https://code-server.dev/install.sh | sh -s -- --version 4.8.3
code-server --auth none --port 13337 >/tmp/code-server.log 2>&1 &
EOT
}

Expand Down
19 changes: 11 additions & 8 deletions examples/templates/gcp-vm-container/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
coder = {
source = "coder/coder"
version = "0.6.6"
version = "0.6.10"
}
google = {
source = "hashicorp/google"
Expand Down Expand Up @@ -36,15 +36,18 @@ data "coder_workspace" "me" {
}

resource "coder_agent" "main" {
auth = "google-instance-identity"
arch = "amd64"
os = "linux"
startup_script = <<EOT
#!/bin/bash
auth = "google-instance-identity"
arch = "amd64"
os = "linux"

login_before_ready = false
startup_script_timeout = 180
startup_script = <<-EOT
set -e

# install and start code-server
curl -fsSL https://code-server.dev/install.sh | sh -s -- --version 4.8.3 | tee code-server-install.log
code-server --auth none --port 13337 | tee code-server-install.log &
curl -fsSL https://code-server.dev/install.sh | sh -s -- --version 4.8.3
code-server --auth none --port 13337 >/tmp/code-server.log 2>&1 &
EOT
}

Expand Down
4 changes: 3 additions & 1 deletion examples/templates/gcp-windows/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
coder = {
source = "coder/coder"
version = "0.6.6"
version = "0.6.10"
}
google = {
source = "hashicorp/google"
Expand Down Expand Up @@ -49,6 +49,8 @@ resource "coder_agent" "main" {
auth = "google-instance-identity"
arch = "amd64"
os = "windows"

login_before_ready = false
}

resource "google_compute_instance" "dev" {
Expand Down
Loading