forked from sourcentis/mercator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·139 lines (116 loc) · 5.01 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·139 lines (116 loc) · 5.01 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
#!/bin/bash
set -e
# ---------------------------------------------------------------------------
# CONFIG
# ---------------------------------------------------------------------------
DOCKER_REGISTRY="ghcr.io/sourcentis"
DOCKER_IMAGE="mercator"
CHART_DIR="docs/_helm_chart/chart"
CHART_INDEX_DIR="docs/_helm_chart/index"
CHART_REPO_URL="https://github.com/sourcentis/mercator/releases/download"
# ---------------------------------------------------------------------------
# 0. Version
# ---------------------------------------------------------------------------
date +%Y.%m.%d > version.txt
VERSION=$(tr -d ' \n' < version.txt)
echo "[✔] Using version: $VERSION"
# Clean logs
truncate --size 0 ./storage/logs/laravel.log
# ---------------------------------------------------------------------------
# 1. Mettre à jour .env
# ---------------------------------------------------------------------------
if grep -q "^APP_VERSION=" .env; then
sed -i "s/^APP_VERSION=.*/APP_VERSION=$VERSION/" .env
else
echo "APP_VERSION=$VERSION" >> .env
fi
echo "[✔] .env updated"
# ---------------------------------------------------------------------------
# 2. Mettre à jour package.json
# ---------------------------------------------------------------------------
if command -v jq > /dev/null; then
tmpfile=$(mktemp)
jq --arg v "$VERSION" '.version = $v' package.json > "$tmpfile" && mv "$tmpfile" package.json
echo "[✔] package.json updated (jq)"
else
sed -i "s/\"version\": *\"[^\"]*\"/\"version\": \"$VERSION\"/" package.json
echo "[✔] package.json updated (sed)"
fi
# ---------------------------------------------------------------------------
# 2b. Composer update (|| true pour éviter l'échec si la clé est absente)
# ---------------------------------------------------------------------------
composer update
echo "[✔] composer updated"
# ---------------------------------------------------------------------------
# 3. Build frontend
# ---------------------------------------------------------------------------
export APP_VERSION=$VERSION
npm run build
if [ -n "$(git status --porcelain public/build/assets/)" ]; then
git add public/build/assets
git commit -m "build: npm assets $VERSION"
git push
else
echo "[✔] No frontend changes to commit"
fi
echo "[✔] Frontend built with APP_VERSION=$VERSION"
# ---------------------------------------------------------------------------
# 4. Mettre à jour le Helm chart
# ---------------------------------------------------------------------------
# Lire la version actuelle du chart et l'incrémenter (patch)
CHART_YAML="${CHART_DIR}/Chart.yaml"
if [ ! -f "$CHART_YAML" ]; then
echo "[✘] $CHART_YAML introuvable — vérifier le chemin" >&2
exit 1
fi
CURRENT_CHART_VERSION=$(grep '^version:' "$CHART_YAML" | awk '{print $2}')
echo "[✔] Current chart version: $CURRENT_CHART_VERSION"
# Incrément du patch (ex: 2.0.5 → 2.0.6)
NEW_CHART_VERSION="$VERSION"
echo "[✔] New chart version: $NEW_CHART_VERSION"
# Mettre à jour Chart.yaml
sed -i "s/^version:.*/version: $NEW_CHART_VERSION/" "$CHART_YAML"
sed -i "s/^appVersion:.*/appVersion: $VERSION/" "$CHART_YAML"
echo "[✔] Chart.yaml updated (version: $NEW_CHART_VERSION, appVersion: $VERSION)"
# Packager le chart
helm dependency update "$CHART_DIR"
helm package "$CHART_DIR" --destination "$CHART_INDEX_DIR"
CHART_TGZ="${CHART_INDEX_DIR}/${DOCKER_IMAGE}-${NEW_CHART_VERSION}.tgz"
echo "[✔] Helm chart packaged: $CHART_TGZ"
# Régénérer l'index en fusionnant avec l'existant
helm repo index "$CHART_INDEX_DIR" \
--url "${CHART_REPO_URL}/mercator-${NEW_CHART_VERSION}" \
--merge "${CHART_INDEX_DIR}/index.yaml"
echo "[✔] Helm index updated"
# Committer l'index mis à jour (sans le .tgz — il ira dans la release GitHub)
git add "${CHART_INDEX_DIR}/index.yaml" "$CHART_YAML"
git commit -m "helm: chart $NEW_CHART_VERSION (app $VERSION)"
git push
exit
# ---------------------------------------------------------------------------
# 5. Git tag & GitHub release
# ---------------------------------------------------------------------------
RELEASE_TAG="mercator-${NEW_CHART_VERSION}"
git tag -a "$RELEASE_TAG" -m "Release $RELEASE_TAG — app $VERSION"
git push origin "$RELEASE_TAG"
# Upload du .tgz comme asset de la release
gh release create "$RELEASE_TAG" \
--title "Mercator $NEW_CHART_VERSION" \
--notes "App version: $VERSION" \
"$CHART_TGZ"
echo "[✔] GitHub release created: $RELEASE_TAG"
# ---------------------------------------------------------------------------
# 6. Construire et pousser l'image Docker
# ---------------------------------------------------------------------------
FULL_IMAGE="${DOCKER_REGISTRY}/${DOCKER_IMAGE}"
docker build \
--build-arg APP_VERSION=$VERSION \
-t "${FULL_IMAGE}:${VERSION}" \
-t "${FULL_IMAGE}:latest" .
echo "[✔] Docker build: ${FULL_IMAGE}:${VERSION} and :latest"
echo ""
echo "========================================="
echo " Build terminé — version: $VERSION"
echo " Chart: $NEW_CHART_VERSION"
echo " Image: ${FULL_IMAGE}:${VERSION}"
echo "========================================="