forked from cerc-io/stack-orchestrator
Compare commits
1 Commits
main
...
telackey/d
Author | SHA1 | Date | |
---|---|---|---|
4e5b5ff031 |
@ -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.deploy.webapp.util import determine_base_container, TimedLogger
|
||||||
from stack_orchestrator.build.build_types import BuildContext
|
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.command()
|
||||||
@click.option('--base-container')
|
@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("--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("--extra-build-args", help="Supply extra arguments to build")
|
||||||
@click.option("--tag", help="Container tag (default: cerc/<app_name>:local)")
|
@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
|
@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'''
|
'''build the specified webapp container'''
|
||||||
logger = TimedLogger()
|
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.
|
# 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_WEBAPP_BUILD_RUNNING"] = "true"
|
||||||
container_build_env["CERC_CONTAINER_BUILD_WORK_DIR"] = os.path.abspath(source_repo)
|
container_build_env["CERC_CONTAINER_BUILD_WORK_DIR"] = os.path.abspath(source_repo)
|
||||||
|
container_build_env["CERC_CONTAINER_BUILD_DOCKERFILE"] = os.path.join(container_build_dir,
|
||||||
# Check if Dockerfile exists in the repository
|
base_container.replace("/", "-"),
|
||||||
repo_dockerfile = os.path.join(container_build_env["CERC_CONTAINER_BUILD_WORK_DIR"], "Dockerfile")
|
"Dockerfile.webapp")
|
||||||
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
|
|
||||||
|
|
||||||
if not tag:
|
if not tag:
|
||||||
webapp_name = os.path.abspath(source_repo).split(os.path.sep)[-1]
|
webapp_name = os.path.abspath(source_repo).split(os.path.sep)[-1]
|
||||||
tag = f"cerc/{webapp_name}:local"
|
tag = f"cerc/{webapp_name}:local"
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
# along with this program. If not, see <http:#www.gnu.org/licenses/>.
|
# along with this program. If not, see <http:#www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import click
|
import click
|
||||||
|
import os
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
import json
|
import json
|
||||||
import platform
|
import platform
|
||||||
@ -84,13 +85,18 @@ def _filter_for_platform(container: str,
|
|||||||
tag_list: List[str]) -> List[str] :
|
tag_list: List[str]) -> List[str] :
|
||||||
filtered_tags = []
|
filtered_tags = []
|
||||||
this_machine = platform.machine()
|
this_machine = platform.machine()
|
||||||
# Translate between Python and docker platform names
|
if "DOCKER_DEFAULT_PLATFORM" in os.environ:
|
||||||
if this_machine == "x86_64":
|
this_machine = os.environ["DOCKER_DEFAULT_PLATFORM"].split("/")[-1]
|
||||||
this_machine = "amd64"
|
if opts.o.debug:
|
||||||
if this_machine == "aarch64":
|
print(f"DOCKER_DEFAULT_PLATFORM says the architecture is: {this_machine}")
|
||||||
this_machine = "arm64"
|
else:
|
||||||
if opts.o.debug:
|
# Translate between Python and docker platform names
|
||||||
print(f"Python says the architecture is: {this_machine}")
|
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()
|
docker = DockerClient()
|
||||||
for tag in tag_list:
|
for tag in tag_list:
|
||||||
remote_tag = f"{registry_info.registry}/{container}:{tag}"
|
remote_tag = f"{registry_info.registry}/{container}:{tag}"
|
||||||
|
Loading…
Reference in New Issue
Block a user