devservices 0.0.2__tar.gz → 0.0.4__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.
- devservices-0.0.4/LICENSE.md +201 -0
- {devservices-0.0.2 → devservices-0.0.4}/PKG-INFO +2 -1
- devservices-0.0.4/README.md +38 -0
- devservices-0.0.4/devservices/commands/check_for_update.py +14 -0
- devservices-0.0.4/devservices/commands/list_services.py +57 -0
- {devservices-0.0.2 → devservices-0.0.4}/devservices/commands/logs.py +7 -12
- {devservices-0.0.2 → devservices-0.0.4}/devservices/commands/start.py +4 -8
- {devservices-0.0.2 → devservices-0.0.4}/devservices/commands/status.py +10 -13
- {devservices-0.0.2 → devservices-0.0.4}/devservices/commands/stop.py +4 -10
- devservices-0.0.4/devservices/commands/update.py +66 -0
- {devservices-0.0.2 → devservices-0.0.4}/devservices/configs/service_config.py +28 -9
- devservices-0.0.4/devservices/constants.py +24 -0
- devservices-0.0.4/devservices/exceptions.py +92 -0
- devservices-0.0.4/devservices/main.py +84 -0
- devservices-0.0.4/devservices/utils/dependencies.py +416 -0
- devservices-0.0.4/devservices/utils/docker_compose.py +291 -0
- devservices-0.0.4/devservices/utils/file_lock.py +24 -0
- devservices-0.0.4/devservices/utils/install_binary.py +52 -0
- {devservices-0.0.2 → devservices-0.0.4}/devservices/utils/services.py +5 -1
- {devservices-0.0.2 → devservices-0.0.4}/devservices.egg-info/PKG-INFO +2 -1
- {devservices-0.0.2 → devservices-0.0.4}/devservices.egg-info/SOURCES.txt +14 -2
- {devservices-0.0.2 → devservices-0.0.4}/devservices.egg-info/top_level.txt +1 -0
- {devservices-0.0.2 → devservices-0.0.4}/pyproject.toml +2 -2
- devservices-0.0.4/testing/utils.py +41 -0
- devservices-0.0.4/tests/commands/test_list_services.py +94 -0
- devservices-0.0.4/tests/commands/test_start.py +123 -0
- devservices-0.0.4/tests/commands/test_stop.py +122 -0
- devservices-0.0.4/tests/commands/test_update.py +101 -0
- {devservices-0.0.2 → devservices-0.0.4}/tests/configs/test_service_config.py +23 -10
- devservices-0.0.4/tests/conftest.py +0 -0
- devservices-0.0.4/tests/utils/test_dependencies.py +1239 -0
- devservices-0.0.4/tests/utils/test_docker_compose.py +482 -0
- devservices-0.0.4/tests/utils/test_install_binary.py +111 -0
- devservices-0.0.2/README.md +0 -1
- devservices-0.0.2/devservices/commands/list_services.py +0 -31
- devservices-0.0.2/devservices/constants.py +0 -4
- devservices-0.0.2/devservices/exceptions.py +0 -41
- devservices-0.0.2/devservices/main.py +0 -57
- devservices-0.0.2/devservices/utils/docker_compose.py +0 -18
- devservices-0.0.2/tests/commands/test_start.py +0 -97
- devservices-0.0.2/tests/commands/test_stop.py +0 -97
- devservices-0.0.2/tests/testutils.py +0 -15
- {devservices-0.0.2 → devservices-0.0.4}/devservices/__init__.py +0 -0
- {devservices-0.0.2 → devservices-0.0.4}/devservices/commands/__init__.py +0 -0
- {devservices-0.0.2 → devservices-0.0.4}/devservices/commands/list_dependencies.py +0 -0
- {devservices-0.0.2 → devservices-0.0.4}/devservices/utils/__init__.py +0 -0
- {devservices-0.0.2 → devservices-0.0.4}/devservices/utils/console.py +0 -0
- {devservices-0.0.2 → devservices-0.0.4}/devservices/utils/devenv.py +0 -0
- {devservices-0.0.2 → devservices-0.0.4}/devservices.egg-info/dependency_links.txt +0 -0
- {devservices-0.0.2 → devservices-0.0.4}/devservices.egg-info/entry_points.txt +0 -0
- {devservices-0.0.2 → devservices-0.0.4}/devservices.egg-info/requires.txt +0 -0
- {devservices-0.0.2 → devservices-0.0.4}/setup.cfg +0 -0
- {devservices-0.0.2/tests → devservices-0.0.4/testing}/__init__.py +0 -0
- /devservices-0.0.2/tests/conftest.py → /devservices-0.0.4/tests/__init__.py +0 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# devservices
|
|
2
|
+
|
|
3
|
+
A standalone cli tool used to manage dependencies for services. It simplifies the process of starting, stopping, and managing services for development purposes.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
`devservices` reads configuration files located in the `devservices` directory of your repository. These configurations define services, their dependencies, and various modes of operation.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
A system-wide installation can be done by downloading the binary of the latest release
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
PLATFORM=darwin # Options: darwin/linux
|
|
15
|
+
INSTALL_DIR="$HOME/.local/bin"
|
|
16
|
+
curl -L "https://github.com/getsentry/devservices/releases/download/0.0.4/devservices-$PLATFORM" -o "$INSTALL_DIR/devservices"
|
|
17
|
+
chmod +x "$INSTALL_DIR/devservices"
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Alternatively, if the repository you're working in has a python virtualenv, you can simply add this to the requirements-dev.txt:
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
devservices==0.0.4
|
|
24
|
+
```
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
devservices provides several commands to manage your services:
|
|
28
|
+
|
|
29
|
+
### Commands
|
|
30
|
+
|
|
31
|
+
NOTE: service-name is an optional parameter. If not provided, devservices will attempt to automatically find a devservices configuration in the current directory in order to proceed.
|
|
32
|
+
|
|
33
|
+
- `devservices start <service-name>`: Start a service and its dependencies.
|
|
34
|
+
- `devservices stop <service-name>`: Stop a service including its dependencies.
|
|
35
|
+
- `devservices status <service-name>`: Display the current status of all services, including their dependencies and ports.
|
|
36
|
+
- `devservices logs <service-name>`: View logs for a specific service.
|
|
37
|
+
- `devservices list-services`: List all available Sentry services.
|
|
38
|
+
- `devservices list-dependencies <service-name>`: List all dependencies for a service and whether they are enabled/disabled.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from urllib.request import urlopen
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def check_for_update(current_version: str) -> str | None:
|
|
8
|
+
url = "https://api.github.com/repos/getsentry/devservices/releases/latest"
|
|
9
|
+
with urlopen(url) as response:
|
|
10
|
+
if response.status == 200:
|
|
11
|
+
data = json.loads(response.read().decode("utf-8"))
|
|
12
|
+
latest_version = str(data["tag_name"])
|
|
13
|
+
return latest_version
|
|
14
|
+
return None
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from argparse import _SubParsersAction
|
|
4
|
+
from argparse import ArgumentParser
|
|
5
|
+
from argparse import Namespace
|
|
6
|
+
|
|
7
|
+
from devservices.utils.devenv import get_coderoot
|
|
8
|
+
from devservices.utils.docker_compose import get_active_docker_compose_projects
|
|
9
|
+
from devservices.utils.services import get_local_services
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def add_parser(subparsers: _SubParsersAction[ArgumentParser]) -> None:
|
|
13
|
+
parser = subparsers.add_parser(
|
|
14
|
+
"list-services", help="List the services installed locally", aliases=["ls"]
|
|
15
|
+
)
|
|
16
|
+
parser.add_argument(
|
|
17
|
+
"-a",
|
|
18
|
+
"--all",
|
|
19
|
+
action="store_true",
|
|
20
|
+
help="Show all services, including stopped ones",
|
|
21
|
+
)
|
|
22
|
+
parser.set_defaults(func=list_services)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def list_services(args: Namespace) -> None:
|
|
26
|
+
"""List the services installed locally."""
|
|
27
|
+
|
|
28
|
+
# Get all of the services installed locally
|
|
29
|
+
coderoot = get_coderoot()
|
|
30
|
+
services = get_local_services(coderoot)
|
|
31
|
+
running_projects = get_active_docker_compose_projects()
|
|
32
|
+
|
|
33
|
+
if not services:
|
|
34
|
+
print("No services found")
|
|
35
|
+
return
|
|
36
|
+
|
|
37
|
+
services_to_show = (
|
|
38
|
+
services if args.all else [s for s in services if s.name in running_projects]
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
if args.all:
|
|
42
|
+
print("Services installed locally:")
|
|
43
|
+
else:
|
|
44
|
+
print("Running services:")
|
|
45
|
+
|
|
46
|
+
for service in services_to_show:
|
|
47
|
+
status = "running" if service.name in running_projects else "stopped"
|
|
48
|
+
print(f"- {service.name}")
|
|
49
|
+
print(f" status: {status}")
|
|
50
|
+
print(f" location: {service.repo_path}")
|
|
51
|
+
|
|
52
|
+
if not args.all:
|
|
53
|
+
stopped_count = len(services) - len(services_to_show)
|
|
54
|
+
if stopped_count > 0:
|
|
55
|
+
print(
|
|
56
|
+
f"\n{stopped_count} stopped service(s) not shown. Use --all/-a to see them."
|
|
57
|
+
)
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
import os
|
|
4
3
|
import sys
|
|
5
4
|
from argparse import _SubParsersAction
|
|
6
5
|
from argparse import ArgumentParser
|
|
7
6
|
from argparse import Namespace
|
|
8
7
|
|
|
9
|
-
from devservices.constants import DEVSERVICES_DIR_NAME
|
|
10
|
-
from devservices.constants import DOCKER_COMPOSE_FILE_NAME
|
|
11
8
|
from devservices.exceptions import DockerComposeError
|
|
12
9
|
from devservices.utils.docker_compose import run_docker_compose_command
|
|
13
10
|
from devservices.utils.services import find_matching_service
|
|
@@ -32,19 +29,17 @@ def logs(args: Namespace) -> None:
|
|
|
32
29
|
except Exception as e:
|
|
33
30
|
print(e)
|
|
34
31
|
exit(1)
|
|
32
|
+
|
|
35
33
|
modes = service.config.modes
|
|
36
34
|
# TODO: allow custom modes to be used
|
|
37
35
|
mode_to_use = "default"
|
|
38
|
-
mode_dependencies =
|
|
39
|
-
|
|
40
|
-
service.repo_path, DEVSERVICES_DIR_NAME, DOCKER_COMPOSE_FILE_NAME
|
|
41
|
-
)
|
|
36
|
+
mode_dependencies = modes[mode_to_use]
|
|
37
|
+
|
|
42
38
|
try:
|
|
43
|
-
logs = run_docker_compose_command(
|
|
44
|
-
f"-f {service_config_file_path} logs {mode_dependencies}"
|
|
45
|
-
)
|
|
39
|
+
logs = run_docker_compose_command(service, "logs", mode_dependencies)
|
|
46
40
|
except DockerComposeError as dce:
|
|
47
41
|
print(f"Failed to get logs for {service.name}: {dce.stderr}")
|
|
48
42
|
exit(1)
|
|
49
|
-
|
|
50
|
-
|
|
43
|
+
for log in logs:
|
|
44
|
+
sys.stdout.write(log.stdout)
|
|
45
|
+
sys.stdout.flush()
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
import os
|
|
4
3
|
from argparse import _SubParsersAction
|
|
5
4
|
from argparse import ArgumentParser
|
|
6
5
|
from argparse import Namespace
|
|
7
6
|
|
|
8
|
-
from devservices.constants import DEVSERVICES_DIR_NAME
|
|
9
|
-
from devservices.constants import DOCKER_COMPOSE_FILE_NAME
|
|
10
7
|
from devservices.exceptions import DockerComposeError
|
|
11
8
|
from devservices.utils.console import Status
|
|
12
9
|
from devservices.utils.docker_compose import run_docker_compose_command
|
|
@@ -29,17 +26,16 @@ def start(args: Namespace) -> None:
|
|
|
29
26
|
except Exception as e:
|
|
30
27
|
print(e)
|
|
31
28
|
exit(1)
|
|
29
|
+
|
|
32
30
|
modes = service.config.modes
|
|
33
31
|
# TODO: allow custom modes to be used
|
|
34
32
|
mode_to_start = "default"
|
|
35
|
-
mode_dependencies =
|
|
36
|
-
|
|
37
|
-
service.repo_path, DEVSERVICES_DIR_NAME, DOCKER_COMPOSE_FILE_NAME
|
|
38
|
-
)
|
|
33
|
+
mode_dependencies = modes[mode_to_start]
|
|
34
|
+
|
|
39
35
|
with Status(f"Starting {service.name}", f"{service.name} started") as status:
|
|
40
36
|
try:
|
|
41
37
|
run_docker_compose_command(
|
|
42
|
-
|
|
38
|
+
service, "up", mode_dependencies, ["-d"], force_update_dependencies=True
|
|
43
39
|
)
|
|
44
40
|
except DockerComposeError as dce:
|
|
45
41
|
status.print(f"Failed to start {service.name}: {dce.stderr}")
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
import json
|
|
4
|
-
import os
|
|
5
4
|
import sys
|
|
6
5
|
from argparse import _SubParsersAction
|
|
7
6
|
from argparse import ArgumentParser
|
|
8
7
|
from argparse import Namespace
|
|
9
8
|
|
|
10
|
-
from devservices.constants import DEVSERVICES_DIR_NAME
|
|
11
|
-
from devservices.constants import DOCKER_COMPOSE_FILE_NAME
|
|
12
9
|
from devservices.exceptions import DockerComposeError
|
|
13
10
|
from devservices.utils.docker_compose import run_docker_compose_command
|
|
14
11
|
from devservices.utils.services import find_matching_service
|
|
@@ -49,7 +46,7 @@ def format_status_output(status_json: str) -> str:
|
|
|
49
46
|
output.append("Ports:")
|
|
50
47
|
for port in ports:
|
|
51
48
|
output.append(
|
|
52
|
-
f" {port['PublishedPort']} -> {port['TargetPort']}/{port['Protocol']}"
|
|
49
|
+
f" {port['URL']}:{port['PublishedPort']} -> {port['TargetPort']}/{port['Protocol']}"
|
|
53
50
|
)
|
|
54
51
|
else:
|
|
55
52
|
output.append("No ports exposed")
|
|
@@ -67,26 +64,26 @@ def status(args: Namespace) -> None:
|
|
|
67
64
|
except Exception as e:
|
|
68
65
|
print(e)
|
|
69
66
|
exit(1)
|
|
67
|
+
|
|
70
68
|
modes = service.config.modes
|
|
71
69
|
# TODO: allow custom modes to be used
|
|
72
70
|
mode_to_view = "default"
|
|
73
|
-
mode_dependencies =
|
|
74
|
-
|
|
75
|
-
service.repo_path, DEVSERVICES_DIR_NAME, DOCKER_COMPOSE_FILE_NAME
|
|
76
|
-
)
|
|
71
|
+
mode_dependencies = modes[mode_to_view]
|
|
72
|
+
|
|
77
73
|
try:
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
)
|
|
74
|
+
status_jsons = run_docker_compose_command(
|
|
75
|
+
service, "ps", mode_dependencies, options=["--format", "json"]
|
|
76
|
+
)
|
|
81
77
|
except DockerComposeError as dce:
|
|
82
78
|
print(f"Failed to get status for {service.name}: {dce.stderr}")
|
|
83
79
|
exit(1)
|
|
84
80
|
# If the service is not running, the status_json will be empty
|
|
85
|
-
if
|
|
81
|
+
if len(status_jsons) == 0:
|
|
86
82
|
print(f"{service.name} is not running")
|
|
87
83
|
return
|
|
88
84
|
output = f"Service: {service.name}\n\n"
|
|
89
|
-
|
|
85
|
+
for status_json in status_jsons:
|
|
86
|
+
output += format_status_output(status_json.stdout)
|
|
90
87
|
output += "=" * LINE_LENGTH
|
|
91
88
|
sys.stdout.write(output + "\n")
|
|
92
89
|
sys.stdout.flush()
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
import os
|
|
4
3
|
from argparse import _SubParsersAction
|
|
5
4
|
from argparse import ArgumentParser
|
|
6
5
|
from argparse import Namespace
|
|
7
6
|
|
|
8
|
-
from devservices.constants import DEVSERVICES_DIR_NAME
|
|
9
|
-
from devservices.constants import DOCKER_COMPOSE_FILE_NAME
|
|
10
7
|
from devservices.exceptions import DockerComposeError
|
|
11
8
|
from devservices.utils.console import Status
|
|
12
9
|
from devservices.utils.docker_compose import run_docker_compose_command
|
|
@@ -29,18 +26,15 @@ def stop(args: Namespace) -> None:
|
|
|
29
26
|
except Exception as e:
|
|
30
27
|
print(e)
|
|
31
28
|
exit(1)
|
|
29
|
+
|
|
32
30
|
modes = service.config.modes
|
|
33
31
|
# TODO: allow custom modes to be used
|
|
34
32
|
mode_to_stop = "default"
|
|
35
|
-
mode_dependencies =
|
|
36
|
-
|
|
37
|
-
service.repo_path, DEVSERVICES_DIR_NAME, DOCKER_COMPOSE_FILE_NAME
|
|
38
|
-
)
|
|
33
|
+
mode_dependencies = modes[mode_to_stop]
|
|
34
|
+
|
|
39
35
|
with Status(f"Stopping {service.name}", f"{service.name} stopped") as status:
|
|
40
36
|
try:
|
|
41
|
-
run_docker_compose_command(
|
|
42
|
-
f"-f {service_config_file_path} down {mode_dependencies}"
|
|
43
|
-
)
|
|
37
|
+
run_docker_compose_command(service, "down", mode_dependencies)
|
|
44
38
|
except DockerComposeError as dce:
|
|
45
39
|
status.print(f"Failed to stop {service.name}: {dce.stderr}")
|
|
46
40
|
exit(1)
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import platform
|
|
4
|
+
import sys
|
|
5
|
+
from argparse import _SubParsersAction
|
|
6
|
+
from argparse import ArgumentParser
|
|
7
|
+
from argparse import Namespace
|
|
8
|
+
from importlib import metadata
|
|
9
|
+
|
|
10
|
+
from devservices.commands.check_for_update import check_for_update
|
|
11
|
+
from devservices.constants import DEVSERVICES_DOWNLOAD_URL
|
|
12
|
+
from devservices.exceptions import BinaryInstallError
|
|
13
|
+
from devservices.exceptions import DevservicesUpdateError
|
|
14
|
+
from devservices.utils.install_binary import install_binary
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def is_in_virtualenv() -> bool:
|
|
18
|
+
return hasattr(sys, "real_prefix") or (
|
|
19
|
+
hasattr(sys, "base_prefix") and sys.base_prefix != sys.prefix
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def update_version(exec_path: str, latest_version: str) -> None:
|
|
24
|
+
system = platform.system().lower()
|
|
25
|
+
url = f"{DEVSERVICES_DOWNLOAD_URL}/{latest_version}/devservices-{system}"
|
|
26
|
+
try:
|
|
27
|
+
install_binary("devservices", exec_path, latest_version, url)
|
|
28
|
+
except BinaryInstallError as e:
|
|
29
|
+
raise DevservicesUpdateError(f"Failed to update devservices: {e}")
|
|
30
|
+
|
|
31
|
+
print(f"Devservices {latest_version} updated successfully")
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def add_parser(subparsers: _SubParsersAction[ArgumentParser]) -> None:
|
|
35
|
+
parser = subparsers.add_parser(
|
|
36
|
+
"update", help="update devservices to the latest version"
|
|
37
|
+
)
|
|
38
|
+
parser.set_defaults(func=update)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def update(args: Namespace) -> None:
|
|
42
|
+
current_version = metadata.version("devservices")
|
|
43
|
+
latest_version = check_for_update(current_version)
|
|
44
|
+
|
|
45
|
+
if latest_version is None:
|
|
46
|
+
raise DevservicesUpdateError("Failed to check for updates.")
|
|
47
|
+
|
|
48
|
+
if latest_version == current_version:
|
|
49
|
+
print("You're already on the latest version.")
|
|
50
|
+
return
|
|
51
|
+
|
|
52
|
+
print(f"A new version of devservices is available: {latest_version}")
|
|
53
|
+
|
|
54
|
+
if is_in_virtualenv():
|
|
55
|
+
print("You are running in a virtual environment.")
|
|
56
|
+
print(
|
|
57
|
+
"To update, please update your requirements.txt or requirements-dev.txt file with the new version."
|
|
58
|
+
)
|
|
59
|
+
print(
|
|
60
|
+
f"For example, update the line in requirements.txt to: devservices=={latest_version}"
|
|
61
|
+
)
|
|
62
|
+
print("Then, run: pip install --update -r requirements.txt")
|
|
63
|
+
return
|
|
64
|
+
|
|
65
|
+
print("Upgrading to the latest version...")
|
|
66
|
+
update_version(sys.executable, latest_version)
|
|
@@ -2,11 +2,12 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import os
|
|
4
4
|
from dataclasses import dataclass
|
|
5
|
+
from dataclasses import fields
|
|
5
6
|
|
|
6
7
|
import yaml
|
|
7
8
|
|
|
9
|
+
from devservices.constants import CONFIG_FILE_NAME
|
|
8
10
|
from devservices.constants import DEVSERVICES_DIR_NAME
|
|
9
|
-
from devservices.constants import DOCKER_COMPOSE_FILE_NAME
|
|
10
11
|
from devservices.exceptions import ConfigNotFoundError
|
|
11
12
|
from devservices.exceptions import ConfigParseError
|
|
12
13
|
from devservices.exceptions import ConfigValidationError
|
|
@@ -14,10 +15,18 @@ from devservices.exceptions import ConfigValidationError
|
|
|
14
15
|
VALID_VERSIONS = [0.1]
|
|
15
16
|
|
|
16
17
|
|
|
18
|
+
@dataclass
|
|
19
|
+
class RemoteConfig:
|
|
20
|
+
repo_name: str
|
|
21
|
+
branch: str
|
|
22
|
+
repo_link: str
|
|
23
|
+
mode: str = "default"
|
|
24
|
+
|
|
25
|
+
|
|
17
26
|
@dataclass
|
|
18
27
|
class Dependency:
|
|
19
28
|
description: str
|
|
20
|
-
|
|
29
|
+
remote: RemoteConfig | None = None
|
|
21
30
|
|
|
22
31
|
|
|
23
32
|
@dataclass
|
|
@@ -56,9 +65,7 @@ class ServiceConfig:
|
|
|
56
65
|
|
|
57
66
|
|
|
58
67
|
def load_service_config_from_file(repo_path: str) -> ServiceConfig:
|
|
59
|
-
config_path = os.path.join(
|
|
60
|
-
repo_path, DEVSERVICES_DIR_NAME, DOCKER_COMPOSE_FILE_NAME
|
|
61
|
-
)
|
|
68
|
+
config_path = os.path.join(repo_path, DEVSERVICES_DIR_NAME, CONFIG_FILE_NAME)
|
|
62
69
|
if not os.path.exists(config_path):
|
|
63
70
|
raise ConfigNotFoundError(f"Config file not found in directory: {config_path}")
|
|
64
71
|
with open(config_path, "r") as stream:
|
|
@@ -75,11 +82,23 @@ def load_service_config_from_file(repo_path: str) -> ServiceConfig:
|
|
|
75
82
|
)
|
|
76
83
|
service_config_data = config.get("x-sentry-service-config")
|
|
77
84
|
|
|
85
|
+
valid_dependency_keys = {field.name for field in fields(Dependency)}
|
|
86
|
+
|
|
87
|
+
dependencies = {}
|
|
88
|
+
|
|
78
89
|
try:
|
|
79
|
-
dependencies
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
90
|
+
for key, value in service_config_data.get("dependencies", {}).items():
|
|
91
|
+
unexpected_keys = set(value.keys()) - valid_dependency_keys
|
|
92
|
+
if unexpected_keys:
|
|
93
|
+
raise ConfigParseError(
|
|
94
|
+
f"Unexpected key(s) in dependency '{key}': {unexpected_keys}"
|
|
95
|
+
)
|
|
96
|
+
dependencies[key] = Dependency(
|
|
97
|
+
description=value.get("description"),
|
|
98
|
+
remote=RemoteConfig(**value.get("remote"))
|
|
99
|
+
if "remote" in value
|
|
100
|
+
else None,
|
|
101
|
+
)
|
|
83
102
|
except TypeError as type_error:
|
|
84
103
|
raise ConfigParseError(
|
|
85
104
|
f"Error parsing service dependencies: {type_error}"
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
|
|
5
|
+
MINIMUM_DOCKER_COMPOSE_VERSION = "2.29.7"
|
|
6
|
+
DEVSERVICES_DIR_NAME = "devservices"
|
|
7
|
+
CONFIG_FILE_NAME = "config.yml"
|
|
8
|
+
DOCKER_USER_PLUGIN_DIR = os.path.expanduser("~/.docker/cli-plugins/")
|
|
9
|
+
|
|
10
|
+
DEVSERVICES_CACHE_DIR = os.path.expanduser("~/.cache/sentry-devservices")
|
|
11
|
+
DEVSERVICES_LOCAL_DIR = os.path.expanduser("~/.local/share/sentry-devservices")
|
|
12
|
+
DEVSERVICES_DEPENDENCIES_CACHE_DIR = os.path.join(DEVSERVICES_CACHE_DIR, "dependencies")
|
|
13
|
+
DEVSERVICES_DEPENDENCIES_CACHE_DIR_KEY = "DEVSERVICES_DEPENDENCIES_CACHE_DIR"
|
|
14
|
+
|
|
15
|
+
DEPENDENCY_CONFIG_VERSION = "v1"
|
|
16
|
+
DEPENDENCY_GIT_PARTIAL_CLONE_CONFIG_OPTIONS = {
|
|
17
|
+
"protocol.version": "2",
|
|
18
|
+
"extensions.partialClone": "true",
|
|
19
|
+
"core.sparseCheckout": "true",
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
DOCKER_COMPOSE_DOWNLOAD_URL = "https://github.com/docker/compose/releases/download"
|
|
23
|
+
DEVSERVICES_DOWNLOAD_URL = "https://github.com/getsentry/devservices/releases/download"
|
|
24
|
+
BINARY_PERMISSIONS = 0o755
|