CI: blue-ci-cd.yml voor BlueGit
@@ -0,0 +1,127 @@
1
# BlueGit CI (vertaald uit .gitlab-ci.yml; GitLab is alleen nog backup).
2
# Secrets (repo, beschermd, eigen FTP-host): timftphost, timftpuser, timftppassword, timftproot, projectftp.
3
stages:
4
- validate
5
- deploy
6
7
validate_json:
8
stage: validate
9
image: python:3.12-slim
10
rules:
11
# Merge request pipelines
12
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
13
when: on_success
14
15
# Pushes to master
16
- if: $CI_COMMIT_BRANCH == "master" && $CI_PIPELINE_SOURCE == "push"
17
when: on_success
18
19
# Everything else: do not run
20
- when: never
21
22
script:
23
- python -V
24
- |
25
python - <<'PY'
26
import json
27
import sys
28
from pathlib import Path
29
30
root = Path("web")
31
data_dir = root / "data"
32
templates_dir = root / "templates"
33
34
if not data_dir.is_dir():
35
print(f"ERROR: data directory not found: {data_dir.resolve()}")
36
sys.exit(1)
37
38
if not templates_dir.is_dir():
39
print(f"ERROR: templates directory not found: {templates_dir.resolve()}")
40
sys.exit(1)
41
42
# NEW: ensure all files under /data are .json (no other extensions, no extensionless files)
43
bad_files = []
44
for p in sorted(data_dir.rglob("*")):
45
if p.is_file() and p.suffix.lower() != ".json":
46
bad_files.append(p.as_posix())
47
48
if bad_files:
49
print("\nDATA DIRECTORY VALIDATION FAILED\n")
50
print("ERROR: Non-JSON files found under web/data (only .json allowed):")
51
for bf in bad_files:
52
print(" - " + bf)
53
sys.exit(1)
54
55
json_files = sorted(data_dir.rglob("*.json"))
56
if not json_files:
57
print(f"ERROR: No .json files found under {data_dir}")
58
sys.exit(1)
59
60
errors = []
61
checked = 0
62
63
for jf in json_files:
64
checked += 1
65
rel = jf.as_posix()
66
67
# 1) JSON syntax check
68
try:
69
obj = json.loads(jf.read_text(encoding="utf-8"))
70
except Exception as e:
71
errors.append(f"{rel}: invalid JSON ({e})")
72
continue
73
74
if not isinstance(obj, dict):
75
errors.append(f"{rel}: JSON root must be an object")
76
continue
77
78
# 2) type exists and is valid
79
t = obj.get("type")
80
if not isinstance(t, str) or not t.strip():
81
errors.append(f"{rel}: missing or invalid 'type'")
82
continue
83
84
t = t.strip()
85
86
n = obj.get("name")
87
if not isinstance(n, str) or not n.strip():
88
errors.append(f"{rel}: missing or invalid 'name'")
89
continue
90
91
# 3) template exists
92
tpl = templates_dir / f"{t}.template"
93
if not tpl.is_file():
94
errors.append(
95
f"{rel}: type '{t}' has no matching template ({tpl.as_posix()})"
96
)
97
98
if errors:
99
print("\nJSON VALIDATION FAILED\n")
100
for e in errors:
101
print(" - " + e)
102
print(f"\nChecked {checked} file(s), found {len(errors)} issue(s).")
103
sys.exit(1)
104
105
print(f"OK: {checked} JSON file(s) validated successfully.")
106
PY
107
108
ftp_upload:
109
stage: deploy
110
image: debian:bookworm-slim
111
resource_group: production
112
rules:
113
- if: $CI_COMMIT_BRANCH == "master" && $CI_PIPELINE_SOURCE == "push"
114
script:
115
- apt-get update -qy
116
- apt-get install -y --no-install-recommends lftp python3 ca-certificates
117
# BlueGit expandeert $timftproot in secrets niet (GitLab deed dat wel).
118
- export projectftp="$(python3 -c 'import os;r=os.environ.get("timftproot","");print(os.environ["projectftp"].replace("${timftproot}",r).replace("$timftproot",r))')"
119
- test -n "$projectftp"
120
# In-place sync instead of "rm -r + mirror": live folders never disappear during a deploy.
121
# - no --only-newer/--ignore-time: the fresh CI checkout gives every file a new mtime, so the
122
# default size+time comparison re-uploads all files (correct even if FTP mtimes are unreliable)
123
# - --delete removes remote files that no longer exist in web/ (runs after the transfers)
124
# - xfer:use-temp-file uploads to a temp name and renames, so a file is never served half-written
125
# - cmd:fail-exit makes the job fail if the mirror fails
126
- lftp -u $timftpuser,$timftppassword $timftphost -e "set ssl:verify-certificate no; set sftp:auto-confirm yes; set xfer:use-temp-file yes; mkdir -p -f $projectftp; set cmd:fail-exit yes; mirror -R --delete --parallel=4 web $projectftp; quit"
127
needs: [validate_json]
@@ -0,0 +1,127 @@1
# BlueGit CI (vertaald uit .gitlab-ci.yml; GitLab is alleen nog backup).2
# Secrets (repo, beschermd, eigen FTP-host): timftphost, timftpuser, timftppassword, timftproot, projectftp.3
stages:4
- validate5
- deploy6
7
validate_json:8
stage: validate9
image: python:3.12-slim10
rules:11
# Merge request pipelines12
- if: $CI_PIPELINE_SOURCE == "merge_request_event"13
when: on_success14
15
# Pushes to master16
- if: $CI_COMMIT_BRANCH == "master" && $CI_PIPELINE_SOURCE == "push"17
when: on_success18
19
# Everything else: do not run20
- when: never21
22
script:23
- python -V24
- |25
python - <<'PY'26
import json27
import sys28
from pathlib import Path29
30
root = Path("web")31
data_dir = root / "data"32
templates_dir = root / "templates"33
34
if not data_dir.is_dir():35
print(f"ERROR: data directory not found: {data_dir.resolve()}")36
sys.exit(1)37
38
if not templates_dir.is_dir():39
print(f"ERROR: templates directory not found: {templates_dir.resolve()}")40
sys.exit(1)41
42
# NEW: ensure all files under /data are .json (no other extensions, no extensionless files)43
bad_files = []44
for p in sorted(data_dir.rglob("*")):45
if p.is_file() and p.suffix.lower() != ".json":46
bad_files.append(p.as_posix())47
48
if bad_files:49
print("\nDATA DIRECTORY VALIDATION FAILED\n")50
print("ERROR: Non-JSON files found under web/data (only .json allowed):")51
for bf in bad_files:52
print(" - " + bf)53
sys.exit(1)54
55
json_files = sorted(data_dir.rglob("*.json"))56
if not json_files:57
print(f"ERROR: No .json files found under {data_dir}")58
sys.exit(1)59
60
errors = []61
checked = 062
63
for jf in json_files:64
checked += 165
rel = jf.as_posix()66
67
# 1) JSON syntax check68
try:69
obj = json.loads(jf.read_text(encoding="utf-8"))70
except Exception as e:71
errors.append(f"{rel}: invalid JSON ({e})")72
continue73
74
if not isinstance(obj, dict):75
errors.append(f"{rel}: JSON root must be an object")76
continue77
78
# 2) type exists and is valid79
t = obj.get("type")80
if not isinstance(t, str) or not t.strip():81
errors.append(f"{rel}: missing or invalid 'type'")82
continue83
84
t = t.strip()85
86
n = obj.get("name")87
if not isinstance(n, str) or not n.strip():88
errors.append(f"{rel}: missing or invalid 'name'")89
continue90
91
# 3) template exists92
tpl = templates_dir / f"{t}.template"93
if not tpl.is_file():94
errors.append(95
f"{rel}: type '{t}' has no matching template ({tpl.as_posix()})"96
)97
98
if errors:99
print("\nJSON VALIDATION FAILED\n")100
for e in errors:101
print(" - " + e)102
print(f"\nChecked {checked} file(s), found {len(errors)} issue(s).")103
sys.exit(1)104
105
print(f"OK: {checked} JSON file(s) validated successfully.")106
PY107
108
ftp_upload:109
stage: deploy110
image: debian:bookworm-slim111
resource_group: production112
rules:113
- if: $CI_COMMIT_BRANCH == "master" && $CI_PIPELINE_SOURCE == "push"114
script:115
- apt-get update -qy116
- apt-get install -y --no-install-recommends lftp python3 ca-certificates117
# BlueGit expandeert $timftproot in secrets niet (GitLab deed dat wel).118
- export projectftp="$(python3 -c 'import os;r=os.environ.get("timftproot","");print(os.environ["projectftp"].replace("${timftproot}",r).replace("$timftproot",r))')"119
- test -n "$projectftp"120
# In-place sync instead of "rm -r + mirror": live folders never disappear during a deploy.121
# - no --only-newer/--ignore-time: the fresh CI checkout gives every file a new mtime, so the122
# default size+time comparison re-uploads all files (correct even if FTP mtimes are unreliable)123
# - --delete removes remote files that no longer exist in web/ (runs after the transfers)124
# - xfer:use-temp-file uploads to a temp name and renames, so a file is never served half-written125
# - cmd:fail-exit makes the job fail if the mirror fails126
- lftp -u $timftpuser,$timftppassword $timftphost -e "set ssl:verify-certificate no; set sftp:auto-confirm yes; set xfer:use-temp-file yes; mkdir -p -f $projectftp; set cmd:fail-exit yes; mirror -R --delete --parallel=4 web $projectftp; quit"127
needs: [validate_json]