-
Notifications
You must be signed in to change notification settings - Fork 886
refactor: conditionally use dotfiles in dogfood template #5332
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
Conversation
This ensures the `coder dotfiles` command only runs if the dotfiles var in the template is not empty.
dogfood/main.tf
Outdated
@@ -34,6 +45,7 @@ resource "coder_agent" "dev" { | |||
code-server --auth none --port 13337 & | |||
sudo service docker start | |||
coder dotfiles -y 2>&1 | tee ~/.personalize.log | |||
"if [ -n ${var.dotfiles_uri} ]; then coder dotfiles var.dotfiles_uri -y 2>&1 | tee ~/.personalize.log; fi" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unsure if this is the exact way to do this interpolation within the Bash script. Smoke-tested locally using terraform validate
. cc @bpmct
Ref: Conditionals
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you need to quote the variable in order for -n
to work; I'm not sure if terraform will quote it for you.
At least, shellcheck seems to think so.
Also, I believe double brackets are generally preferred for conditionals over single brackets (ref: https://www.baeldung.com/linux/bash-single-vs-double-brackets) Edit: disregard, @mafredri points out that [[
is a bash-ism
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mafredri Shouldn't we have set pipefail
in this script?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mtojek Since we're supporting /bin/sh
, we should avoid -o pipefail
(it's a bash-ism).
dogfood/main.tf
Outdated
@@ -34,6 +45,7 @@ resource "coder_agent" "dev" { | |||
code-server --auth none --port 13337 & | |||
sudo service docker start | |||
coder dotfiles -y 2>&1 | tee ~/.personalize.log | |||
"if [ -n ${var.dotfiles_uri} ]; then coder dotfiles var.dotfiles_uri -y 2>&1 | tee ~/.personalize.log; fi" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay found this and these are called Heredoc strings
Now I'm second guessing it. Is this what it should be?
"if [ -n ${var.dotfiles_uri} ]; then coder dotfiles var.dotfiles_uri -y 2>&1 | tee ~/.personalize.log; fi" | |
if [ -n "${var.dotfiles_uri}" ]; then coder dotfiles "${var.dotfiles_uri}" -y 2>&1 | tee ~/.personalize.log; fi |
Not sure if the quotes will stay so could be ""${var.dotfilesa-uri}""
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jsjoeio I think a great way to deal with variables is to assign them to a shell variable in the scripts, like this:
DOTFILES_URI=${var.dotfiles_uri}
if [ -n "$DOTFILES_URI" ]; then
# ...
fi
This way escaping the value becomes a non-issue because the assignment supports basically any input.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Genius! I'll see if I can wrap this up at the end of the day!
Description
When I merged 9e4d213, I had forgotten to ask the user for the dotfiles URI and then use it with
coder dotfiles
resulting in this log output:Assuming my syntax is correct, this should fix that issue.
Changes