https://pulumi.com logo
m

miniature-lion-41490

07/07/2023, 2:46 PM
Any tricks to get deployment time and git hash as an env-var til a container? i know how to set env vars, but if i simply set
datetime.now()
then the pulumi code will obviously/presumably(?) redeploy the service whenever i run pulumi due to the change in values; i don't want that. any ideas?
b

billowy-army-68599

07/07/2023, 3:17 PM
git hash should be fairly straightforward as it’s locally static, is the issue that you want to get a deployment time only when changes happen?
m

miniature-lion-41490

07/07/2023, 3:18 PM
Yes - i want the "version" of the webapp to be shown in a developer-debug-info view as well as when the service was deployed last. the issue being that the webapp doesn't change everytime i redeploy my stack, so it should only be the specific ressource
b

billowy-army-68599

07/07/2023, 3:21 PM
thinking out loud, I think that likely wants to be set inside the container rather than at the deployment, the deployment time information doesn’t really have the metadata ability to set values that way. I’ll keep considering if there’s a way to solve
m

miniature-lion-41490

07/07/2023, 3:21 PM
thanks. it's also a nice to have of sorts.
i mean the githash might be of less value, but the datetime would be nice
my issue with setting it in the container is that if it gets restarted that isn't the same as a redeploy.. hmm
maybe it's more of a build time. 🤔
b

billowy-army-68599

07/07/2023, 3:23 PM
yeah I think that’s gonna be easier
m

miniature-lion-41490

07/19/2023, 11:58 AM
My solution for getting the build time of a docker image, ended up being:
Copy code
def get_build_time(self, image: docker.Image) -> Output[datetime | None]:
        cmd = command.local.Command(
            f"{image._name}-build-time",
            create='TZ=UTC date +"%Y-%m-%d %H:%M:%S"',
            triggers=[image.repo_digest],
            opts=pulumi.ResourceOptions(parent=image),
        )

        def to_datetime(stdout: str) -> datetime | None:
            if not stdout.strip():
                return None

            return datetime.strptime(stdout.strip(), "%Y-%m-%d %H:%M:%S")

        return cmd.stdout.apply(to_datetime)
In theory i could add the git hash in a similar way