How to use coder_parameter to force_rebuild docker images?

Hi there, I saw this in the docs:
data "coder_parameter" "force_rebuild" {
name = "force_rebuild"
type = "bool"
description = "Rebuild the Docker image rather than use the cached one."
mutable = true
default = false
ephemeral = true
}
data "coder_parameter" "force_rebuild" {
name = "force_rebuild"
type = "bool"
description = "Rebuild the Docker image rather than use the cached one."
mutable = true
default = false
ephemeral = true
}
(source: https://coder.com/docs/@v2.19.0/admin/templates/extending-templates/parameters#ephemeral-parameters) How I want to add this feature to my current template. I guess I need to use the force_rebuild somewhere in order to really force the rebuild of the image, right? Probably in the triggers here:
resource "docker_image" "main" {
name = "coder-${data.coder_workspace.me.id}"
build {
context = "."
build_args = {
USER = local.username
}
}
triggers = {
docker_sha1 = sha1(filesha1("./Dockerfile"))
terraform_sha1 = sha1(filesha1("./Base.tf"))
rebuild_sha1 = sha1(data.coder_parameter.force_rebuild.value) <-- something like this?
assets_sha1 = sha1(join("", [for f in fileset(path.module, "./assets/*") : filesha1(f)]))
}
}
resource "docker_image" "main" {
name = "coder-${data.coder_workspace.me.id}"
build {
context = "."
build_args = {
USER = local.username
}
}
triggers = {
docker_sha1 = sha1(filesha1("./Dockerfile"))
terraform_sha1 = sha1(filesha1("./Base.tf"))
rebuild_sha1 = sha1(data.coder_parameter.force_rebuild.value) <-- something like this?
assets_sha1 = sha1(join("", [for f in fileset(path.module, "./assets/*") : filesha1(f)]))
}
}
Would this work? Thanks!
Build Parameters | Coder Docs
Use parameters to customize workspaces at build
From An unknown user
From An unknown user
15 Replies
Codercord
Codercord3w ago
<#1336684655717650493>
Category
Help needed
Product
Coder (v2)
Platform
Linux
Logs
Please post any relevant logs/error messages.
Atif
Atif3w ago
It should work as per the provider docs. Any chnage in triggers should trigger an image build.
Zoker
ZokerOP3w ago
Thanks @Atif! So this should work?
triggers = {
sha1(data.coder_parameter.force_rebuild.value)
}
triggers = {
sha1(data.coder_parameter.force_rebuild.value)
}
Atif
Atif3w ago
Yes it shoudl work even without sha1
Phorcys
Phorcys2w ago
hey @Zoker, did you get it to work?
Zoker
ZokerOP2w ago
Hi @Phorcys, no I don't think so. I added it to my terraform file. Then I updated my coder workspace. During the initializsation of this, I got this promt here (apt update && apt upgrade are run on every workspace start):
No description
Zoker
ZokerOP2w ago
In my Dockerfile I have this part:
No description
Zoker
ZokerOP2w ago
For me that means, that even after I selected this option here, the docker image was not rebuild:
No description
Zoker
ZokerOP2w ago
Otherwhise there would not have been any apt packages to update
Phorcys
Phorcys2w ago
did you do it with or without sha1? this message, sorry
Zoker
ZokerOP7d ago
Without the sha1. Here is the full tf file: https://gist.zkr.dev/FlorianGareis/8170896d2bd14fefb2af886e433f5364#file-base-tf-154 @Phorcys Do you have any idea, why it's not working?
Phorcys
Phorcys7d ago
I can't find anything on the matter, you could try downgrading the provider to v2.5.0 to see if it works https://github.com/kreuzwerker/terraform-provider-docker/issues/571
GitHub
docker_image build image even if file context and dockerfile doesn'...
Community Note Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request Please do not leave "+1" or "me to...
Zoker
ZokerOP7d ago
But the code should work like it is currently, right?
Phorcys
Phorcys2d ago
sorry for the delay, yes it should, I think there's a bug in the provider
Zoker
ZokerOP2d ago
Should I open a GitHub issue or something for it?

Did you find this page helpful?