Created
April 1, 2024 01:35
-
-
Save acenturyandabit/516a5b42d46b9f8c796758a01e15234e to your computer and use it in GitHub Desktop.
This file contains 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
# Use to merge docker files together and output them as one single file. | |
# Usage: python docker_compose_combine.py -f docker-compose1.yaml -f docker-compose2.yaml | |
# Courtesy of our good friend ChatGPT. | |
import argparse | |
import yaml | |
from collections import OrderedDict | |
def combine_compose_files(files): | |
combined_data = OrderedDict({'version': '3', 'services': {}}) | |
for file in files: | |
with open(file, 'r') as f: | |
data = yaml.safe_load(f) | |
if 'services' in data: | |
combined_data['services'].update(data['services']) | |
return combined_data | |
def main(): | |
parser = argparse.ArgumentParser(description='Combine multiple Docker Compose files into a single YAML file') | |
parser.add_argument('-f', '--file', action='append', dest='files', required=True, | |
help='Specify one or more Docker Compose files to combine', metavar='FILE') | |
args = parser.parse_args() | |
combined_data = combine_compose_files(args.files) | |
print(yaml.dump(combined_data, default_flow_style=False)) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment