Skip to content

feat: set $HOME for coder agent in gcp-linux template #2147

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 1 commit into from
Jun 8, 2022
Merged
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: 17 additions & 1 deletion examples/templates/gcp-linux/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,21 @@ resource "google_compute_instance" "dev" {
email = data.google_compute_default_service_account.default.email
scopes = ["cloud-platform"]
}
metadata_startup_script = coder_agent.dev.init_script
# The startup script runs as root with no $HOME environment set up, which can break workspace applications, so
# instead of directly running the agent init script, setup the home directory, write the init script, and then execute
# it.
metadata_startup_script = <<EOMETA
#!/usr/bin/env sh
set -eux pipefail

mkdir /root || true
cat <<'EOCODER' > /root/coder_agent.sh
${coder_agent.dev.init_script}
EOCODER
chmod +x /root/coder_agent.sh

export HOME=/root
/root/coder_agent.sh

EOMETA
Comment on lines +76 to +89
Copy link
Member

Choose a reason for hiding this comment

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

I believe you could just export HOME=/root && ${coder_agent.dev.init_script}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about that, but I want to move this template in the direction of writing scripts to disk in anticipation of further refinement where we also write a systemd unit.

}