mantis-cli 18.0.0__tar.gz → 19.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mantis-cli-18.0.0/mantis_cli.egg-info → mantis-cli-19.0.0}/PKG-INFO +1 -1
- mantis-cli-19.0.0/mantis/__init__.py +1 -0
- {mantis-cli-18.0.0 → mantis-cli-19.0.0}/mantis/managers.py +81 -48
- {mantis-cli-18.0.0 → mantis-cli-19.0.0}/mantis/mantis.tpl +0 -1
- {mantis-cli-18.0.0 → mantis-cli-19.0.0/mantis_cli.egg-info}/PKG-INFO +1 -1
- mantis-cli-18.0.0/mantis/__init__.py +0 -1
- {mantis-cli-18.0.0 → mantis-cli-19.0.0}/LICENSE +0 -0
- {mantis-cli-18.0.0 → mantis-cli-19.0.0}/MANIFEST.in +0 -0
- {mantis-cli-18.0.0 → mantis-cli-19.0.0}/README.md +0 -0
- {mantis-cli-18.0.0 → mantis-cli-19.0.0}/mantis/__main__.py +0 -0
- {mantis-cli-18.0.0 → mantis-cli-19.0.0}/mantis/command_line.py +0 -0
- {mantis-cli-18.0.0 → mantis-cli-19.0.0}/mantis/crypto.py +0 -0
- {mantis-cli-18.0.0 → mantis-cli-19.0.0}/mantis/environment.py +0 -0
- {mantis-cli-18.0.0 → mantis-cli-19.0.0}/mantis/extensions/__init__.py +0 -0
- {mantis-cli-18.0.0 → mantis-cli-19.0.0}/mantis/extensions/django.py +0 -0
- {mantis-cli-18.0.0 → mantis-cli-19.0.0}/mantis/extensions/nginx.py +0 -0
- {mantis-cli-18.0.0 → mantis-cli-19.0.0}/mantis/extensions/postgres.py +0 -0
- {mantis-cli-18.0.0 → mantis-cli-19.0.0}/mantis/helpers.py +0 -0
- {mantis-cli-18.0.0 → mantis-cli-19.0.0}/mantis/logic.py +0 -0
- {mantis-cli-18.0.0 → mantis-cli-19.0.0}/mantis_cli.egg-info/SOURCES.txt +0 -0
- {mantis-cli-18.0.0 → mantis-cli-19.0.0}/mantis_cli.egg-info/dependency_links.txt +0 -0
- {mantis-cli-18.0.0 → mantis-cli-19.0.0}/mantis_cli.egg-info/entry_points.txt +0 -0
- {mantis-cli-18.0.0 → mantis-cli-19.0.0}/mantis_cli.egg-info/requires.txt +0 -0
- {mantis-cli-18.0.0 → mantis-cli-19.0.0}/mantis_cli.egg-info/top_level.txt +0 -0
- {mantis-cli-18.0.0 → mantis-cli-19.0.0}/setup.cfg +0 -0
- {mantis-cli-18.0.0 → mantis-cli-19.0.0}/setup.py +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
VERSION = '19.0.0'
|
|
@@ -2,6 +2,7 @@ import json
|
|
|
2
2
|
import os
|
|
3
3
|
import time
|
|
4
4
|
import yaml
|
|
5
|
+
from collections import defaultdict
|
|
5
6
|
from os import path
|
|
6
7
|
from os.path import dirname, normpath
|
|
7
8
|
from time import sleep
|
|
@@ -139,7 +140,7 @@ class AbstractManager(object):
|
|
|
139
140
|
|
|
140
141
|
self.key_file = normalize(path.join(self.config['encryption']['folder'], 'mantis.key'))
|
|
141
142
|
self.environment_path = normalize(self.config['environment']['folder'])
|
|
142
|
-
self.compose_path = normalize(self.config['compose']['folder'])
|
|
143
|
+
self.compose_path = normalize(path.join(self.config['compose']['folder'], self.environment_id))
|
|
143
144
|
|
|
144
145
|
def init_environment(self):
|
|
145
146
|
self.env = Environment(
|
|
@@ -150,14 +151,11 @@ class AbstractManager(object):
|
|
|
150
151
|
# connection
|
|
151
152
|
self.connection = self.config['connections'].get(self.env.id, None)
|
|
152
153
|
|
|
153
|
-
# compose
|
|
154
|
-
|
|
155
|
-
self.compose_file = os.path.join(self.compose_path, f'{compose_prefix}.{self.env.id}.yml')
|
|
154
|
+
# compose files
|
|
155
|
+
compose_file_paths = os.popen(f'find {self.compose_path} -name "*.yml" -o -name "*.yaml"').read().strip().split('\n')
|
|
156
156
|
|
|
157
|
-
#
|
|
158
|
-
self.
|
|
159
|
-
self.CONTAINER_PREFIX = self.PROJECT_NAME
|
|
160
|
-
self.IMAGE_PREFIX = self.PROJECT_NAME
|
|
157
|
+
# Remove empty strings
|
|
158
|
+
self.compose_files = list(filter(None, compose_file_paths))
|
|
161
159
|
|
|
162
160
|
def check_environment_encryption(self, env_file):
|
|
163
161
|
decrypted_environment = self.decrypt_env(env_file=env_file, return_value=True) # .env.encrypted
|
|
@@ -240,8 +238,10 @@ class AbstractManager(object):
|
|
|
240
238
|
def docker_compose(self, command, return_output=False, use_connection=True):
|
|
241
239
|
compose_command = self.config['compose']['command']
|
|
242
240
|
|
|
241
|
+
compose_files = ' '.join([f'-f {compose_file}' for compose_file in self.compose_files])
|
|
242
|
+
|
|
243
243
|
return self.docker_command(
|
|
244
|
-
command=f'{compose_command}
|
|
244
|
+
command=f'{compose_command} {compose_files} {command}',
|
|
245
245
|
return_output=return_output,
|
|
246
246
|
use_connection=use_connection
|
|
247
247
|
)
|
|
@@ -274,7 +274,7 @@ class AbstractManager(object):
|
|
|
274
274
|
containers = list(filter(None, containers))
|
|
275
275
|
|
|
276
276
|
# get project containers only
|
|
277
|
-
containers = list(filter(lambda c: self.get_container_project(c)
|
|
277
|
+
containers = list(filter(lambda c: self.get_container_project(c) in self.project_services().keys(), containers))
|
|
278
278
|
|
|
279
279
|
# find containers starting with custom prefix
|
|
280
280
|
containers = list(filter(lambda s: s.startswith(prefix), containers))
|
|
@@ -533,7 +533,8 @@ class BaseManager(AbstractManager):
|
|
|
533
533
|
Constructs container name with project prefix for given service
|
|
534
534
|
"""
|
|
535
535
|
suffix = self.get_container_suffix(service)
|
|
536
|
-
|
|
536
|
+
prefix = self.get_project_by_service(service)
|
|
537
|
+
return f'{prefix}{suffix}'.replace('_', '-')
|
|
537
538
|
|
|
538
539
|
def get_service_containers(self, service):
|
|
539
540
|
"""
|
|
@@ -560,7 +561,8 @@ class BaseManager(AbstractManager):
|
|
|
560
561
|
Constructs image name for given service
|
|
561
562
|
"""
|
|
562
563
|
suffix = self.get_image_suffix(service)
|
|
563
|
-
|
|
564
|
+
prefix = self.get_project_by_service(service)
|
|
565
|
+
return f'{prefix}{suffix}'.replace('-', '_')
|
|
564
566
|
|
|
565
567
|
def has_healthcheck(self, container):
|
|
566
568
|
"""
|
|
@@ -678,7 +680,7 @@ class BaseManager(AbstractManager):
|
|
|
678
680
|
image = info['image'] if info['image'] != '' else f"{info['project_name']}-{service}".lstrip('-')
|
|
679
681
|
|
|
680
682
|
# build paths for docker build command (paths in compose are relative to compose file, but paths for docker command are relative to $PWD)
|
|
681
|
-
context = normpath(path.join(dirname(self.
|
|
683
|
+
context = normpath(path.join(dirname(self.compose_path), info['context']))
|
|
682
684
|
dockerfile = normpath(path.join(context, info['dockerfile']))
|
|
683
685
|
|
|
684
686
|
# Build service using docker
|
|
@@ -687,47 +689,73 @@ class BaseManager(AbstractManager):
|
|
|
687
689
|
else:
|
|
688
690
|
CLI.error(f'Unknown build tool: {build_tool}. Available tools: {", ".join(available_tools)}')
|
|
689
691
|
|
|
690
|
-
def
|
|
692
|
+
def project_services(self):
|
|
691
693
|
"""
|
|
692
|
-
Returns project
|
|
694
|
+
Returns project names by compose files
|
|
693
695
|
"""
|
|
694
|
-
|
|
695
|
-
|
|
696
|
+
projects = defaultdict(list)
|
|
697
|
+
|
|
698
|
+
for compose_file in self.compose_files:
|
|
699
|
+
with open(compose_file, 'r') as file:
|
|
700
|
+
compose_data = yaml.safe_load(file)
|
|
701
|
+
name = compose_data.get('name', '')
|
|
702
|
+
services = compose_data.get('services', {}).keys()
|
|
703
|
+
projects[name].extend(services)
|
|
704
|
+
|
|
705
|
+
return projects
|
|
706
|
+
|
|
707
|
+
def get_project_by_service(self, service):
|
|
708
|
+
project_services = self.project_services()
|
|
696
709
|
|
|
697
|
-
|
|
710
|
+
for project, services in project_services.items():
|
|
711
|
+
if service in services:
|
|
712
|
+
return project
|
|
698
713
|
|
|
699
|
-
|
|
714
|
+
return None
|
|
715
|
+
|
|
716
|
+
def services(self, compose_file=None):
|
|
700
717
|
"""
|
|
701
|
-
|
|
718
|
+
Returns all defined services
|
|
702
719
|
"""
|
|
703
|
-
|
|
704
|
-
|
|
720
|
+
services = []
|
|
721
|
+
|
|
722
|
+
compose_files = [compose_file] if compose_file else self.compose_files
|
|
723
|
+
|
|
724
|
+
for compose_file in compose_files:
|
|
725
|
+
with open(compose_file, 'r') as file:
|
|
726
|
+
compose_data = yaml.safe_load(file)
|
|
727
|
+
compose_services = compose_data.get('services', {}).keys()
|
|
705
728
|
|
|
706
|
-
|
|
729
|
+
services += compose_services
|
|
707
730
|
|
|
708
|
-
|
|
731
|
+
return services
|
|
732
|
+
|
|
733
|
+
def services_to_build(self, compose_file=None):
|
|
709
734
|
"""
|
|
710
735
|
Prints all services which will be build
|
|
711
736
|
"""
|
|
712
|
-
with open(self.compose_file, 'r') as file:
|
|
713
|
-
compose_data = yaml.safe_load(file)
|
|
714
|
-
|
|
715
737
|
data = {}
|
|
716
738
|
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
739
|
+
compose_files = [compose_file] if compose_file else self.compose_files
|
|
740
|
+
|
|
741
|
+
for compose_file in compose_files:
|
|
742
|
+
with open(compose_file, 'r') as file:
|
|
743
|
+
compose_data = yaml.safe_load(file)
|
|
744
|
+
|
|
745
|
+
services = compose_data.get('services', {})
|
|
746
|
+
for service_name, service_config in services.items():
|
|
747
|
+
build = service_config.get('build', None)
|
|
748
|
+
|
|
749
|
+
if build:
|
|
750
|
+
data[service_name] = {
|
|
751
|
+
'project_name': compose_data.get('name', ''),
|
|
752
|
+
'dockerfile': build.get('dockerfile', 'Dockerfile'),
|
|
753
|
+
'context': build.get('context', '.'),
|
|
754
|
+
'cache_from': build.get('cache_from', []),
|
|
755
|
+
'args': build.get('args', {}),
|
|
756
|
+
'image': service_config.get('image', ''),
|
|
757
|
+
'platform': service_config.get('platform', '')
|
|
758
|
+
}
|
|
731
759
|
|
|
732
760
|
return data
|
|
733
761
|
|
|
@@ -764,7 +792,7 @@ class BaseManager(AbstractManager):
|
|
|
764
792
|
elif self.mode == 'ssh':
|
|
765
793
|
CLI.info('Uploading docker compose configs, environment files and mantis')
|
|
766
794
|
|
|
767
|
-
files_to_upload = [self.config_file
|
|
795
|
+
files_to_upload = [self.config_file] + self.compose_files + self.env.files
|
|
768
796
|
|
|
769
797
|
# mantis config file
|
|
770
798
|
for file in files_to_upload:
|
|
@@ -1134,10 +1162,15 @@ class BaseManager(AbstractManager):
|
|
|
1134
1162
|
"""
|
|
1135
1163
|
Returns default number of deploy replicas of given services
|
|
1136
1164
|
"""
|
|
1137
|
-
|
|
1138
|
-
compose_data = yaml.safe_load(file)
|
|
1165
|
+
replicas = 1
|
|
1139
1166
|
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1167
|
+
for compose_file in self.compose_files:
|
|
1168
|
+
with open(compose_file, 'r') as file:
|
|
1169
|
+
compose_data = yaml.safe_load(file)
|
|
1170
|
+
|
|
1171
|
+
try:
|
|
1172
|
+
replicas = compose_data['services'][service]['deploy']['replicas']
|
|
1173
|
+
except KeyError:
|
|
1174
|
+
pass
|
|
1175
|
+
|
|
1176
|
+
return replicas
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
VERSION = '18.0.0'
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|