Skip to content

Commit

Permalink
Merge pull request #54 from blumenstiel/main
Browse files Browse the repository at this point in the history
Added plattfrom arg and added docker buildx
  • Loading branch information
romeokienzler authored Mar 27, 2024
2 parents 2ac399f + e08161a commit dba1fe8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/c3/create_gridwrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ def main():
help='Exclude logging code from component setup code')
parser.add_argument('--keep-generated-files', action='store_true',
help='Do not delete temporary generated files.')
parser.add_argument('--platform', type=str, default='linux/amd64',
help='Select image platform, default is linux/amd64. Alternativly, select linux/arm64".')

args = parser.parse_args()

Expand Down Expand Up @@ -227,6 +229,7 @@ def main():
rename_files=args.rename,
skip_logging=args.skip_logging,
keep_generated_files=args.keep_generated_files,
platform=args.platform,
)
except Exception as err:
logging.error('Error while generating CLAIMED grid wrapper. '
Expand Down
16 changes: 15 additions & 1 deletion src/c3/create_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ def create_operator(file_path: str,
overwrite_files=False,
skip_logging=False,
keep_generated_files=False,
platform='linux/amd64',
):
logging.info('Parameters: ')
logging.info('file_path: ' + file_path)
Expand Down Expand Up @@ -356,12 +357,21 @@ def create_operator(file_path: str,
logging.warning('No repository provided. The container image is only saved locally. Add `-r <repository>` '
'to push the image to a container registry or run `--local_mode` to suppress this warning.')
local_mode = True
repository = 'local'

if subprocess.run('docker buildx', shell=True, stdout=subprocess.PIPE).returncode == 0:
# Using docker buildx
logging.debug('Using docker buildx')
build_command = 'docker buildx build'
else:
logging.debug('Using docker build. Consider installing docker-buildx.')
build_command = 'docker build'

logging.info(f'Building container image claimed-{name}:{version}')
try:
# Run docker build
subprocess.run(
f"docker build --platform linux/amd64 -t claimed-{name}:{version} . {'--no-cache' if no_cache else ''}",
f"{build_command} --platform {platform} -t claimed-{name}:{version} . {'--no-cache' if no_cache else ''}",
stdout=None if log_level == 'DEBUG' else subprocess.PIPE, check=True, shell=True
)
if repository is not None:
Expand Down Expand Up @@ -450,6 +460,9 @@ def main():
help='Exclude logging code from component setup code')
parser.add_argument('--keep-generated-files', action='store_true',
help='Do not delete temporary generated files.')
parser.add_argument('--platform', type=str, default='linux/amd64',
help='Select image platform, default is linux/amd64. Alternativly, select linux/arm64".')

args = parser.parse_args()

# Init logging
Expand Down Expand Up @@ -482,6 +495,7 @@ def main():
rename_files=args.rename,
skip_logging=args.skip_logging,
keep_generated_files=args.keep_generated_files,
platform=args.platform,
)


Expand Down

0 comments on commit dba1fe8

Please sign in to comment.