Skip to content

Commit

Permalink
fix: ssh-agent, etc. (#268)
Browse files Browse the repository at this point in the history
* ssh-agent, etc.

* code automatically formatted

Signed-off-by: sentential[bot] <bot@sentential>

* flaggy flag

* code automatically formatted

Signed-off-by: sentential[bot] <bot@sentential>

* publish flagging

* bye bye!

---------

Signed-off-by: sentential[bot] <bot@sentential>
Co-authored-by: sentential[bot] <bot@sentential>
  • Loading branch information
raylas and sentential[bot] committed Jul 25, 2023
1 parent 005a6cd commit a91aa62
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 28 deletions.
12 changes: 8 additions & 4 deletions sentential/cli/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ def init(repository_name: str, runtime: Runtimes):


@root.command()
def build(arch: Architecture = typer.Option(Architecture.system().value)):
def build(
arch: Architecture = typer.Option(Architecture.system().value),
ssh_agent: bool = typer.Option(False),
):
"""build lambda image"""
ontology = Ontology()
LocalLambdaDriver(ontology).destroy()
LocalImagesDriver(ontology).build(arch)
LocalImagesDriver(ontology).build(arch, ssh_agent)


@root.command()
Expand All @@ -35,16 +38,17 @@ def publish(
minor: bool = typer.Option(False),
arch: List[Architecture] = typer.Option([Architecture.system().value]),
multiarch: bool = typer.Option(False),
ssh_agent: bool = typer.Option(False),
):
"""publish lambda image"""
ontology = Ontology()
tag = AwsEcrDriver(ontology).next(major, minor)
docker = LocalImagesDriver(ontology)

if multiarch:
docker.publish(tag, [a for a in Architecture])
docker.publish(tag, [a for a in Architecture], ssh_agent)
else:
docker.publish(tag, [a for a in arch])
docker.publish(tag, [a for a in arch], ssh_agent)


@root.command()
Expand Down
19 changes: 9 additions & 10 deletions sentential/lib/drivers/local_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ def __init__(self, ontology: Ontology) -> None:
self.repo_name = ontology.context.repository_name
self.repo_url = ontology.context.repository_url

def build(self, arch: Architecture) -> Image:
def build(self, arch: Architecture, ssh_agent: bool) -> Image:
platform = f"linux/{arch.value}"
manifest_uri = f"{self.repo_name}:{SNTL_WORKING_IMAGE_TAG}"
self._build(manifest_uri, platform)
self._build(manifest_uri, platform, ssh_agent)
return self.get_image()

def publish(self, tag: str, arch: List[Architecture]) -> List[Image]:
def publish(
self, tag: str, arch: List[Architecture], ssh_agent: bool
) -> List[Image]:
platforms = [f"linux/{a.value}" for a in arch]
manifest_list_uri = f"{self.repo_url}:{tag}"
image_manifest_uris = []
Expand All @@ -32,15 +34,10 @@ def publish(self, tag: str, arch: List[Architecture]) -> List[Image]:

for platform in platforms:
image_manifest_uri = f"{manifest_list_uri}-{platform.split('/')[1]}"
image = self._build(image_manifest_uri, platform)
image = self._build(image_manifest_uri, platform, ssh_agent)
image_manifest_uris.append(image_manifest_uri)
built.append(image)

if cwi.id not in [build.id for build in built]:
raise LocalDriverError(
"current working image id does not match that of any local build"
)

for image_manifest_uri in image_manifest_uris:
clients.docker.push(image_manifest_uri)

Expand All @@ -49,14 +46,16 @@ def publish(self, tag: str, arch: List[Architecture]) -> List[Image]:
clients.docker.manifest.push(manifest_list_uri, False)
return built

def _build(self, tag: str, platform: str) -> Image:
def _build(self, tag: str, platform: str, ssh_agent: bool) -> Image:
self.ontology.args.export_defaults()
cmd = {
"tags": [tag],
"platforms": [platform],
"load": True,
"build_args": self.ontology.args.parameters.dict(),
}
if ssh_agent:
cmd["ssh"] = "default"

image = clients.docker.build(self.ontology.context.path.root, **cmd)

Expand Down
2 changes: 1 addition & 1 deletion sentential/sntl.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
ValidationError,
)

root.add_typer(store, name="args", help="build arguments", callback=Assurances.build)
root.add_typer(store, name="args", help="build arguments")
root.add_typer(store, name="envs", help="environment variables")
root.add_typer(store, name="secrets", help="secrets")
root.add_typer(store, name="configs", help="provisioning")
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
def cwi():
local_images_driver = LocalImagesDriver(Ontology())
local_images_driver.clean()
yield local_images_driver.build(Architecture.system())
yield local_images_driver.build(Architecture.system(), False)


#
Expand Down
17 changes: 7 additions & 10 deletions tests/lib/drivers/test_local_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,26 @@ def test_get_image(self, cwi: Image, local_images_driver: LocalImagesDriver):
def test_publish(
self, cwi: Image, local_images_driver: LocalImagesDriver, native_arch
):
assert cwi in local_images_driver.publish("1.0.0", [native_arch])
assert cwi in local_images_driver.publish("1.0.0", [native_arch], False)

def test_publish_multi_arch(
self, cwi: Image, local_images_driver: LocalImagesDriver
):
built = local_images_driver.publish("2.0.0", [a for a in Architecture])
built = local_images_driver.publish("2.0.0", [a for a in Architecture], False)
archs = [image.architecture for image in built]
assert len(archs) == 2
assert "amd64" in archs
assert "arm64" in archs
assert cwi in built

def test_cross_build(self, local_images_driver: LocalImagesDriver, cross_arch):
assert local_images_driver.build(cross_arch).architecture == cross_arch.value

def test_cross_publish_failure(
self, local_images_driver: LocalImagesDriver, native_arch
):
with pytest.raises(LocalDriverError):
local_images_driver.publish("1.0.1", [native_arch])
assert (
local_images_driver.build(cross_arch, False).architecture
== cross_arch.value
)

def test_cross_publish(self, local_images_driver: LocalImagesDriver, cross_arch):
built = local_images_driver.publish("1.0.1", [cross_arch])
built = local_images_driver.publish("1.0.1", [cross_arch], False)
archs = [image.architecture for image in built]
assert len(archs) == 1
assert cross_arch.value in archs
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/drivers/test_local_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_build(
local_images_driver: LocalImagesDriver,
):
local_images_driver.ontology.args.set("buildarg", "present")
local_images_driver.build(Architecture.system())
local_images_driver.build(Architecture.system(), False)

def test_deploy(
self,
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/mounts/test_local_lambda_public_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def http_handler_returns_environ(init):
class TestAwsLambdaPublicUrlMount:
def test_build(self, local_images_driver: LocalImagesDriver):
local_images_driver.ontology.args.set("buildarg", "present")
local_images_driver.build(Architecture.system())
local_images_driver.build(Architecture.system(), False)

def test_deploy(self, cwi: Image, local_lambda_driver: LocalLambdaDriver):
local_lambda_driver.ontology.envs.set("ENVVAR", "present")
Expand Down

0 comments on commit a91aa62

Please sign in to comment.