al-devops-kit 0.4.0__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.
- al_devops_kit/__init__.py +0 -0
- al_devops_kit/__main__.py +3 -0
- al_devops_kit/dags_installer.py +130 -0
- al_devops_kit/templates/v3.0.0/_airflow_installer_dag.py +394 -0
- al_devops_kit-0.4.0.dist-info/METADATA +85 -0
- al_devops_kit-0.4.0.dist-info/RECORD +10 -0
- al_devops_kit-0.4.0.dist-info/WHEEL +5 -0
- al_devops_kit-0.4.0.dist-info/entry_points.txt +2 -0
- al_devops_kit-0.4.0.dist-info/licenses/LICENSE +21 -0
- al_devops_kit-0.4.0.dist-info/top_level.txt +1 -0
|
File without changes
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"""
|
|
2
|
+
al-devops-kit DAGs installer CLI
|
|
3
|
+
|
|
4
|
+
Usage:
|
|
5
|
+
al-devops-kit copy-dags <target_dir> [--version <ver>] [--force]
|
|
6
|
+
al-devops-kit list-versions
|
|
7
|
+
python -m al_devops_kit copy-dags <target_dir> [--version <ver>]
|
|
8
|
+
|
|
9
|
+
Commands:
|
|
10
|
+
copy-dags Copy the airflow installer DAG to the specified Airflow dags folder.
|
|
11
|
+
Existing files are overwritten if contents differ.
|
|
12
|
+
Use --force to overwrite regardless of content.
|
|
13
|
+
list-versions List all available template versions.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
import argparse
|
|
17
|
+
import filecmp
|
|
18
|
+
import os
|
|
19
|
+
import shutil
|
|
20
|
+
from pathlib import Path
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _templates_dir() -> Path:
|
|
24
|
+
return Path(__file__).parent / 'templates'
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _version_key(name: str) -> tuple:
|
|
28
|
+
stripped = name.lstrip('v')
|
|
29
|
+
try:
|
|
30
|
+
return tuple(int(x) for x in stripped.split('.'))
|
|
31
|
+
except ValueError:
|
|
32
|
+
return (0, 0, 0)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _available_versions() -> list[str]:
|
|
36
|
+
base = _templates_dir()
|
|
37
|
+
versions = [p.name for p in base.iterdir() if p.is_dir()]
|
|
38
|
+
return sorted(versions, key=_version_key)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _latest_version() -> str:
|
|
42
|
+
versions = _available_versions()
|
|
43
|
+
if not versions:
|
|
44
|
+
raise RuntimeError('No template versions found in the package.')
|
|
45
|
+
return versions[-1]
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _copy_dags(target: str, version: str | None, force: bool = False) -> None:
|
|
49
|
+
ver = version or _latest_version()
|
|
50
|
+
src_dir = _templates_dir() / ver
|
|
51
|
+
|
|
52
|
+
if not src_dir.exists():
|
|
53
|
+
available = ', '.join(_available_versions()) or 'none'
|
|
54
|
+
raise SystemExit(f"Version '{ver}' not found. Available versions: {available}")
|
|
55
|
+
|
|
56
|
+
dest_dir = Path(target)
|
|
57
|
+
dest_dir.mkdir(parents=True, exist_ok=True)
|
|
58
|
+
|
|
59
|
+
print(f'Copying templates version {ver} -> {dest_dir}\n')
|
|
60
|
+
copied = updated = skipped = 0
|
|
61
|
+
for src in sorted(src_dir.glob('*.py')):
|
|
62
|
+
dest = dest_dir / src.name
|
|
63
|
+
if dest.exists() and not force:
|
|
64
|
+
if filecmp.cmp(src, dest, shallow=False):
|
|
65
|
+
print(f' skip {src.name} (identical)')
|
|
66
|
+
skipped += 1
|
|
67
|
+
else:
|
|
68
|
+
shutil.copy2(src, dest)
|
|
69
|
+
print(f' update {src.name} -> {dest}')
|
|
70
|
+
updated += 1
|
|
71
|
+
else:
|
|
72
|
+
shutil.copy2(src, dest)
|
|
73
|
+
print(f' copy {src.name} -> {dest}')
|
|
74
|
+
copied += 1
|
|
75
|
+
|
|
76
|
+
print(f'\nDone. {copied} copied, {updated} updated, {skipped} skipped.')
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def _list_versions() -> None:
|
|
80
|
+
versions = _available_versions()
|
|
81
|
+
if not versions:
|
|
82
|
+
print('No template versions found.')
|
|
83
|
+
return
|
|
84
|
+
latest = versions[-1]
|
|
85
|
+
for v in versions:
|
|
86
|
+
marker = ' (latest)' if v == latest else ''
|
|
87
|
+
print(f' {v}{marker}')
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def main() -> None:
|
|
91
|
+
parser = argparse.ArgumentParser(
|
|
92
|
+
prog='al-devops-kit', description='al-devops-kit DAGs installer'
|
|
93
|
+
)
|
|
94
|
+
sub = parser.add_subparsers(dest='command', required=True)
|
|
95
|
+
|
|
96
|
+
copy_cmd = sub.add_parser(
|
|
97
|
+
'copy-dags', help='Copy installer DAG template(s) to the Airflow dags folder'
|
|
98
|
+
)
|
|
99
|
+
copy_cmd.add_argument(
|
|
100
|
+
'target',
|
|
101
|
+
nargs='?',
|
|
102
|
+
default=None,
|
|
103
|
+
help='Destination directory (default on POSIX: /opt/airflow/dags; required elsewhere)',
|
|
104
|
+
)
|
|
105
|
+
copy_cmd.add_argument(
|
|
106
|
+
'--version', default=None, help='Template version to copy (default: latest)'
|
|
107
|
+
)
|
|
108
|
+
copy_cmd.add_argument(
|
|
109
|
+
'--force',
|
|
110
|
+
action='store_true',
|
|
111
|
+
help='Overwrite existing files even if contents are identical',
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
sub.add_parser('list-versions', help='List available template versions')
|
|
115
|
+
|
|
116
|
+
args = parser.parse_args()
|
|
117
|
+
|
|
118
|
+
if args.command == 'copy-dags':
|
|
119
|
+
target = args.target
|
|
120
|
+
if target is None:
|
|
121
|
+
if os.name != 'posix':
|
|
122
|
+
parser.error('copy-dags: <target> is required on this platform')
|
|
123
|
+
target = '/opt/airflow/dags'
|
|
124
|
+
_copy_dags(target, args.version, args.force)
|
|
125
|
+
elif args.command == 'list-versions':
|
|
126
|
+
_list_versions()
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
if __name__ == '__main__':
|
|
130
|
+
main()
|
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
"""
|
|
2
|
+
_airflow_installer_dag.py
|
|
3
|
+
|
|
4
|
+
Bootstrap installer DAG. Airflow 3.x.
|
|
5
|
+
|
|
6
|
+
Reads /opt/airflow/.repos/repos.yml, then for each repo:
|
|
7
|
+
1. Clones or pulls the repo into /opt/airflow/.repos/{name}/
|
|
8
|
+
2. Merges all requirements.txt files and pip-installs them into the Airflow venv
|
|
9
|
+
3. Runs copy-dags CLI for each package listed in requirements_post_install.yaml
|
|
10
|
+
(installs flat into /opt/airflow/dags/ alongside repo DAGs)
|
|
11
|
+
4. Copies DAGs from repo dags_path -> /opt/airflow/dags/ via files_sync_utils,
|
|
12
|
+
excluding package DAG files from deletion
|
|
13
|
+
|
|
14
|
+
Run manually after a fresh Airflow setup, or let it run on schedule to keep DAGs in sync.
|
|
15
|
+
|
|
16
|
+
Setup:
|
|
17
|
+
- Create /opt/airflow/.repos/repos.yml:
|
|
18
|
+
|
|
19
|
+
venv_pip: /opt/airflow/.venv/bin/pip
|
|
20
|
+
repos:
|
|
21
|
+
- name: my-dags
|
|
22
|
+
url: https://<token>@github.com/<org>/<repo>.git
|
|
23
|
+
branch: main
|
|
24
|
+
dags_path: dags/
|
|
25
|
+
requirements: requirements.txt
|
|
26
|
+
|
|
27
|
+
- al-data-utils is installed automatically as a dependency of al-devops-kit.
|
|
28
|
+
|
|
29
|
+
Package DAGs:
|
|
30
|
+
Add requirements_post_install.yaml to any repo root to install DAGs from packages:
|
|
31
|
+
|
|
32
|
+
package_dags:
|
|
33
|
+
- name: al_data_core
|
|
34
|
+
version: latest # or a tag e.g. v3.0.0 (optional)
|
|
35
|
+
files:
|
|
36
|
+
- data_core_dag.py # filenames to protect from sync deletion
|
|
37
|
+
- data_core_config_engine_dag.py
|
|
38
|
+
|
|
39
|
+
Each package must be installed in the Airflow venv and expose a dags_installer
|
|
40
|
+
module with a _copy_dags(target, version, force) function.
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
from __future__ import annotations
|
|
44
|
+
|
|
45
|
+
import subprocess
|
|
46
|
+
from datetime import datetime
|
|
47
|
+
from pathlib import Path
|
|
48
|
+
|
|
49
|
+
import yaml
|
|
50
|
+
from airflow.sdk import dag, task
|
|
51
|
+
|
|
52
|
+
# ── Paths ────────────────────────────────────────────────────────────────────
|
|
53
|
+
|
|
54
|
+
AIRFLOW_HOME = Path('/opt/airflow')
|
|
55
|
+
REPOS_DIR = AIRFLOW_HOME / '.repos'
|
|
56
|
+
REPOS_CONFIG = REPOS_DIR / 'repos.yml'
|
|
57
|
+
DAGS_DIR = AIRFLOW_HOME / 'dags'
|
|
58
|
+
LOG_DIR = REPOS_DIR / 'logs'
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def _redact_url(url: str) -> str:
|
|
62
|
+
"""Hide user:token@ in a git URL before logging it."""
|
|
63
|
+
from urllib.parse import urlsplit, urlunsplit
|
|
64
|
+
|
|
65
|
+
parts = urlsplit(url)
|
|
66
|
+
if not parts.username and not parts.password:
|
|
67
|
+
return url
|
|
68
|
+
host = parts.hostname or ''
|
|
69
|
+
if parts.port:
|
|
70
|
+
host = f'{host}:{parts.port}'
|
|
71
|
+
return urlunsplit(
|
|
72
|
+
(parts.scheme, f'***@{host}', parts.path, parts.query, parts.fragment)
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
# ── DAG ──────────────────────────────────────────────────────────────────────
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
@dag(
|
|
80
|
+
dag_id='_airflow_installer_dag',
|
|
81
|
+
schedule='@daily',
|
|
82
|
+
start_date=datetime(2026, 1, 1),
|
|
83
|
+
catchup=False,
|
|
84
|
+
max_active_runs=1,
|
|
85
|
+
tags=['infrastructure'],
|
|
86
|
+
description='Syncs DAG repos from .repos/repos.yml and installs requirements.',
|
|
87
|
+
)
|
|
88
|
+
def airflow_installer():
|
|
89
|
+
|
|
90
|
+
@task
|
|
91
|
+
def load_config() -> dict:
|
|
92
|
+
"""Read and validate /opt/airflow/.repos/repos.yml."""
|
|
93
|
+
if not REPOS_CONFIG.exists():
|
|
94
|
+
raise FileNotFoundError(
|
|
95
|
+
f'Repos config not found: {REPOS_CONFIG}\n'
|
|
96
|
+
f'Create it with a repos: list (see module docstring).'
|
|
97
|
+
)
|
|
98
|
+
with open(REPOS_CONFIG) as f:
|
|
99
|
+
config = yaml.safe_load(f)
|
|
100
|
+
|
|
101
|
+
repos = config.get('repos') or []
|
|
102
|
+
if not repos:
|
|
103
|
+
raise ValueError(f'No repos defined in {REPOS_CONFIG}')
|
|
104
|
+
|
|
105
|
+
print(f'Loaded {len(repos)} repo(s) from {REPOS_CONFIG}')
|
|
106
|
+
for r in repos:
|
|
107
|
+
print(
|
|
108
|
+
f' - {r["name"]} ({_redact_url(r["url"])} @ {r.get("branch", "main")})'
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
return config
|
|
112
|
+
|
|
113
|
+
@task
|
|
114
|
+
def sync_repos(config: dict) -> dict:
|
|
115
|
+
"""
|
|
116
|
+
Clone or pull each repo into /opt/airflow/.repos/{name}/.
|
|
117
|
+
Removes cloned repos and their DAGs if no longer in config.
|
|
118
|
+
Returns dict with venv_pip and enriched repos list (includes clone_path).
|
|
119
|
+
"""
|
|
120
|
+
import shutil
|
|
121
|
+
|
|
122
|
+
REPOS_DIR.mkdir(parents=True, exist_ok=True)
|
|
123
|
+
|
|
124
|
+
configured_names = {r['name'] for r in config['repos']}
|
|
125
|
+
|
|
126
|
+
# Remove repos that are no longer in config
|
|
127
|
+
for existing in REPOS_DIR.iterdir():
|
|
128
|
+
if not existing.is_dir():
|
|
129
|
+
continue
|
|
130
|
+
if existing.name in configured_names:
|
|
131
|
+
continue
|
|
132
|
+
shutil.rmtree(existing)
|
|
133
|
+
print(f'[{existing.name}] removed from .repos/ (not in config)')
|
|
134
|
+
stale_dags = DAGS_DIR / existing.name
|
|
135
|
+
if stale_dags.exists():
|
|
136
|
+
shutil.rmtree(stale_dags)
|
|
137
|
+
print(f'[{existing.name}] removed from dags/ (not in config)')
|
|
138
|
+
|
|
139
|
+
repos = []
|
|
140
|
+
for repo in config['repos']:
|
|
141
|
+
name = repo['name']
|
|
142
|
+
url = repo['url']
|
|
143
|
+
branch = repo.get('branch', 'main')
|
|
144
|
+
clone_path = REPOS_DIR / name
|
|
145
|
+
|
|
146
|
+
if clone_path.exists():
|
|
147
|
+
print(f'[{name}] pulling {branch}...')
|
|
148
|
+
result = subprocess.run(
|
|
149
|
+
['git', '-C', str(clone_path), 'pull', 'origin', branch],
|
|
150
|
+
check=True,
|
|
151
|
+
capture_output=True,
|
|
152
|
+
text=True,
|
|
153
|
+
)
|
|
154
|
+
print(result.stdout or result.stderr)
|
|
155
|
+
else:
|
|
156
|
+
print(f'[{name}] cloning {_redact_url(url)} @ {branch}...')
|
|
157
|
+
result = subprocess.run(
|
|
158
|
+
['git', 'clone', '--branch', branch, url, str(clone_path)],
|
|
159
|
+
check=True,
|
|
160
|
+
capture_output=True,
|
|
161
|
+
text=True,
|
|
162
|
+
)
|
|
163
|
+
print(result.stdout or result.stderr)
|
|
164
|
+
|
|
165
|
+
# Exclude url (may contain credentials) from XCom payload
|
|
166
|
+
repos.append(
|
|
167
|
+
{
|
|
168
|
+
'name': name,
|
|
169
|
+
'branch': branch,
|
|
170
|
+
'dags_path': repo.get('dags_path', 'dags'),
|
|
171
|
+
'requirements': repo.get('requirements'),
|
|
172
|
+
'clone_path': str(clone_path),
|
|
173
|
+
}
|
|
174
|
+
)
|
|
175
|
+
print(f'[{name}] synced -> {clone_path}')
|
|
176
|
+
|
|
177
|
+
return {
|
|
178
|
+
'venv_pip': config.get('venv_pip', '/opt/airflow/.venv/bin/pip'),
|
|
179
|
+
'repos': repos,
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
@task
|
|
183
|
+
def install_requirements(synced: dict) -> dict:
|
|
184
|
+
"""
|
|
185
|
+
Collect requirements.txt from each repo, merge unique lines,
|
|
186
|
+
write to .repos/merged_requirements.txt, and pip install.
|
|
187
|
+
Returns synced unchanged (pass-through for task chaining).
|
|
188
|
+
"""
|
|
189
|
+
venv_pip = synced['venv_pip']
|
|
190
|
+
repos = synced['repos']
|
|
191
|
+
all_lines: set[str] = set()
|
|
192
|
+
|
|
193
|
+
for repo in repos:
|
|
194
|
+
req_rel = repo.get('requirements')
|
|
195
|
+
if not req_rel:
|
|
196
|
+
continue
|
|
197
|
+
|
|
198
|
+
req_file = Path(repo['clone_path']) / req_rel
|
|
199
|
+
if not req_file.exists():
|
|
200
|
+
print(
|
|
201
|
+
f'[{repo["name"]}] requirements file not found: {req_file} — skipping'
|
|
202
|
+
)
|
|
203
|
+
continue
|
|
204
|
+
|
|
205
|
+
lines = [
|
|
206
|
+
line.strip()
|
|
207
|
+
for line in req_file.read_text().splitlines()
|
|
208
|
+
if line.strip() and not line.strip().startswith('#')
|
|
209
|
+
]
|
|
210
|
+
all_lines.update(lines)
|
|
211
|
+
print(
|
|
212
|
+
f'[{repo["name"]}] collected {len(lines)} requirement(s) from {req_file}'
|
|
213
|
+
)
|
|
214
|
+
|
|
215
|
+
if not all_lines:
|
|
216
|
+
print('No requirements to install.')
|
|
217
|
+
return synced
|
|
218
|
+
|
|
219
|
+
merged_req = REPOS_DIR / 'merged_requirements.txt'
|
|
220
|
+
merged_req.write_text('\n'.join(sorted(all_lines)) + '\n')
|
|
221
|
+
print(f'Merged {len(all_lines)} unique requirement(s) -> {merged_req}')
|
|
222
|
+
|
|
223
|
+
subprocess.run([venv_pip, 'install', '-r', str(merged_req)], check=True)
|
|
224
|
+
print('Requirements installed.')
|
|
225
|
+
return synced
|
|
226
|
+
|
|
227
|
+
@task
|
|
228
|
+
def install_package_dags(synced: dict) -> list[str]:
|
|
229
|
+
"""
|
|
230
|
+
For each cloned repo that contains requirements_post_install.yaml, collect
|
|
231
|
+
the package_dags entries (Python package names) and call each package's
|
|
232
|
+
dags_installer._copy_dags() in-process via a temp dir.
|
|
233
|
+
|
|
234
|
+
Calls each package's _list_dags() to discover filenames, then _copy_dags()
|
|
235
|
+
to install directly into /opt/airflow/dags/. Both run in-process to avoid
|
|
236
|
+
re-initialising Airflow's DB connection in a subprocess.
|
|
237
|
+
|
|
238
|
+
The returned list of filenames is passed to copy_dags so those files are
|
|
239
|
+
excluded from deletion during the repo sync.
|
|
240
|
+
|
|
241
|
+
Stale cleanup is automatic: removed packages are simply absent from the
|
|
242
|
+
returned list, so copy_dags will delete their files as normal.
|
|
243
|
+
"""
|
|
244
|
+
import importlib
|
|
245
|
+
|
|
246
|
+
repos = synced['repos']
|
|
247
|
+
|
|
248
|
+
# Collect package entries from all repos, deduplicated, order-preserving.
|
|
249
|
+
# Each entry is normalised to {'name': str, 'version': str | None, 'files': list[str]}.
|
|
250
|
+
# yaml format:
|
|
251
|
+
# - name: al_data_core
|
|
252
|
+
# version: latest # or a tag like v3.0.0 (optional, default: latest)
|
|
253
|
+
# files:
|
|
254
|
+
# - data_core_dag.py # filenames to protect from copy_dags deletion
|
|
255
|
+
seen: set[str] = set()
|
|
256
|
+
packages: list[dict] = []
|
|
257
|
+
for repo in repos:
|
|
258
|
+
post_install = Path(repo['clone_path']) / 'requirements_post_install.yaml'
|
|
259
|
+
if not post_install.exists():
|
|
260
|
+
continue
|
|
261
|
+
with open(post_install) as f:
|
|
262
|
+
cfg = yaml.safe_load(f) or {}
|
|
263
|
+
for raw in cfg.get('package_dags') or []:
|
|
264
|
+
ver = raw.get('version')
|
|
265
|
+
entry = {
|
|
266
|
+
'name': raw['name'],
|
|
267
|
+
'version': None if ver in (None, 'latest') else ver,
|
|
268
|
+
'files': raw.get('files') or [],
|
|
269
|
+
}
|
|
270
|
+
if entry['name'] not in seen:
|
|
271
|
+
seen.add(entry['name'])
|
|
272
|
+
packages.append(entry)
|
|
273
|
+
print(
|
|
274
|
+
f'[{repo["name"]}] requirements_post_install.yaml: {cfg.get("package_dags") or []}'
|
|
275
|
+
)
|
|
276
|
+
|
|
277
|
+
if not packages:
|
|
278
|
+
print('No package DAGs to install.')
|
|
279
|
+
return []
|
|
280
|
+
|
|
281
|
+
installed_files: list[str] = []
|
|
282
|
+
for entry in packages:
|
|
283
|
+
pkg = entry['name']
|
|
284
|
+
version = entry['version']
|
|
285
|
+
pkg_files = entry['files']
|
|
286
|
+
installer = importlib.import_module(f'{pkg}.dags_installer')
|
|
287
|
+
ver_label = version or 'latest'
|
|
288
|
+
print(f'[{pkg}] installing DAGs ({ver_label}) -> {DAGS_DIR}')
|
|
289
|
+
installer._copy_dags(str(DAGS_DIR), version, False)
|
|
290
|
+
installed_files.extend(pkg_files)
|
|
291
|
+
print(f'[{pkg}] protected files: {pkg_files}')
|
|
292
|
+
|
|
293
|
+
return installed_files
|
|
294
|
+
|
|
295
|
+
@task
|
|
296
|
+
def copy_dags(synced: dict, package_dag_files: list[str]) -> None:
|
|
297
|
+
"""
|
|
298
|
+
Copy DAGs from all repos flat into /opt/airflow/dags/ in a single pass.
|
|
299
|
+
|
|
300
|
+
Uses files_sync_utils with a single SyncConfig whose source_paths lists
|
|
301
|
+
every repo's dags_path directory. Copy/update/delete are all handled by
|
|
302
|
+
the library. Files installed by install_package_dags are excluded from
|
|
303
|
+
deletion so the repo sync never removes them.
|
|
304
|
+
"""
|
|
305
|
+
from al_data_utils.files_sync_utils import (
|
|
306
|
+
SyncConfig,
|
|
307
|
+
build_plan_df,
|
|
308
|
+
execute_plan,
|
|
309
|
+
log_activity,
|
|
310
|
+
log_folder_retention,
|
|
311
|
+
)
|
|
312
|
+
|
|
313
|
+
repos = synced['repos']
|
|
314
|
+
LOG_DIR.mkdir(parents=True, exist_ok=True)
|
|
315
|
+
|
|
316
|
+
source_paths: list[str] = []
|
|
317
|
+
for repo in repos:
|
|
318
|
+
dags_path = Path(repo['clone_path']) / repo.get('dags_path', 'dags')
|
|
319
|
+
if dags_path.exists():
|
|
320
|
+
source_paths.append(str(dags_path))
|
|
321
|
+
else:
|
|
322
|
+
print(f'[{repo["name"]}] dags_path not found: {dags_path} — skipping')
|
|
323
|
+
|
|
324
|
+
if source_paths:
|
|
325
|
+
cfg = SyncConfig(
|
|
326
|
+
source_paths=source_paths,
|
|
327
|
+
target_path=str(DAGS_DIR),
|
|
328
|
+
log_folder=str(LOG_DIR),
|
|
329
|
+
copy_folders_names_to_skip=['__pycache__', '.git'],
|
|
330
|
+
copy_files_names_to_skip=['.gitignore', '.gitkeep'],
|
|
331
|
+
delete_folders_names_to_skip=['.configs'],
|
|
332
|
+
delete_files_names_to_skip=[
|
|
333
|
+
'_airflow_installer_dag.py',
|
|
334
|
+
*package_dag_files,
|
|
335
|
+
],
|
|
336
|
+
delete_folders_names_to_try=[],
|
|
337
|
+
delete_files_names_to_try=[],
|
|
338
|
+
)
|
|
339
|
+
|
|
340
|
+
plan = build_plan_df(cfg)
|
|
341
|
+
result_df, summary = execute_plan(plan)
|
|
342
|
+
|
|
343
|
+
_RESULT_LABEL = {
|
|
344
|
+
'copied': 'COPY',
|
|
345
|
+
'updated': 'UPDATE',
|
|
346
|
+
'deleted_file': 'DELETE',
|
|
347
|
+
'deleted_dir': 'DELETE DIR',
|
|
348
|
+
'skipped': 'SKIP',
|
|
349
|
+
'try_delete_failed': 'TRY DELETE FAILED',
|
|
350
|
+
'error': 'ERROR',
|
|
351
|
+
}
|
|
352
|
+
_QUIET_REASONS = {'same', 'dir_tree_skip'}
|
|
353
|
+
for _, row in result_df.iterrows():
|
|
354
|
+
result = row.get('result', '')
|
|
355
|
+
reason = row.get('reason', '')
|
|
356
|
+
if (
|
|
357
|
+
result in ('skipped', 'already_missing')
|
|
358
|
+
and reason in _QUIET_REASONS
|
|
359
|
+
):
|
|
360
|
+
continue
|
|
361
|
+
label = _RESULT_LABEL.get(result, result.upper())
|
|
362
|
+
line = f' [{label}] {row.get("rel_path", "")}'
|
|
363
|
+
if reason and reason not in _QUIET_REASONS:
|
|
364
|
+
line += f' ({reason})'
|
|
365
|
+
if row.get('error'):
|
|
366
|
+
line += f' -> {row["error"]}'
|
|
367
|
+
print(line)
|
|
368
|
+
|
|
369
|
+
log_activity(result_df, summary, str(LOG_DIR))
|
|
370
|
+
log_folder_retention(str(LOG_DIR), retain_days=30)
|
|
371
|
+
|
|
372
|
+
print(
|
|
373
|
+
f'DAGs synced -> {DAGS_DIR} | '
|
|
374
|
+
f'copied={summary["copied_files"]} '
|
|
375
|
+
f'updated={summary["updated_files"]} '
|
|
376
|
+
f'deleted={summary.get("deleted_files", 0)} '
|
|
377
|
+
f'errors={summary["errors"]}'
|
|
378
|
+
)
|
|
379
|
+
|
|
380
|
+
if summary['errors'] > 0:
|
|
381
|
+
raise RuntimeError(
|
|
382
|
+
f'DAG copy finished with {summary["errors"]} error(s)'
|
|
383
|
+
)
|
|
384
|
+
|
|
385
|
+
# ── Wire up ───────────────────────────────────────────────────────────────
|
|
386
|
+
|
|
387
|
+
config = load_config()
|
|
388
|
+
synced = sync_repos(config)
|
|
389
|
+
synced = install_requirements(synced)
|
|
390
|
+
package_dag_files = install_package_dags(synced)
|
|
391
|
+
copy_dags(synced, package_dag_files)
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
airflow_installer()
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: al-devops-kit
|
|
3
|
+
Version: 0.4.0
|
|
4
|
+
Summary: Airflow installer DAG and CLI: sync DAG repos, install requirements and package DAGs into a running Airflow.
|
|
5
|
+
Author-email: AL Data Labs <pypi@aldatalabs.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://aldatalabs.com
|
|
8
|
+
Keywords: airflow,devops,dags,deployment,ubuntu
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
11
|
+
Classifier: Topic :: System :: Installation/Setup
|
|
12
|
+
Requires-Python: >=3.10
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: al-data-utils>=0.3.2
|
|
16
|
+
Dynamic: license-file
|
|
17
|
+
|
|
18
|
+
# al-devops-kit
|
|
19
|
+
|
|
20
|
+
Airflow bootstrap tooling: a versioned installer DAG plus a CLI that deploys it.
|
|
21
|
+
|
|
22
|
+
## Install
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pip install al-devops-kit
|
|
26
|
+
al-devops-kit copy-dags /opt/airflow/dags
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Python 3.10+. Install into the Airflow virtualenv. `al-data-utils` is pulled in
|
|
30
|
+
automatically; `apache-airflow` 3.x is expected from the host environment.
|
|
31
|
+
|
|
32
|
+
## CLI
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
al-devops-kit copy-dags <dags_dir> [--version vX.Y.Z] [--force]
|
|
36
|
+
al-devops-kit list-versions
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
`copy-dags` copies the installer DAG template into the given dags folder.
|
|
40
|
+
Existing files are overwritten only when their content differs.
|
|
41
|
+
|
|
42
|
+
## Installer DAG
|
|
43
|
+
|
|
44
|
+
`_airflow_installer_dag.py` runs daily (or on demand) and:
|
|
45
|
+
|
|
46
|
+
1. Reads `/opt/airflow/.repos/repos.yml`.
|
|
47
|
+
2. Clones or pulls each listed repo into `/opt/airflow/.repos/<name>/`.
|
|
48
|
+
3. Merges the repos' `requirements.txt` files and pip-installs them into the Airflow venv.
|
|
49
|
+
4. Installs DAGs from Python packages listed in each repo's `requirements_post_install.yaml`.
|
|
50
|
+
5. Syncs each repo's `dags_path` into `/opt/airflow/dags/` (copy, update, delete).
|
|
51
|
+
|
|
52
|
+
`repos.yml` format:
|
|
53
|
+
|
|
54
|
+
```yaml
|
|
55
|
+
venv_pip: /opt/airflow/.venv/bin/pip
|
|
56
|
+
repos:
|
|
57
|
+
- name: my-dags
|
|
58
|
+
url: https://<token>@github.com/<org>/<repo>.git
|
|
59
|
+
branch: main
|
|
60
|
+
dags_path: dags/
|
|
61
|
+
requirements: requirements.txt
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
`requirements_post_install.yaml` (in a repo root, optional):
|
|
65
|
+
|
|
66
|
+
```yaml
|
|
67
|
+
package_dags:
|
|
68
|
+
- name: al_data_core
|
|
69
|
+
version: latest
|
|
70
|
+
files:
|
|
71
|
+
- data_core_dag.py
|
|
72
|
+
- data_core_config_engine_dag.py
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Each package listed must be installed in the Airflow venv and expose a
|
|
76
|
+
`dags_installer` module with `_copy_dags(target, version, force)`.
|
|
77
|
+
|
|
78
|
+
## Repository extras
|
|
79
|
+
|
|
80
|
+
The source repository also contains an Ansible playbook for a single-VM
|
|
81
|
+
Airflow install on Ubuntu. It is not part of the PyPI package.
|
|
82
|
+
|
|
83
|
+
## Changelog
|
|
84
|
+
|
|
85
|
+
See `CHANGELOG.md` in the repository for release notes.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
al_devops_kit/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
al_devops_kit/__main__.py,sha256=9NguP06OkOuWFffWcWRz7bNFBdHcXa-TSIzMABNsVrk,57
|
|
3
|
+
al_devops_kit/dags_installer.py,sha256=SukNeXYVlAAW6SHO9aeqhSAJgZddtf3s74TLkOEwTEI,4074
|
|
4
|
+
al_devops_kit/templates/v3.0.0/_airflow_installer_dag.py,sha256=rGusdilKE8BAkftM1Ukf4U4T8zhokRdl0KLhP4Rv4Dw,15121
|
|
5
|
+
al_devops_kit-0.4.0.dist-info/licenses/LICENSE,sha256=FSoDw09XQtrZEbEgid_0dBku6vuuPj3r7XPxcTklOfo,1090
|
|
6
|
+
al_devops_kit-0.4.0.dist-info/METADATA,sha256=poi6nTtm-g8debjrtbeTZ4HN0Ryfn-ePZfUUW1VJG_4,2574
|
|
7
|
+
al_devops_kit-0.4.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
8
|
+
al_devops_kit-0.4.0.dist-info/entry_points.txt,sha256=C2vQ_VYyoI7T9Btvi-tXNVzvvkHtC5mhDQtRC7Zm-4A,68
|
|
9
|
+
al_devops_kit-0.4.0.dist-info/top_level.txt,sha256=DbWIoN2Opq57cDNXYMCxK5QwJANF6m7_Jj2fEm7OuJk,14
|
|
10
|
+
al_devops_kit-0.4.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 AL Data Labs
|
|
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.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
al_devops_kit
|