-
Notifications
You must be signed in to change notification settings - Fork 32
Adds labels and network aliases #1214
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
Open
ribalba
wants to merge
2
commits into
main
Choose a base branch
from
label-and-network-alias
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -469,6 +469,10 @@ def remove_docker_images(self): | |||||
and then link itself in the runs table accordingly. | ||||||
''' | ||||||
def register_machine_id(self): | ||||||
|
||||||
if self._dev_no_save: | ||||||
return | ||||||
|
||||||
config = GlobalConfig().config | ||||||
if config['machine'].get('id') is None \ | ||||||
or not isinstance(config['machine']['id'], int) \ | ||||||
|
@@ -973,10 +977,56 @@ def setup_services(self): | |||||
if env_var_check_errors: | ||||||
raise RuntimeError('Docker container environment setup has problems:\n\n'.join(env_var_check_errors)) | ||||||
|
||||||
if 'labels' in service: | ||||||
labels_check_errors = [] | ||||||
for docker_label_var in service['labels']: | ||||||
# https://docs.docker.com/reference/compose-file/services/#labels | ||||||
if isinstance(docker_label_var, str) and '=' in docker_label_var: | ||||||
label_key, label_value = docker_label_var.split('=') | ||||||
elif isinstance(service['labels'], dict): | ||||||
label_key, label_value = str(docker_label_var), str(service['labels'][docker_label_var]) | ||||||
else: | ||||||
|
||||||
raise RuntimeError('Environment variable needs to be a string with = or dict and non-empty. We do not allow the feature of forwarding variables from the host OS!') | ||||||
|
||||||
# Check the key of the environment var | ||||||
if not self._allow_unsafe and re.search(r'^[A-Za-z_]+[A-Za-z0-9_.]*$', label_key) is None: | ||||||
if self._skip_unsafe: | ||||||
warn_message= arrows(f"Found label key with wrong format. Only ^[A-Za-z_]+[A-Za-z0-9_.]*$ allowed: {label_key} - Skipping") | ||||||
print(TerminalColors.WARNING, warn_message, TerminalColors.ENDC) | ||||||
continue | ||||||
labels_check_errors.append(f"- key '{label_key}' has wrong format. Only ^[A-Za-z_]+[A-Za-z0-9_.]*$ is allowed - Maybe consider using --allow-unsafe or --skip-unsafe") | ||||||
|
||||||
# Check the value of the environment var | ||||||
# We only forbid long values (>1024), every character is allowed. | ||||||
# The value is directly passed to the container and is not evaluated on the host system, so there is no security related reason to forbid special characters. | ||||||
if not self._allow_unsafe and len(label_value) > 1024: | ||||||
if self._skip_unsafe: | ||||||
print(TerminalColors.WARNING, arrows(f"Found label value with size {len(label_value)} (max allowed length is 1024) - Skipping label '{label_value}'"), TerminalColors.ENDC) | ||||||
continue | ||||||
labels_check_errors.append(f"- value of label '{label_key}' is too long {len(label_key)} (max allowed length is 1024) - Maybe consider using --allow-unsafe or --skip-unsafe") | ||||||
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. logic: Using label_key length instead of label_value length in error message
Suggested change
|
||||||
|
||||||
docker_run_string.append('-l') | ||||||
docker_run_string.append(f"{label_key}={label_value}") | ||||||
|
||||||
if labels_check_errors: | ||||||
raise RuntimeError('Docker container labels that have problems:\n\n'.join(labels_check_errors)) | ||||||
|
||||||
if 'networks' in service: | ||||||
for network in service['networks']: | ||||||
docker_run_string.append('--net') | ||||||
docker_run_string.append(network) | ||||||
print('-------------------------------------------------------------') | ||||||
print(service['networks']) | ||||||
print(network) | ||||||
print('-------------------------------------------------------------') | ||||||
if service['networks'][network]: | ||||||
if service['networks'][network].get('aliases', None): | ||||||
for alias in service['networks'][network]['aliases']: | ||||||
docker_run_string.append('--network-alias') | ||||||
docker_run_string.append(alias) | ||||||
print(f"Adding network alias {alias} for network {network} in service {service_name}") | ||||||
|
||||||
elif self.__join_default_network: | ||||||
# only join default network if no other networks provided | ||||||
# if this is true only one entry is in self.__networks | ||||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
syntax: Error message should refer to 'label' instead of 'Environment variable'