Compare commits

..

1 Commits

Author SHA1 Message Date
4e5b5ff031 Honor DOCKER_DEFAULT_PLATFORM 2024-08-29 14:57:35 -05:00
2 changed files with 17 additions and 37 deletions

View File

@ -30,12 +30,6 @@ from stack_orchestrator.build import build_containers
from stack_orchestrator.deploy.webapp.util import determine_base_container, TimedLogger
from stack_orchestrator.build.build_types import BuildContext
def create_env_file(env_vars, repo_root):
env_file_path = os.path.join(repo_root, '.env')
with open(env_file_path, 'w') as env_file:
for key, value in env_vars.items():
env_file.write(f"{key}={value}\n")
return env_file_path
@click.command()
@click.option('--base-container')
@ -43,9 +37,8 @@ def create_env_file(env_vars, repo_root):
@click.option("--force-rebuild", is_flag=True, default=False, help="Override dependency checking -- always rebuild")
@click.option("--extra-build-args", help="Supply extra arguments to build")
@click.option("--tag", help="Container tag (default: cerc/<app_name>:local)")
@click.option("--env", help="Environment variables for webapp (format: KEY1=VALUE1,KEY2=VALUE2)", default="")
@click.pass_context
def command(ctx, base_container, source_repo, force_rebuild, extra_build_args, tag, env):
def command(ctx, base_container, source_repo, force_rebuild, extra_build_args, tag):
'''build the specified webapp container'''
logger = TimedLogger()
@ -95,28 +88,9 @@ def command(ctx, base_container, source_repo, force_rebuild, extra_build_args, t
# Now build the target webapp. We use the same build script, but with a different Dockerfile and work dir.
container_build_env["CERC_WEBAPP_BUILD_RUNNING"] = "true"
container_build_env["CERC_CONTAINER_BUILD_WORK_DIR"] = os.path.abspath(source_repo)
# Check if Dockerfile exists in the repository
repo_dockerfile = os.path.join(container_build_env["CERC_CONTAINER_BUILD_WORK_DIR"], "Dockerfile")
default_dockerfile = os.path.join(container_build_dir,
base_container.replace("/", "-"),
"Dockerfile.webapp")
if os.path.isfile(repo_dockerfile):
env_vars = {}
if env:
for pair in env.split(','):
key, value = pair.split('=')
env_vars[key.strip()] = value.strip()
container_build_env["CERC_CONTAINER_BUILD_DOCKERFILE"] = repo_dockerfile
# Create .env file with environment variables
env_file_path = create_env_file(env_vars, container_build_env["CERC_CONTAINER_BUILD_WORK_DIR"])
container_build_env["CERC_CONTAINER_BUILD_ENV_FILE"] = env_file_path
else:
container_build_env["CERC_CONTAINER_BUILD_DOCKERFILE"] = default_dockerfile
container_build_env["CERC_CONTAINER_BUILD_DOCKERFILE"] = os.path.join(container_build_dir,
base_container.replace("/", "-"),
"Dockerfile.webapp")
if not tag:
webapp_name = os.path.abspath(source_repo).split(os.path.sep)[-1]
tag = f"cerc/{webapp_name}:local"

View File

@ -14,6 +14,7 @@
# along with this program. If not, see <http:#www.gnu.org/licenses/>.
import click
import os
from dataclasses import dataclass
import json
import platform
@ -84,13 +85,18 @@ def _filter_for_platform(container: str,
tag_list: List[str]) -> List[str] :
filtered_tags = []
this_machine = platform.machine()
# Translate between Python and docker platform names
if this_machine == "x86_64":
this_machine = "amd64"
if this_machine == "aarch64":
this_machine = "arm64"
if opts.o.debug:
print(f"Python says the architecture is: {this_machine}")
if "DOCKER_DEFAULT_PLATFORM" in os.environ:
this_machine = os.environ["DOCKER_DEFAULT_PLATFORM"].split("/")[-1]
if opts.o.debug:
print(f"DOCKER_DEFAULT_PLATFORM says the architecture is: {this_machine}")
else:
# Translate between Python and docker platform names
if this_machine == "x86_64":
this_machine = "amd64"
if this_machine == "aarch64":
this_machine = "arm64"
if opts.o.debug:
print(f"Python says the architecture is: {this_machine}")
docker = DockerClient()
for tag in tag_list:
remote_tag = f"{registry_info.registry}/{container}:{tag}"