-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy-with-argocd.sh
executable file
·76 lines (64 loc) · 2.04 KB
/
deploy-with-argocd.sh
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
#!/bin/bash
function retrieveVersionFromMaven {
export VERSION=$(mvn -q -s .m2/settings.xml help:evaluate -Dexpression=project.version -DforceStdout);
echo "Retrieved version from maven";
if [[ -z ${VERSION} ]]; then
echo "Failed to retrieve artifact version from maven";
exit 1;
fi
}
function retrieveVersionFromGradle {
export VERSION=$(./gradlew -q printVersion --init-script gradle/init.gradle);
echo "Retrieved version from gradle";
if [[ -z ${VERSION} ]]; then
echo "Failed to retrieve artifact version from gradle";
exit 1;
fi
}
# check if the NAMESPACE var is set.
if [[ -z ${NAMESPACE} ]]; then
echo "Failed to deploy application, missing variable 'NAMESPACE'";
exit 1;
fi
# check if the INFRA_REPO var is set
if [[ -z ${INFRA_REPO} ]]; then
echo "Failed to deploy application, missing variable 'INFRA_REPO'";
exit 1;
fi
# check if the APPS var is set
if [[ -z ${APPS} ]]; then
echo "Failed to deploy application, missing or empty variable 'APPS'";
exit 1;
fi
# include the common functions
source "commons.sh"
# prepare git
prepare_git
# set the version based on the Gradle project version.
if [[ -z ${VERSION} ]]; then
if [[ -z ${GRADLE} ]]; then
retrieveVersionFromMaven || exit 1
else
retrieveVersionFromGradle || exit 1
fi
fi
echo "Deploying version ${VERSION}";
# checkout gitOps repo.
git config --global user.email "[email protected]"
git config --global user.name "Magda Pipeline"
rm -rf "${INFRA_REPO}"
git clone "[email protected]:vlaamseoverheid/${INFRA_REPO}.git" || exit 1
cd "${INFRA_REPO}"
# loop over the apps
for app in ${APPS}
do
echo "Updating chart information of ${app}";
# update version.
yq -i '.version = strenv(VERSION)' "./$NAMESPACE/${app}/Chart.yaml" || exit 1;
#update lastDeploymentDate
DATE=$(date '+%Y-%m-%dT%H:%M:%S') yq -i '.deployment.lastDeploymentDate = strenv(DATE)' "./$NAMESPACE/${app}/values.yaml" || exit 1;
done
## commit and push changes
git add .
git commit -m "Version bumped to ${VERSION} by pipeline ${BITBUCKET_BUILD_NUMBER}"
git push || exit 1