From 11ae4768180cf1e23cc6f8c1dbe4fc759c6a7d29 Mon Sep 17 00:00:00 2001 From: Oliver Ni Date: Wed, 25 Jan 2023 21:45:55 -0800 Subject: [PATCH] Add get hash step --- transpire/types.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/transpire/types.py b/transpire/types.py index 3f03722..2f9b864 100644 --- a/transpire/types.py +++ b/transpire/types.py @@ -7,7 +7,7 @@ from types import ModuleType from typing import Any, Callable, Iterable, List, Protocol, TypeVar -from hera import Env, SecretVolume, Task, Volume, Workflow +from hera import Env, Parameter, SecretVolume, Task, ValueFrom, Volume, Workflow from kubernetes import client from pydantic import BaseModel, Field @@ -174,6 +174,14 @@ def workflow(self) -> Workflow: working_dir="/build/build", ) + get_hash = Task( + "hash", + image="alpine/git:2.36.3", + args=["rev-parse", "HEAD"], + volumes=[volume], + working_dir="/build/build", + ) + build = [ Task( "build", @@ -195,8 +203,12 @@ def workflow(self) -> Workflow: "--local", f"dockerfile={image.resolved_path}", "--output", - # TODO: Get the git hash - f"type=image,name=harbor.ocf.berkeley.edu/ocf/{self.name}/{image.name}:latest,push=true", + ( + "type=image," + f"name=harbor.ocf.berkeley.edu/ocf/{self.name}/{image.name}:latest," + f"name=harbor.ocf.berkeley.edu/ocf/{self.name}/{image.name}:{{{{tasks.hash.outputs.result}}}}," + "push=true" + ), ], volumes=[ volume, @@ -219,6 +231,6 @@ def workflow(self) -> Workflow: # invokes `Task.__rshift__`, which returns the RHS (`clone`), which is a # `Task`. If `clone` ever becomes a list, this breaks (since there is no # way for Hera to override `list >> list`). - self.pipeline() >> clone >> build # type: ignore + self.pipeline() >> clone >> get_hash >> build # type: ignore return w