From 0da6d2115dd5c3aedd1f5c8def9bd57eadbdce3a Mon Sep 17 00:00:00 2001 From: bhoobalan Date: Fri, 11 Nov 2022 14:38:39 +0530 Subject: [PATCH 1/3] Portainer Node Red Added --- node-red/portainer_node-red.json | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 node-red/portainer_node-red.json diff --git a/node-red/portainer_node-red.json b/node-red/portainer_node-red.json new file mode 100644 index 0000000..acef646 --- /dev/null +++ b/node-red/portainer_node-red.json @@ -0,0 +1,21 @@ +{ + "version": "2", + "templates": [ + { + "type": 1, + "title": "Node Red", + "name": "node-red", + "description": "Eclipse Mosquitto is an open source message broker which implements MQTT version 5, 3.1.1 and 3.1", + "platform": "linux", + "logo": "https://d1q6f0aelx0por.cloudfront.net/product-logos/library-eclipse-mosquitto-logo.png", + "image": "nodered/node-red", + "ports": [ + "1880:1880/tcp" + ], + "volumes": [ + "/data" + ], + "restart_policy": "always" + } + ] + } \ No newline at end of file -- 2.54.0 From c0d9973273ebc9e1f4e39c126e2905282844abbb Mon Sep 17 00:00:00 2001 From: bhoobalan Date: Sat, 12 Nov 2022 12:31:38 +0530 Subject: [PATCH 2/3] change --- node-red/portainer_node-red.json | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 node-red/portainer_node-red.json diff --git a/node-red/portainer_node-red.json b/node-red/portainer_node-red.json deleted file mode 100644 index acef646..0000000 --- a/node-red/portainer_node-red.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "version": "2", - "templates": [ - { - "type": 1, - "title": "Node Red", - "name": "node-red", - "description": "Eclipse Mosquitto is an open source message broker which implements MQTT version 5, 3.1.1 and 3.1", - "platform": "linux", - "logo": "https://d1q6f0aelx0por.cloudfront.net/product-logos/library-eclipse-mosquitto-logo.png", - "image": "nodered/node-red", - "ports": [ - "1880:1880/tcp" - ], - "volumes": [ - "/data" - ], - "restart_policy": "always" - } - ] - } \ No newline at end of file -- 2.54.0 From f23c3eb0328a38cb414143ec038212091b6a8322 Mon Sep 17 00:00:00 2001 From: bhoobalan Date: Sat, 12 Nov 2022 12:52:31 +0530 Subject: [PATCH 3/3] Portainer Script Added --- Portainer_Script/.env.copy | 1 + Portainer_Script/README.md | 7 ++ .../bitnami_yml_files/couchdb.yml | 15 +++ Portainer_Script/bitnami_yml_files/dex.yml | 5 + .../bitnami_yml_files/discourse.yml | 66 ++++++++++++++ .../bitnami_yml_files/dokuwiki.yml | 12 +++ Portainer_Script/requirements.txt | 1 + Portainer_Script/yml_to_json.py | 91 +++++++++++++++++++ 8 files changed, 198 insertions(+) create mode 100644 Portainer_Script/.env.copy create mode 100644 Portainer_Script/README.md create mode 100644 Portainer_Script/bitnami_yml_files/couchdb.yml create mode 100644 Portainer_Script/bitnami_yml_files/dex.yml create mode 100644 Portainer_Script/bitnami_yml_files/discourse.yml create mode 100644 Portainer_Script/bitnami_yml_files/dokuwiki.yml create mode 100644 Portainer_Script/requirements.txt create mode 100644 Portainer_Script/yml_to_json.py diff --git a/Portainer_Script/.env.copy b/Portainer_Script/.env.copy new file mode 100644 index 0000000..5d37331 --- /dev/null +++ b/Portainer_Script/.env.copy @@ -0,0 +1 @@ +FILE_PATH=yml_files \ No newline at end of file diff --git a/Portainer_Script/README.md b/Portainer_Script/README.md new file mode 100644 index 0000000..04c5ed1 --- /dev/null +++ b/Portainer_Script/README.md @@ -0,0 +1,7 @@ + +# Yml Files to Portainer Json Script + +1. Run `pip install -r requirements.txt ` +2. Run `cp .env.copy .env `, Config `.env` file for file path, where yml files are located. +3. Run the `yml_to_json.py` script. +4. File named `portainer_json_format.json` will be created. diff --git a/Portainer_Script/bitnami_yml_files/couchdb.yml b/Portainer_Script/bitnami_yml_files/couchdb.yml new file mode 100644 index 0000000..e351484 --- /dev/null +++ b/Portainer_Script/bitnami_yml_files/couchdb.yml @@ -0,0 +1,15 @@ +version: '2' +services: + couchdb: + image: docker.io/bitnami/couchdb:3 + environment: + - COUCHDB_PASSWORD=couchdb + ports: + - '5984:5984' + - '4369:4369' + - '9100:9100' + volumes: + - couchdb_data:/bitnami/couchdb +volumes: + couchdb_data: + driver: local diff --git a/Portainer_Script/bitnami_yml_files/dex.yml b/Portainer_Script/bitnami_yml_files/dex.yml new file mode 100644 index 0000000..c7ed7e9 --- /dev/null +++ b/Portainer_Script/bitnami_yml_files/dex.yml @@ -0,0 +1,5 @@ +version: '2' + +services: + dex: + image: docker.io/bitnami/dex:2 diff --git a/Portainer_Script/bitnami_yml_files/discourse.yml b/Portainer_Script/bitnami_yml_files/discourse.yml new file mode 100644 index 0000000..6b9b371 --- /dev/null +++ b/Portainer_Script/bitnami_yml_files/discourse.yml @@ -0,0 +1,66 @@ +version: '2' +services: + postgresql: + image: docker.io/bitnami/postgresql:11 + volumes: + - 'postgresql_data:/bitnami/postgresql' + environment: + # ALLOW_EMPTY_PASSWORD is recommended only for development. + - ALLOW_EMPTY_PASSWORD=yes + - POSTGRESQL_USERNAME=bn_discourse + - POSTGRESQL_DATABASE=bitnami_discourse + redis: + image: docker.io/bitnami/redis:7.0 + environment: + # ALLOW_EMPTY_PASSWORD is recommended only for development. + - ALLOW_EMPTY_PASSWORD=yes + volumes: + - 'redis_data:/bitnami/redis' + discourse: + image: docker.io/bitnami/discourse:2 + ports: + - '80:3000' + volumes: + - 'discourse_data:/bitnami/discourse' + depends_on: + - postgresql + - redis + environment: + # ALLOW_EMPTY_PASSWORD is recommended only for development. + - ALLOW_EMPTY_PASSWORD=yes + - DISCOURSE_HOST=www.example.com + - DISCOURSE_DATABASE_HOST=postgresql + - DISCOURSE_DATABASE_PORT_NUMBER=5432 + - DISCOURSE_DATABASE_USER=bn_discourse + - DISCOURSE_DATABASE_NAME=bitnami_discourse + - DISCOURSE_REDIS_HOST=redis + - DISCOURSE_REDIS_PORT_NUMBER=6379 + - POSTGRESQL_CLIENT_POSTGRES_USER=postgres + - POSTGRESQL_CLIENT_CREATE_DATABASE_NAME=bitnami_discourse + - POSTGRESQL_CLIENT_CREATE_DATABASE_EXTENSIONS=hstore,pg_trgm + sidekiq: + image: docker.io/bitnami/discourse:2 + depends_on: + - discourse + volumes: + - 'sidekiq_data:/bitnami/discourse' + command: /opt/bitnami/scripts/discourse-sidekiq/run.sh + environment: + # ALLOW_EMPTY_PASSWORD is recommended only for development. + - ALLOW_EMPTY_PASSWORD=yes + - DISCOURSE_HOST=www.example.com + - DISCOURSE_DATABASE_HOST=postgresql + - DISCOURSE_DATABASE_PORT_NUMBER=5432 + - DISCOURSE_DATABASE_USER=bn_discourse + - DISCOURSE_DATABASE_NAME=bitnami_discourse + - DISCOURSE_REDIS_HOST=redis + - DISCOURSE_REDIS_PORT_NUMBER=6379 +volumes: + postgresql_data: + driver: local + redis_data: + driver: local + discourse_data: + driver: local + sidekiq_data: + driver: local diff --git a/Portainer_Script/bitnami_yml_files/dokuwiki.yml b/Portainer_Script/bitnami_yml_files/dokuwiki.yml new file mode 100644 index 0000000..b9a5991 --- /dev/null +++ b/Portainer_Script/bitnami_yml_files/dokuwiki.yml @@ -0,0 +1,12 @@ +version: '2' +services: + dokuwiki: + image: docker.io/bitnami/dokuwiki:20220731 + ports: + - '80:8080' + - '443:8443' + volumes: + - 'dokuwiki_data:/bitnami/dokuwiki' +volumes: + dokuwiki_data: + driver: local diff --git a/Portainer_Script/requirements.txt b/Portainer_Script/requirements.txt new file mode 100644 index 0000000..3e338bf --- /dev/null +++ b/Portainer_Script/requirements.txt @@ -0,0 +1 @@ +python-dotenv \ No newline at end of file diff --git a/Portainer_Script/yml_to_json.py b/Portainer_Script/yml_to_json.py new file mode 100644 index 0000000..803a7d9 --- /dev/null +++ b/Portainer_Script/yml_to_json.py @@ -0,0 +1,91 @@ +import os +from dotenv import load_dotenv +load_dotenv() +file_name=list() +#listing all yml file in the path +for x in os.listdir(os.getenv('FILE_PATH')): + if x.endswith(".yml"): + print(x) + file_name.append(x) +portainer_json_format=''' +{ + "version": "2", + "templates": [ + { + ''' +temp_expect_handle=0 +port=1024 +for i in file_name: + temp_replace_title='' + temp='' + with open(os.getenv('FILE_PATH')+i,'r') as f: + givenWord = 'image:' + for textline in f: + wordsList = textline.split() + if givenWord in wordsList: + temp_replace_title=temp + temp=textline + + title=temp_replace_title.replace(" ", "").replace('\n','').replace(':','') + with open(os.getenv('FILE_PATH')+i,'r') as ff: + kk=ff.read() + portainer_json_format +=' "type": 1,' + portainer_json_format +=f'"title" : "{title}",\n' + portainer_json_format +=f'"name": "{title}.bit.lan",\n' + portainer_json_format +='"platform": "linux",\n' + portainer_json_format+= '"administrator_only": false,\n' + + #finding image name + start_value=kk.rfind("image:") + end_value=kk.find('\n',start_value+6) + image=kk[start_value+6:end_value].replace(" ", "").replace('\n','') + portainer_json_format +=f'"image" : "{image}",\n' + portainer_json_format +=f'"hostname": "{title}",\n"restart_policy": "always",\n' + portainer_json_format +=f'"ports": ["{port}/tcp"],\n' + port+=1 + #volumes allocating + try: + start_value=kk.index("volumes:") + + start_value=kk.find("-",start_value) + end_Value=kk.find(":",start_value+3) + # print("image :",kk[start_value+3:end_Value].replace(" ", "").replace('\n','')) + ports=kk[start_value+3:end_Value].replace(" ", "").replace('\n','') + portainer_json_format +=''' + "volumes": [ + { + "container": "/%s/data", + "bind": "/srv/%s.bit.lan/docker/data", + "readonly": false + }, + + { + "container": "/%s/config", + "bind": "/srv/%s.bit.lan/docker/config", + "readonly": false + } + , + { + "container": "/%s/log", + "bind": "/srv/%s.bit.lan/docker/log", + "readonly": false + } + ],\n'''%(title,title,title,title,title,title) + + except: + temp_expect_handle=1 + portainer_json_format+= ''' "labels": [ + { "name": "com.centurylinklabs.watchtower.enable", "value": "true" } + ]''' + portainer_json_format+= ''' + }, + { + ''' +portainer_json_format+= ''' + ] + } + ''' + +portainer_json_format = f"{portainer_json_format}" +with open("portainer_json_format.json",'w') as f: + f.write(portainer_json_format) -- 2.54.0