Any tricks to get deployment time and git hash as ...
# general
m
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
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
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
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
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
yeah I think that’s gonna be easier
m
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