forked from inveniosoftware/invenio-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontainers.py
More file actions
174 lines (150 loc) · 4.66 KB
/
Copy pathcontainers.py
File metadata and controls
174 lines (150 loc) · 4.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# SPDX-FileCopyrightText: 2020 CERN.
# SPDX-FileCopyrightText: 2020 Northwestern University.
# SPDX-License-Identifier: MIT
"""Invenio module to ease the creation and management of applications."""
import click
from ..commands import ContainersCommands
from .services import status as services_status_cmd
from .utils import pass_cli_config, run_steps
@click.group()
def containers():
"""Containers management commands."""
@containers.command()
@click.option(
"--pull/--no-pull",
default=True,
is_flag=True,
help="Download newer versions of the images (default: True).",
)
@click.option(
"--cache/--no-cache",
default=True,
is_flag=True,
help="Disable cache (default=False).",
)
@pass_cli_config
def build(cli_config, pull, cache):
"""Build application and service images."""
commands = ContainersCommands(cli_config)
click.secho(
f"Building images... Pull newer versions {pull}, use cache {cache}", fg="green"
)
steps = commands.build(pull, cache)
on_fail = "Failed to build images."
on_success = "Images built successfully."
run_steps(steps, on_fail, on_success)
@containers.command()
@click.option(
"-f",
"--force",
default=False,
is_flag=True,
help="Force recreation of db tables, search indices, queues...",
)
@click.option(
"-N",
"--no-demo-data",
default=False,
is_flag=True,
help="Disable the creation of demo data",
)
@click.option(
"--stop-services", default=False, is_flag=True, help="Stop containers after setup."
)
@click.option(
"--services/--no-services",
"-s/-n",
default=True,
is_flag=True,
help="Enable/disable dockerized services (default: enabled).",
)
@pass_cli_config
def setup(cli_config, force, no_demo_data, stop_services, services):
"""Setup containerized services."""
# no_demo_data = False (default) means "YES to demo_data"
demo_data = not no_demo_data
commands = ContainersCommands(cli_config)
click.secho(
f"Setting up services with force {force}, demo data {demo_data} "
+ f"and stop after setup {stop_services}...",
fg="green",
)
steps = commands.setup(force, demo_data, stop_services, services)
on_fail = "Failed to setup services."
on_success = "Services setup successfully."
run_steps(steps, on_fail, on_success)
@containers.command()
@click.option(
"-v",
"--verbose",
default=False,
is_flag=True,
required=False,
help="Verbose mode will show all logs in the console.",
)
@click.pass_context
def status(ctx, verbose):
"""Checks if the services are up and running.
NOTE: currently only search (opensearch2), DB (postgresql) and redis are supported.
"""
ctx.invoke(services_status_cmd, verbose=verbose)
@containers.command()
@click.option(
"--lock/--skip-lock",
default=False,
is_flag=True,
help="Lock Python dependencies (default=False).",
)
@click.option(
"--build/--no-build",
default=False,
is_flag=True,
help="Build images (default=False).",
)
@click.option(
"--setup/--no-setup",
default=False,
is_flag=True,
help="Setup services (default=False). " + "It will run with force=True.",
)
@click.option(
"--demo-data/--no-demo-data",
default=True,
is_flag=True,
help="Include demo records (default=True), requires --setup.",
)
@click.option(
"--services/--no-services",
"-s/-n",
default=True,
is_flag=True,
help="Enable/disable dockerized services (default: enabled).",
)
@pass_cli_config
def start(cli_config, lock, build, setup, demo_data, services):
"""Start containerized services and application."""
commands = ContainersCommands(cli_config)
click.secho("Starting InvenioRDM instance...")
steps = commands.start(lock, build, setup, demo_data, services)
on_fail = "Failed to start containerized instance."
on_success = "Instance running!\nVisit https://127.0.0.1"
run_steps(steps, on_fail, on_success)
@containers.command()
@pass_cli_config
def stop(cli_config):
"""Stop containerized services and application."""
commands = ContainersCommands(cli_config)
steps = commands.stop()
on_fail = "Failed to stop containers."
on_success = "Stopped containers."
run_steps(steps, on_fail, on_success)
@containers.command()
@pass_cli_config
def destroy(cli_config):
"""Destroy containerized services and application."""
commands = ContainersCommands(cli_config)
click.secho("Destroying containers, volumes, virtual environment...", fg="green")
steps = commands.destroy()
on_fail = "Failed to destroy instance's containers."
on_success = "Instance' containers destroyed."
run_steps(steps, on_fail, on_success)