C
Coder.com3mo ago
Zoker

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
20 Replies
Codercord
Codercord3mo ago
<#1336684655717650493>
Category
Help needed
Product
Coder (v2)
Platform
Linux
Logs
Please post any relevant logs/error messages.
Atif
Atif3mo ago
It should work as per the provider docs. Any chnage in triggers should trigger an image build.
Zoker
ZokerOP3mo ago
Thanks @Atif! So this should work?
triggers = {
sha1(data.coder_parameter.force_rebuild.value)
}
triggers = {
sha1(data.coder_parameter.force_rebuild.value)
}
Atif
Atif3mo ago
Yes it shoudl work even without sha1
Phorcys
Phorcys3mo ago
hey @Zoker, did you get it to work?
Zoker
ZokerOP3mo 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
ZokerOP3mo ago
In my Dockerfile I have this part:
No description
Zoker
ZokerOP3mo ago
For me that means, that even after I selected this option here, the docker image was not rebuild:
No description
Zoker
ZokerOP3mo ago
Otherwhise there would not have been any apt packages to update
Phorcys
Phorcys3mo ago
did you do it with or without sha1? this message, sorry
Zoker
ZokerOP3mo 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
Phorcys3mo 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
ZokerOP3mo ago
But the code should work like it is currently, right?
Phorcys
Phorcys3mo ago
sorry for the delay, yes it should, I think there's a bug in the provider
Zoker
ZokerOP3mo ago
Should I open a GitHub issue or something for it?
Phorcys
Phorcys2mo ago
you can but the provider's repo is pretty dead sadly, I would recommend trying to find a workaround instead I'll try to have a stab at it next week hey @Zoker, sorry, haven't got the time to try yet, have you figured it out?
Zoker
ZokerOP2mo ago
After a lot more debugging I think the issue is, that I did not enable the no_cache option for the docker build. So the flag did trigger a rebuild, but since the dockerfile itself did not change, the cache would kick in and the same image would be used again 😅
Phorcys
Phorcys2mo ago
oh okay that is a bit annoying though but i'm not sure there's much you can do
Zoker
ZokerOP2mo ago
But as long as it works I'm happy 😄 Thanks for the support!
Codercord
Codercord2mo ago
@Phorcys closed the thread.

Did you find this page helpful?