buildah-wrapper 0.0.0.1__py3-none-any.whl

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.
@@ -0,0 +1 @@
1
+ # __init__.py
@@ -0,0 +1,278 @@
1
+ import os
2
+ import argparse
3
+ import yaml
4
+ import subprocess
5
+ from collections import defaultdict
6
+ from concurrent.futures import ThreadPoolExecutor, as_completed
7
+ import logging
8
+ import sys
9
+
10
+ # Script version
11
+ SCRIPT_VERSION = "0.0.0.1"
12
+
13
+ # ASCII art for Buildah Wrapper
14
+ ASCII_ART = r"""
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
+ def setup_logging():
49
+ logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
50
+
51
+ def parse_args():
52
+ parser = argparse.ArgumentParser(description="Buildah Wrapper", add_help=False)
53
+ parser.add_argument('--compose-file', default=os.getenv('COMPOSE_FILE', 'docker-compose.yml'), help='Path to docker-compose.yml file')
54
+ parser.add_argument('--version', '-v', action='store_true', help='Show script version')
55
+ parser.add_argument('--help', '-h', action='store_true', help='Show this help message and exit')
56
+
57
+ # Aliases --build, --deploy и --clean
58
+ parser.add_argument('--build', action='store_true', help='Build images using Buildah')
59
+ parser.add_argument('--deploy', action='store_true', help='Deploy images using Buildah')
60
+ parser.add_argument('--clean', action='store_true', help='Clean all Buildah containers and images')
61
+
62
+ # Subcommands build, deploy и clean
63
+ subparsers = parser.add_subparsers(dest='command', help='Available commands')
64
+ build_parser = subparsers.add_parser('build', help='Build images using Buildah')
65
+ build_parser.add_argument('--no-cache', action='store_true', help='Disable cache during build')
66
+
67
+ deploy_parser = subparsers.add_parser('deploy', help='Deploy images using Buildah')
68
+
69
+ clean_parser = subparsers.add_parser('clean', help='Clean all Buildah containers and images')
70
+
71
+ return parser.parse_args()
72
+
73
+ def load_compose_file(file_path):
74
+ with open(file_path, 'r') as file:
75
+ return yaml.safe_load(file)
76
+
77
+ def build_with_buildah(service_name, build_context, dockerfile, image_name, no_cache):
78
+ buildah_command = [
79
+ 'buildah', 'build',
80
+ '--format', 'docker',
81
+ '--no-cache' if no_cache else '',
82
+ '--rm',
83
+ '--layers=false',
84
+ '-f', f'{build_context}/{dockerfile}',
85
+ '-t', image_name,
86
+ build_context
87
+ ]
88
+
89
+ # Remove empty strings from the command list
90
+ buildah_command = [arg for arg in buildah_command if arg]
91
+
92
+ logging.info(f"Building {service_name} with Buildah: {' '.join(buildah_command)}")
93
+
94
+ process = subprocess.Popen(buildah_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
95
+
96
+ # Stream output in real-time
97
+ for line in process.stdout:
98
+ logging.info(line.strip())
99
+
100
+ process.wait()
101
+
102
+ if process.returncode == 0:
103
+ logging.info(f"Successfully built {service_name}")
104
+ else:
105
+ for line in process.stderr:
106
+ logging.error(line.strip())
107
+ logging.error(f"Error building {service_name}")
108
+ raise Exception(f"Failed to build {service_name}")
109
+
110
+ def deploy_with_buildah(image_name):
111
+ buildah_command = [
112
+ 'buildah', 'push',
113
+ image_name
114
+ ]
115
+
116
+ logging.info(f"Deploying {image_name} with Buildah: {' '.join(buildah_command)}")
117
+
118
+ process = subprocess.Popen(buildah_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
119
+
120
+ # Stream output in real-time
121
+ for line in process.stdout:
122
+ logging.info(line.strip())
123
+
124
+ process.wait()
125
+
126
+ if process.returncode == 0:
127
+ logging.info(f"Successfully deployed {image_name}")
128
+ else:
129
+ for line in process.stderr:
130
+ logging.error(line.strip())
131
+ logging.error(f"Error deploying {image_name}")
132
+ raise Exception(f"Failed to deploy {image_name}")
133
+
134
+ def clean_buildah():
135
+ # RM containers and images
136
+ rm_command = ['buildah', 'rm', '--all']
137
+ logging.info(f"Cleaning Buildah containers: {' '.join(rm_command)}")
138
+
139
+ rm_process = subprocess.Popen(rm_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
140
+ for line in rm_process.stdout:
141
+ logging.info(line.strip())
142
+ rm_process.wait()
143
+
144
+ if rm_process.returncode != 0:
145
+ for line in rm_process.stderr:
146
+ logging.error(line.strip())
147
+ logging.error("Error cleaning Buildah containers")
148
+ raise Exception("Failed to clean Buildah containers")
149
+
150
+ # Удаляем все образы
151
+ rmi_command = ['buildah', 'rmi', '--all']
152
+ logging.info(f"Cleaning Buildah images: {' '.join(rmi_command)}")
153
+
154
+ rmi_process = subprocess.Popen(rmi_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
155
+ for line in rmi_process.stdout:
156
+ logging.info(line.strip())
157
+ rmi_process.wait()
158
+
159
+ if rmi_process.returncode != 0:
160
+ for line in rmi_process.stderr:
161
+ logging.error(line.strip())
162
+ logging.error("Error cleaning Buildah images")
163
+ raise Exception("Failed to clean Buildah images")
164
+
165
+ logging.info("Successfully cleaned all Buildah containers and images")
166
+
167
+ def show_help():
168
+ print(ASCII_ART)
169
+ print("Buildah Wrapper\n")
170
+ print("Arguments:")
171
+ print("--compose-file Path to docker-compose.yml file")
172
+ print("--version, -v Show script version")
173
+ print("--help, -h Show this help message and exit")
174
+ print("\nCommands:")
175
+ print("build, --build Build images using Buildah")
176
+ print("deploy, --deploy Deploy images using Buildah")
177
+ print("clean, --clean Clean all Buildah containers and images")
178
+
179
+ def show_version():
180
+ print(ASCII_ART)
181
+ print(f"Buildah Wrapper {SCRIPT_VERSION}, Python: {sys.version}")
182
+
183
+ def main():
184
+ setup_logging()
185
+
186
+ args = parse_args()
187
+
188
+ # Show help and exit if --help is provided
189
+ if args.help:
190
+ show_help()
191
+ return
192
+
193
+ # Show version and exit if --version or no relevant arguments are provided
194
+ if args.version or not (args.build or args.deploy or args.clean or args.command):
195
+ show_version()
196
+ return
197
+
198
+ # Cleaup if selected this arg
199
+ if args.clean or args.command == 'clean':
200
+ try:
201
+ clean_buildah()
202
+ except Exception as exc:
203
+ logging.error(f"Clean failed: {exc}")
204
+ sys.exit(1)
205
+ return
206
+
207
+ compose_file = args.compose_file
208
+
209
+ if not os.path.exists(compose_file):
210
+ logging.error(f"{compose_file} not found")
211
+ return
212
+
213
+ compose_data = load_compose_file(compose_file)
214
+
215
+ services = compose_data.get('services', {})
216
+ image_names = defaultdict(int)
217
+
218
+ for service_name, service_data in services.items():
219
+ image_name = service_data.get('image')
220
+
221
+ if not image_name:
222
+ logging.warning(f"No image specified for service {service_name}")
223
+ continue
224
+
225
+ image_names[image_name] += 1
226
+
227
+ for image_name, count in image_names.items():
228
+ if count > 1:
229
+ logging.error(f"Error: Image name {image_name} is used {count} times.")
230
+ return
231
+
232
+ try:
233
+ # Determine which command is selected: via a subcommand or an alias
234
+ command = args.command
235
+ if args.build:
236
+ command = 'build'
237
+ elif args.deploy:
238
+ command = 'deploy'
239
+
240
+ if command == 'build':
241
+ with ThreadPoolExecutor() as executor:
242
+ futures = []
243
+ for service_name, service_data in services.items():
244
+ build_data = service_data.get('build', {})
245
+ build_context = build_data.get('context', '.')
246
+ dockerfile = build_data.get('dockerfile', 'Dockerfile')
247
+ image_name = service_data.get('image')
248
+
249
+ if not image_name:
250
+ logging.warning(f"No image specified for service {service_name}")
251
+ continue
252
+
253
+ futures.append(executor.submit(build_with_buildah, service_name, build_context, dockerfile, image_name, args.no_cache))
254
+
255
+ for future in as_completed(futures):
256
+ future.result()
257
+
258
+ elif command == 'deploy':
259
+ with ThreadPoolExecutor() as executor:
260
+ futures = []
261
+ for service_name, service_data in services.items():
262
+ image_name = service_data.get('image')
263
+
264
+ if not image_name:
265
+ logging.warning(f"No image specified for service {service_name}")
266
+ continue
267
+
268
+ futures.append(executor.submit(deploy_with_buildah, image_name))
269
+
270
+ for future in as_completed(futures):
271
+ future.result()
272
+
273
+ except Exception as exc:
274
+ logging.error(f"Operation failed: {exc}")
275
+ sys.exit(1)
276
+
277
+ if __name__ == '__main__':
278
+ main()
@@ -0,0 +1,97 @@
1
+ Metadata-Version: 2.4
2
+ Name: buildah-wrapper
3
+ Version: 0.0.0.1
4
+ Summary: EpicMorg: Buildah-Compose Wrapper - CLI wrapper for buildah build system
5
+ Project-URL: Homepage, https://github.com/EpicMorg/buildah-wrapper
6
+ Project-URL: Documentation, https://github.com/EpicMorg/buildah-wrapper/blob/master/README.md
7
+ Project-URL: Repository, https://github.com/EpicMorg/buildah-wrapper.git
8
+ Project-URL: Bug Tracker, https://github.com/EpicMorg/buildah-wrapper/issues
9
+ Project-URL: Changelog, https://github.com/EpicMorg/buildah-wrapper/blob/master/CHANGELOG.md
10
+ Author-email: EpicMorg <developer@epicm.org>
11
+ Maintainer-email: EpicMorg <developer@epicm.org>
12
+ License: MIT License
13
+
14
+ Copyright (c) EpicMorg
15
+
16
+ Permission is hereby granted, free of charge, to any person obtaining a copy
17
+ of this software and associated documentation files (the "Software"), to deal
18
+ in the Software without restriction, including without limitation the rights
19
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
20
+ copies of the Software, and to permit persons to whom the Software is
21
+ furnished to do so, subject to the following conditions:
22
+
23
+ The above copyright notice and this permission notice shall be included in all
24
+ copies or substantial portions of the Software.
25
+
26
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32
+ SOFTWARE.
33
+ License-File: LICENSE
34
+ Keywords: build,buildah,docker
35
+ Classifier: License :: OSI Approved :: MIT License
36
+ Classifier: Operating System :: Unix
37
+ Classifier: Programming Language :: Python :: 3
38
+ Requires-Python: >=3.6
39
+ Requires-Dist: python-dotenv
40
+ Requires-Dist: pyyaml
41
+ Description-Content-Type: text/markdown
42
+
43
+ # [![Activity](https://img.shields.io/github/commit-activity/m/EpicMorg/buildah-wrapper?label=commits&style=flat-square)](https://github.com/EpicMorg/buildah-wrapper/commits) [![GitHub issues](https://img.shields.io/github/issues/EpicMorg/buildah-wrapper.svg?style=popout-square)](https://github.com/EpicMorg/buildah-wrapper/issues) [![GitHub forks](https://img.shields.io/github/forks/EpicMorg/buildah-wrapper.svg?style=popout-square)](https://github.com/EpicMorg/buildah-wrapper/network) [![GitHub stars](https://img.shields.io/github/stars/EpicMorg/buildah-wrapper.svg?style=popout-square)](https://github.com/EpicMorg/buildah-wrapper/stargazers) [![Size](https://img.shields.io/github/repo-size/EpicMorg/buildah-wrapper?label=size&style=flat-square)](https://github.com/EpicMorg/buildah-wrapper/archive/master.zip) [![Release](https://img.shields.io/github/v/release/EpicMorg/buildah-wrapper?style=flat-square)](https://github.com/EpicMorg/buildah-wrapper/releases) [![GitHub license](https://img.shields.io/github/license/EpicMorg/buildah-wrapper.svg?style=popout-square)](LICENSE.md) [![Changelog](https://img.shields.io/badge/Changelog-yellow.svg?style=popout-square)](CHANGELOG.md) [![PyPI - Downloads](https://img.shields.io/pypi/dm/buildah-wrapper?style=flat-square)](https://pypi.org/project/buildah-wrapper/)
44
+
45
+ ## Description
46
+ Python wrapper for run kaniko from shell with parameters from `docker-compose.yml` file.
47
+
48
+ ## Motivation
49
+ 1. You have Docker project thar contains:
50
+ 1.1 `docker-compose.yml` - as build manifest
51
+ 1.2 One or more `Dockerfile`s in project
52
+ 2. You want to automate builds with `kaniko` build system.
53
+ 3. `kaniko` dont support `docker-compose.yml` builds.
54
+
55
+ ## How to
56
+ ```
57
+ pip install buildah-wrapper
58
+ cd <...>/directory/contains/docker/and/docker-compose-file/
59
+ buildah-wrapper
60
+ ```
61
+
62
+ ### Arguments (examples)
63
+ * `--compose-file` - Path to docker-compose.yml file
64
+ * `--version`, `-v` - Show script version
65
+ * `--help`, `-h` - Show this help message and exit
66
+
67
+ ## Supported features (example):
68
+
69
+ 1. Single project in `docker-compose.yml`
70
+ ```
71
+ services:
72
+ app:
73
+ image: "EpicMorg/buildah-wrapper:image"
74
+ build:
75
+ context: .
76
+ dockerfile: ./Dockerfile
77
+ ```
78
+
79
+ 2. Multiproject in `docker-compose.yml`
80
+
81
+ ```
82
+ services:
83
+ app:
84
+ image: "EpicMorg/buildah-wrapper:image-jdk11"
85
+ build:
86
+ context: .
87
+ app-develop:
88
+ image: "EpicMorg/buildah-wrapper:image-develop-jdk11"
89
+ build:
90
+ context: .
91
+ dockerfile: ./Dockerfile.develop
92
+ app-develop-17:
93
+ image: "epicmorg/astralinux:image-develop-jdk17"
94
+ build:
95
+ context: .
96
+ dockerfile: ./Dockerfile.develop-17
97
+ ```
@@ -0,0 +1,7 @@
1
+ buildah_wrapper/__init__.py,sha256=5YdTwwQoP6maFB-_aV12Jf5cZJMLoUeunz-pb1XWKV0,14
2
+ buildah_wrapper/buildah_wrapper.py,sha256=ZnFohoCpZhfsLVYMFjSBUVrdMLEwUfGrO0uMUKiI6NM,11085
3
+ buildah_wrapper-0.0.0.1.dist-info/METADATA,sha256=cWUlzRMSyiDeZeouIlqAyNfoRaY4kmhoy-xIjaHiC9w,4783
4
+ buildah_wrapper-0.0.0.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
5
+ buildah_wrapper-0.0.0.1.dist-info/entry_points.txt,sha256=irJeqZ55jRU2dLT5tPWDUlT0FnYmoKor_1-mALlsnw4,73
6
+ buildah_wrapper-0.0.0.1.dist-info/licenses/LICENSE,sha256=bm_WGoejFcUka8uFcrpUs7wK4dTFs026uy87iZTpGbc,1060
7
+ buildah_wrapper-0.0.0.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.27.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ buildah-wrapper = buildah_wrapper.buildah_wrapper:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) EpicMorg
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.