-
Couldn't load subscription status.
- Fork 4
Feat add in build tool control to config #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 10 commits
342fa69
b9a87a2
43a4c77
c43e551
95bbe7e
ea9d93f
3f5d2f5
049643f
08282e4
5f41acd
ed3f624
b69594e
0f83a1e
084f9a1
e8ccbe3
22916ef
ef6d234
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
| import sys | ||
| from enum import Enum | ||
| from subprocess import Popen, TimeoutExpired | ||
| from typing import Literal | ||
|
|
||
| import typer | ||
|
|
||
|
|
@@ -134,12 +135,15 @@ def get_azure_access_token(image_registry: str) -> bytes: | |
| return token | ||
|
|
||
|
|
||
| def login_registry(image_registry: str) -> None: | ||
| def login_registry( | ||
| image_registry: str, | ||
| build_tool: Literal["podman", "docker", "auto"] = "podman", | ||
| ) -> None: | ||
| """Logs into registry with az cli""" | ||
| typer.echo(f"Logging into acr with {BuildTool.podman.value}...") | ||
| token = get_azure_access_token(image_registry) | ||
| cmd = [ | ||
| BuildTool.podman.value, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would keep |
||
| build_tool, | ||
| "login", | ||
| "--username", | ||
| "00000000-0000-0000-0000-000000000000", | ||
|
|
@@ -175,22 +179,37 @@ def build_and_push( | |
| branch_name: str, | ||
| use_az_login: bool, | ||
| build_envs: list[str], | ||
| build_tool: Literal["podman", "docker", "auto"] = "podman", | ||
| build_format: Literal["OCI", "docker"] = "OCI", | ||
| ): | ||
| """Build a docker image and push it to the registry""" | ||
| # We need to work from the root of the repo so docker can access all files | ||
| previous_dir = os.getcwd() | ||
| os.chdir(repository_root) | ||
|
|
||
| cmd = [ | ||
| BuildTool.podman.value, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would keep BuildTool.podman.value |
||
| "build", | ||
| "-f", | ||
| os.path.join(os.getcwd(), dockerfile), | ||
| "-t", | ||
| os.path.join(image_registry, f"{image_name}:{tag}"), | ||
| "--build-arg=BRANCH_NAME=" + branch_name, | ||
| ".", | ||
| ] | ||
| if build_tool == BuildTool.podman.value and build_format == "docker": | ||
| cmd = [ | ||
|
||
| build_tool, | ||
| "build", | ||
| "-f", | ||
| os.path.join(os.getcwd(), dockerfile), | ||
| "-t", | ||
| os.path.join(image_registry, f"{image_name}:{tag}"), | ||
| "--format", | ||
| "docker", | ||
| "--build-arg=BRANCH_NAME=" + branch_name, | ||
| ".", | ||
| ] | ||
| else: | ||
| cmd = [ | ||
| build_tool, | ||
| "build", | ||
| "-f", | ||
| os.path.join(os.getcwd(), dockerfile), | ||
| "-t", | ||
| os.path.join(image_registry, f"{image_name}:{tag}"), | ||
| "--build-arg=BRANCH_NAME=" + branch_name, | ||
| ".", | ||
| ] | ||
| for env_var in build_envs: | ||
| cmd.extend(["--env", env_var]) | ||
|
|
||
|
|
@@ -200,10 +219,10 @@ def build_and_push( | |
| exception_on_failed_subprocess(subprocess.run(cmd, capture_output=False)) | ||
|
|
||
| if use_az_login: | ||
| login_registry(image_registry=image_registry) | ||
| login_registry(image_registry=image_registry, build_tool=build_tool) | ||
|
|
||
| typer.echo("Pushing image...") | ||
| cmd = [BuildTool.podman.value, "push", os.path.join(image_registry, f"{image_name}:{tag}")] | ||
mackenziedott marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| cmd = [build_tool, "push", os.path.join(image_registry, f"{image_name}:{tag}")] | ||
| if use_sudo: | ||
| cmd = ["sudo"] + cmd | ||
| exception_on_failed_subprocess(subprocess.run(cmd, capture_output=False)) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not true, you can run podman fine without sudo
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently not in Azure Pipelines! Either that or I have to do some funkier stuff to make it work. Running podman info fails right after installation, but sudo podman info works fine.