revival
This commit is contained in:
		
							parent
							
								
									f7eaa1e5fc
								
							
						
					
					
						commit
						1f3a7bd9d8
					
				
					 7 changed files with 1607 additions and 0 deletions
				
			
		
							
								
								
									
										8
									
								
								.idea/.gitignore
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								.idea/.gitignore
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,8 @@
 | 
				
			||||||
 | 
					# Default ignored files
 | 
				
			||||||
 | 
					/shelf/
 | 
				
			||||||
 | 
					/workspace.xml
 | 
				
			||||||
 | 
					# Editor-based HTTP Client requests
 | 
				
			||||||
 | 
					/httpRequests/
 | 
				
			||||||
 | 
					# Datasource local storage ignored files
 | 
				
			||||||
 | 
					/dataSources/
 | 
				
			||||||
 | 
					/dataSources.local.xml
 | 
				
			||||||
							
								
								
									
										0
									
								
								__init__.py
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										0
									
								
								__init__.py
									
										
									
									
									
										Executable file
									
								
							
							
								
								
									
										100
									
								
								main.py
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										100
									
								
								main.py
									
										
									
									
									
										Executable file
									
								
							| 
						 | 
					@ -0,0 +1,100 @@
 | 
				
			||||||
 | 
					# Universal Docker Setup Tool by Raphael Lucas Dittberner
 | 
				
			||||||
 | 
					import os
 | 
				
			||||||
 | 
					import subprocess
 | 
				
			||||||
 | 
					import sys
 | 
				
			||||||
 | 
					import typer
 | 
				
			||||||
 | 
					import yaml
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					app = typer.Typer()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if "REPO" in os.environ:
 | 
				
			||||||
 | 
					    repo = os.environ['REPO'] + '/'
 | 
				
			||||||
 | 
					    print("Your current repository path is " + repo + ". To change it, change the REPO environment variable.")
 | 
				
			||||||
 | 
					else:
 | 
				
			||||||
 | 
					    repo = ''
 | 
				
			||||||
 | 
					    print("The tool will use the config file from the directory it is running in. If you want to change this, "
 | 
				
			||||||
 | 
					          "set the REPO environment variable.")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					config = repo + 'udtconfig.yml'
 | 
				
			||||||
 | 
					with open(config, 'r') as udtcfg:
 | 
				
			||||||
 | 
					    read_config = yaml.safe_load(udtcfg)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					compose_config = repo + "docker-compose.yml"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					services = read_config['services']
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@app.command(help="Create docker containers for services specified in utdconfig.yml without starting them")
 | 
				
			||||||
 | 
					def create():
 | 
				
			||||||
 | 
					    subprocess.run(["rm", "-rf", compose_config])
 | 
				
			||||||
 | 
					    invalid_options = ['addons', 'bindings', 'commands']
 | 
				
			||||||
 | 
					    with open(config) as oldfile, open(compose_config, 'w') as newfile:
 | 
				
			||||||
 | 
					        for line in oldfile:
 | 
				
			||||||
 | 
					            if not any(invalid_option in line for invalid_option in invalid_options):
 | 
				
			||||||
 | 
					                newfile.write(line)
 | 
				
			||||||
 | 
					    subprocess.run(["docker-compose", "-f", compose_config, "up", "--no-start"])
 | 
				
			||||||
 | 
					    for i in list(read_config['services']):
 | 
				
			||||||
 | 
					        for index in list(read_config['services'][i]['addons']['bindings']['commands']):
 | 
				
			||||||
 | 
					            subprocess.run([index])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@app.command(help="Start all or specific services specified in udtconfig.yml")
 | 
				
			||||||
 | 
					def start():
 | 
				
			||||||
 | 
					    start_service = input("Enter the name of the service you want to start, or press ENTER to start all: ")
 | 
				
			||||||
 | 
					    if start_service == "":
 | 
				
			||||||
 | 
					        start_service = list(services)
 | 
				
			||||||
 | 
					        index = 0
 | 
				
			||||||
 | 
					        for i in start_service:
 | 
				
			||||||
 | 
					            subprocess.run(["docker-compose", "start", start_service[index]])
 | 
				
			||||||
 | 
					            index += 1
 | 
				
			||||||
 | 
					        sys.exit(0)
 | 
				
			||||||
 | 
					    else:
 | 
				
			||||||
 | 
					        subprocess.run(["docker-compose", "start", start_service])
 | 
				
			||||||
 | 
					        sys.exit(0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@app.command(help="Stop all or specific services specified in udtconfig.yml")
 | 
				
			||||||
 | 
					def stop():
 | 
				
			||||||
 | 
					    stop_service = input("Enter the name of the service you want to stop, or press ENTER to stop all: ")
 | 
				
			||||||
 | 
					    if stop_service == "":
 | 
				
			||||||
 | 
					        while True:
 | 
				
			||||||
 | 
					            confirm = input("Are you sure you want to stop all services? Type YES or NO! ")
 | 
				
			||||||
 | 
					            if confirm == "NO":
 | 
				
			||||||
 | 
					                print("aborting")
 | 
				
			||||||
 | 
					                sys.exit(0)
 | 
				
			||||||
 | 
					            elif confirm == "YES":
 | 
				
			||||||
 | 
					                stop_service = list(services)
 | 
				
			||||||
 | 
					                index = 0
 | 
				
			||||||
 | 
					                for i in stop_service:
 | 
				
			||||||
 | 
					                    subprocess.run(["docker-compose", "stop", stop_service[index]])
 | 
				
			||||||
 | 
					                    index += 1
 | 
				
			||||||
 | 
					                sys.exit(0)
 | 
				
			||||||
 | 
					            else:
 | 
				
			||||||
 | 
					                print("Please type YES or NO!")
 | 
				
			||||||
 | 
					                continue
 | 
				
			||||||
 | 
					    else:
 | 
				
			||||||
 | 
					        subprocess.run(["docker-compose", "stop", stop_service])
 | 
				
			||||||
 | 
					        sys.exit(0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@app.command(help="Run shell in docker container of specified service")
 | 
				
			||||||
 | 
					def shell():
 | 
				
			||||||
 | 
					    service = input("Enter service name: ")
 | 
				
			||||||
 | 
					    subprocess.run(["docker", "compose", "run", service, "sh"])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@app.command(help="Run karaf shell in specified openhab container")
 | 
				
			||||||
 | 
					def karaf():
 | 
				
			||||||
 | 
					    service = input("Enter service name: ")
 | 
				
			||||||
 | 
					    subprocess.run(["docker", "compose", "run", service, "/openhab/runtime/bin/client"])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@app.command(help="Stop all services and delete all docker containers")
 | 
				
			||||||
 | 
					def down():
 | 
				
			||||||
 | 
					    subprocess.run(["docker-compose", "-f", compose_config, "down"])
 | 
				
			||||||
 | 
					    sys.exit(0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if __name__ == "__main__":
 | 
				
			||||||
 | 
					    app()
 | 
				
			||||||
							
								
								
									
										4
									
								
								requirements.txt
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										4
									
								
								requirements.txt
									
										
									
									
									
										Executable file
									
								
							| 
						 | 
					@ -0,0 +1,4 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					docker-compose==1.29.2
 | 
				
			||||||
 | 
					typer==0.9.0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										2
									
								
								udtconfig template
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										2
									
								
								udtconfig template
									
										
									
									
									
										Executable file
									
								
							| 
						 | 
					@ -0,0 +1,2 @@
 | 
				
			||||||
 | 
					[udtconfig]
 | 
				
			||||||
 | 
					docker_image = test
 | 
				
			||||||
							
								
								
									
										34
									
								
								udtconfig.yml
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										34
									
								
								udtconfig.yml
									
										
									
									
									
										Executable file
									
								
							| 
						 | 
					@ -0,0 +1,34 @@
 | 
				
			||||||
 | 
					services:
 | 
				
			||||||
 | 
					  alpine1:
 | 
				
			||||||
 | 
					    image: redis:alpine
 | 
				
			||||||
 | 
					    addons:
 | 
				
			||||||
 | 
					      bindings:
 | 
				
			||||||
 | 
					        commands: [ls]
 | 
				
			||||||
 | 
					  alpine2:
 | 
				
			||||||
 | 
					    image: redis:alpine
 | 
				
			||||||
 | 
					    addons:
 | 
				
			||||||
 | 
					      bindings:
 | 
				
			||||||
 | 
					        commands: [ls]
 | 
				
			||||||
 | 
					  debian:
 | 
				
			||||||
 | 
					    image: debian:latest
 | 
				
			||||||
 | 
					    addons:
 | 
				
			||||||
 | 
					      bindings:
 | 
				
			||||||
 | 
					        commands: [ls]
 | 
				
			||||||
 | 
					  openhab:
 | 
				
			||||||
 | 
					    image: openhab/openhab:latest
 | 
				
			||||||
 | 
					    restart: always
 | 
				
			||||||
 | 
					    network_mode: host
 | 
				
			||||||
 | 
					    volumes:
 | 
				
			||||||
 | 
					      - "/etc/localtime:/etc/localtime:ro"
 | 
				
			||||||
 | 
					      - "/etc/timezone:/etc/timezone:ro"
 | 
				
			||||||
 | 
					      - "./openhab_addons:/openhab/addons"
 | 
				
			||||||
 | 
					      - "./openhab_conf:/openhab/conf"
 | 
				
			||||||
 | 
					      - "./openhab_userdata:/openhab/userdata"
 | 
				
			||||||
 | 
					    environment:
 | 
				
			||||||
 | 
					      CRYPTO_POLICY: "unlimited"
 | 
				
			||||||
 | 
					      EXTRA_JAVA_OPTS: "-Duser.timezone=Europe/Berlin"
 | 
				
			||||||
 | 
					      OPENHAB_HTTP_PORT: "8080"
 | 
				
			||||||
 | 
					      OPENHAB_HTTPS_PORT: "8443"
 | 
				
			||||||
 | 
					    addons:
 | 
				
			||||||
 | 
					      bindings:
 | 
				
			||||||
 | 
					        commands: [ls]
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue