mirror of
https://gitlab.sectorq.eu/jaydee/portainer.git
synced 2025-12-14 10:44:52 +01:00
build
This commit is contained in:
30
port.py
30
port.py
@@ -472,18 +472,22 @@ class Portainer:
|
||||
self.stack_name = s.get("Name")
|
||||
self.stack_ids.append(s.get("Id"))
|
||||
return s
|
||||
|
||||
print(ValueError(f"Stack not found: {stack}"))
|
||||
sys.exit(1)
|
||||
RED = "\033[91m"
|
||||
RESET = "\033[0m"
|
||||
print(ValueError(f"{RED}✗{RESET} >> Stack not found: {stack}"))
|
||||
return 1
|
||||
|
||||
def create_stack(
|
||||
self,
|
||||
endpoint,
|
||||
stack=None,
|
||||
stacks=None,
|
||||
mode="git",
|
||||
autostart=False,
|
||||
stack_mode="swarm",
|
||||
):
|
||||
|
||||
|
||||
for stack in stacks:
|
||||
if stack_mode == "swarm":
|
||||
swarm_id = self.get_swarm_id(endpoint)
|
||||
p = "swarm"
|
||||
@@ -500,7 +504,7 @@ class Portainer:
|
||||
Repo.clone_from(self.git_url, self.repo_dir)
|
||||
if mode == "git":
|
||||
path = f"/stacks/create/{p}/repository"
|
||||
print(p)
|
||||
# print(p)
|
||||
if self.endpoint_id is not None:
|
||||
path += f"?endpointId={self.endpoint_id}"
|
||||
|
||||
@@ -526,7 +530,9 @@ class Portainer:
|
||||
or stack in self.stacks_all[self.endpoint_id]["by_name"]
|
||||
)
|
||||
if stack_check:
|
||||
print(f"Stack {stack} already exist")
|
||||
GREEN = "\033[92m"
|
||||
RESET = "\033[0m"
|
||||
print(f"{GREEN}✓{RESET} >> Stack {stack} already exist")
|
||||
continue
|
||||
print(f"Working on {stack} , stack mode: {stack_mode}")
|
||||
|
||||
@@ -613,7 +619,7 @@ class Portainer:
|
||||
try:
|
||||
# print(self.endpoint_id)
|
||||
# print(stack)
|
||||
self.get_stack(stack, self.endpoint_id)
|
||||
if self.get_stack(stack, self.endpoint_id) != 1:
|
||||
created = True
|
||||
break
|
||||
except Exception as e:
|
||||
@@ -852,12 +858,16 @@ class Portainer:
|
||||
self._resolve_endpoint(endpoint_id)
|
||||
endpoint_id = self.endpoint_id
|
||||
|
||||
stack_id = self._resolve_stack_id(stack, endpoint_id)
|
||||
|
||||
|
||||
|
||||
if stack == "all":
|
||||
return self._delete_all_stacks(endpoint_id)
|
||||
|
||||
return self._delete_single_stack(stack_id, endpoint_id)
|
||||
else:
|
||||
for s in stack:
|
||||
stack_id = self._resolve_stack_id(s, endpoint_id)
|
||||
self._delete_single_stack(stack_id, endpoint_id)
|
||||
return "Done"
|
||||
|
||||
# def delete_stack(self, endpoint_id=None, stack=None):
|
||||
# """
|
||||
|
||||
27
portainer.py
27
portainer.py
@@ -141,7 +141,7 @@ parser.add_argument("--gpu", "-g", action="store_true")
|
||||
parser.add_argument("--create-stacks", "-C", action="store_true")
|
||||
parser.add_argument("--refresh-status", "-r", action="store_true")
|
||||
|
||||
parser.add_argument("--stack", "-s", type=str, help="Stack ID for operations")
|
||||
parser.add_argument("--stack", "-s", type=str, nargs="+", help="Stack ID for operations")
|
||||
parser.add_argument(
|
||||
"--token-only", action="store_true", help="Print auth token and exit"
|
||||
)
|
||||
@@ -152,7 +152,6 @@ args = parser.parse_args()
|
||||
print("Running version:", VERSION)
|
||||
print("Environment:", args.site)
|
||||
|
||||
|
||||
if args.site is not None:
|
||||
cur_config["PORTAINER_SITE"] = args.site
|
||||
if args.endpoint_id is not None:
|
||||
@@ -272,12 +271,13 @@ def prompt_missing_args(args_in, defaults_in, fields):
|
||||
)
|
||||
try:
|
||||
if field == "stack":
|
||||
result = checkboxlist_dialog(
|
||||
commands_tuples = [(cmd, cmd) for cmd in commands]
|
||||
value_in = checkboxlist_dialog(
|
||||
title="Select Services",
|
||||
text="Choose one or more services:",
|
||||
values=commands,
|
||||
values=commands_tuples,
|
||||
).run()
|
||||
input(result)
|
||||
print(" >> Stacks :", ",".join(value_in))
|
||||
else:
|
||||
value_in = (
|
||||
prompt(
|
||||
@@ -316,9 +316,14 @@ def prompt_missing_args(args_in, defaults_in, fields):
|
||||
print("Value entered:", value_in)
|
||||
defaults_in[f"PORTAINER_{field}".upper()] = value_in
|
||||
setattr(args, field, value_in)
|
||||
os.environ[field] = value_in
|
||||
|
||||
if field == "site" and value_in != cur_site:
|
||||
por.get_site(value_in)
|
||||
|
||||
if field == "stack" and value_in != cur_site:
|
||||
os.environ[field] = ",".join(value_in)
|
||||
else:
|
||||
os.environ[field] = value_in
|
||||
if por._debug:
|
||||
print(f"{defaults_in} {field} {value_in}")
|
||||
if field == "endpoint_id" and value_in != defaults_in.get(
|
||||
@@ -375,8 +380,14 @@ if __name__ == "__main__":
|
||||
if args.debug:
|
||||
por._debug = True
|
||||
if args.action == "secrets":
|
||||
if args.endpoint_id is None:
|
||||
args.endpoint_id = input("Endpoint ID is required for creating secrets : ")
|
||||
args = prompt_missing_args(
|
||||
args,
|
||||
cur_config,
|
||||
[
|
||||
("site", "Site"),
|
||||
("endpoint_id", "Endpoint ID"),
|
||||
],
|
||||
)
|
||||
|
||||
secrets = {
|
||||
"gitea_runner_registration_token": "8nmKqJhkvYwltmNfF2o9vs0tzo70ufHSQpVg6ymb",
|
||||
|
||||
Reference in New Issue
Block a user