-
Notifications
You must be signed in to change notification settings - Fork 58
feat(dotfiles): add ability to apply dotfiles as any user #133
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
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.
Hmm. Can you run bun fmt
and bun lint
to fix the formatting issues?
Yes, sorry, I'm not used to formatting every commit yet. |
This comment was marked as resolved.
This comment was marked as resolved.
d720a16
to
72fcae9
Compare
This comment was marked as outdated.
This comment was marked as outdated.
a059f11
to
ede72ca
Compare
This comment was marked as outdated.
This comment was marked as outdated.
ede72ca
to
7d31865
Compare
I didn't mean to close, i'm starting off of a clean slate, which is probably what triggered it to close. |
5349aea
to
b8db92e
Compare
hey @mafredri, while writing this PR, I realized that the script running the dotfiles is named "personalize", do you want me to rename it to "dotfiles" in this PR even though it's not really it's scope, or should I open another PR ? to fix it resource "coder_script" "personalize" {
agent_id = var.agent_id
script = templatefile("${path.module}/run.sh", {
DOTFILES_URI : local.dotfiles_uri,
})
display_name = "Dotfiles"
icon = "/icon/dotfiles.svg"
run_on_start = true
} |
@phorcys420 feel free to do it here, no need for another PR IMO. Thanks for spotting. |
e4770c0
to
037b089
Compare
31d8b0e
to
e653503
Compare
sorry for all the noise, but given that terraform modules can only be loaded via an URL, I have to push debug commits and then force-push to clean my branch. here is an example of what you can do with this PR : module "dotfiles" {
source = "git::https://github.com/phorcys420/coder-modules.git//dotfiles?ref=dotfiles-root"
agent_id = coder_agent.dev.id
#dotfiles_uri = "<defined by template admin>"
}
module "dotfiles-root" {
source = "git::https://github.com/phorcys420/coder-modules.git//dotfiles?ref=dotfiles-root"
agent_id = coder_agent.dev.id
user = "root"
dotfiles_uri = module.dotfiles.dotfiles_uri # "<defined by template admin>" if uncommented, or the value the end user provided in template settings
} I have tested all the following scenarios and they are working :
|
@mafredri I would like your input on these things.
variable "dotfiles_uri" {
type = string
description = "The URL to a dotfiles repository. (optional)"
default = null
}
variable "user" {
type = string
description = "The name of the user to apply the dotfiles to. (optional, applies to the current user by default)"
default = null
}
locals {
dotfiles_uri = var.dotfiles_uri != null ? var.dotfiles_uri : data.coder_parameter.dotfiles_uri[0].value
user = var.user != null ? var.user : ""
} Currently,
if [ -n "$${DOTFILES_URI// }" ]; then
if [ -z "$DOTFILES_USER" ]; then
DOTFILES_USER="$USER"
fi
fi In this section, I use if [ -n "$${DOTFILES_URI// }" ]; then
if [ "$${DOTFILES_USER// }" ]; then
DOTFILES_USER="$USER"
fi
fi |
hey! |
@phorcys420 can you rebase it? |
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, I approve it, but wait for you to merge in case you want a final review.
hey @matifali, just resolved the merge conflict, there was an error in the docs where the variable name was Also, does it make sense that there is a output "dotfiles_default_uri" {
description = "Dotfiles Default URI"
value = var.default_dotfiles_uri
} |
Another thing, could you review the README.md to see if it makes sense to you? |
@phorcys420 having an output doesn't do any harm but could be helpful for some users, so I did not remove it. I agree that to doesn't add much value as its not anything computed but a direct output from an input. Let's remove that. |
@matifali do you want me to remove it in this PR? |
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.
done
@phorcys420 We can do it in a separate PR and keep the changes related in this PR. The new PR can fix the typo and remove output. I will do that |
This comment was marked as outdated.
This comment was marked as outdated.
#225 does that but we need to wait for someone to approve that :D |
oh okay, but I already fixed the typo in this branch @matifali, do you want me to unfix it to keep the changes related to the PR? 😄 |
@phorcys420 Yes, its better to do ina separate PR. |
I have tested the module again after all the changes and I can confirm that it still works as expected. |
@phorcys420 Could you rebase it again. :D |
will do! |
variable "default_dotfiles_uri" { | ||
type = string | ||
description = "The default dotfiles URI if the workspace user does not provide one." | ||
description = "The default dotfiles URI if the workspace user does not provide one" | ||
default = "" | ||
} | ||
|
||
variable "dotfiles_uri" { | ||
type = string | ||
description = "The URL to a dotfiles repository. (optional, when set, the user isn't prompted for their dotfiles)" | ||
|
||
default = null | ||
} |
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 we should only have one of these
In my template (basic-env), dotfiles are also applied to root.
I like doing this because whenever switching to a root shell for more than one command (e.g installing packages, etc), my shell is consistent with my user.
I have added an optional
user
parameter that applies the dotfiles as a specific user.I have added an optional
dotfiles_uri
parameter that, if passed, hides thecoder_parameter
that asks the end user for their dotfiles URI, this way you can "daisy chain" modules together.Running dotfiles as root only
"Daisy chaining" to run as the default user (usually "coder") and as root without prompting the user twice.