Portainer Script Added
This commit is contained in:
@@ -0,0 +1 @@
|
||||
FILE_PATH=yml_files
|
||||
@@ -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.
|
||||
@@ -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
|
||||
@@ -0,0 +1,5 @@
|
||||
version: '2'
|
||||
|
||||
services:
|
||||
dex:
|
||||
image: docker.io/bitnami/dex:2
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -0,0 +1 @@
|
||||
python-dotenv
|
||||
@@ -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)
|
||||
Reference in New Issue
Block a user