-
Notifications
You must be signed in to change notification settings - Fork 7
134 lines (113 loc) · 4.97 KB
/
release.yaml
File metadata and controls
134 lines (113 loc) · 4.97 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
name: Release Charts
on:
push:
branches: [main]
env:
HELM_VERSION: v3.18.2
HELM_S3_VERSION: v0.17.1
HELM_S3_BUCKET: geosolutions-charts
HELM_S3_PREFIX: charts
HELM_S3_REPO: charts
CHARTS_URL: https://charts.geosolutionsgroup.com/charts
jobs:
release-charts:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Helm
uses: azure/setup-helm@v4
with:
version: ${{ env.HELM_VERSION }}
- name: Configure AWS credentials from OIDC
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::227022658256:role/charts-s3-bucket-role
aws-region: eu-west-2
- name: Install Helm S3 plugin
run: |
helm plugin install https://github.com/hypnoglow/helm-s3.git --version ${{ env.HELM_S3_VERSION }}
- name: Package and push charts to S3
run: |
set -euo pipefail
repo_name="${HELM_S3_REPO}"
repo_url="s3://${HELM_S3_BUCKET}/${HELM_S3_PREFIX}"
https_url="${CHARTS_URL}"
# Initialize Helm repo index in S3 if it does not exist yet
if ! aws s3api head-object --bucket "${HELM_S3_BUCKET}" --key "${HELM_S3_PREFIX}/index.yaml" >/dev/null 2>&1; then
echo "Initializing Helm repo at ${repo_url}"
helm s3 init "$repo_url"
fi
if ! helm repo list | awk '{print $1}' | grep -qx "$repo_name"; then
helm repo add "$repo_name" "$repo_url"
fi
helm repo update
for chart_dir in */*/; do
if [ -f "${chart_dir}Chart.yaml" ]; then
chart_name=$(grep '^name:' "${chart_dir}Chart.yaml" | awk '{print $2}' | tr -d '"' | tr -d "'")
chart_version=$(grep '^version:' "${chart_dir}Chart.yaml" | awk '{print $2}' | tr -d '"' | tr -d "'")
echo "Processing $chart_name:$chart_version"
if helm search repo "${repo_name}/${chart_name}" --version "$chart_version" 2>/dev/null | grep -q "${chart_name}"; then
echo "Chart already exists in $repo_url, skipping..."
continue
fi
helm package "$chart_dir"
package_file="${chart_name}-${chart_version}.tgz"
if [ -f "$package_file" ]; then
helm s3 push "$package_file" "$repo_name"
echo "✅ Pushed $chart_name:$chart_version to $repo_url"
rm "$package_file"
fi
fi
done
# Fix index.yaml URLs from s3:// to HTTPS
echo "Converting index.yaml URLs from s3:// to HTTPS..."
aws s3 cp "$repo_url/index.yaml" /tmp/index.yaml
sed -i "s|$repo_url/|${https_url}/|g" /tmp/index.yaml
aws s3 cp /tmp/index.yaml "$repo_url/index.yaml"
echo "✅ Updated index.yaml with HTTPS URLs"
- name: Checkout GitOps Repository
uses: actions/checkout@v4
with:
repository: geosolutions-it/gitops-dev
token: ${{ secrets.GITOPS_DEV_TOKEN }}
path: gitops-dev
- name: Deploy to Dev (GitOps)
run: |
cd gitops-dev
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
repo_url="${CHARTS_URL}"
changes_made=false
for chart_dir in ../*/*/; do
if [ -f "${chart_dir}Chart.yaml" ]; then
chart_name=$(grep '^name:' "${chart_dir}Chart.yaml" | awk '{print $2}' | tr -d '"' | tr -d "'")
chart_version=$(grep '^version:' "${chart_dir}Chart.yaml" | awk '{print $2}' | tr -d '"' | tr -d "'")
if [ -d "apps/$chart_name" ]; then
current_version=$(grep 'targetRevision:' "apps/$chart_name/application.yaml" | head -1 | awk '{print $2}' | tr -d '"' | tr -d "'")
if [ "$current_version" = "$chart_version" ]; then
echo "$chart_name version $chart_version is already deployed, skipping..."
continue
fi
echo "Updating $chart_name from $current_version to $chart_version in GitOps repository"
sed -i "0,/targetRevision: .*/s/targetRevision: .*/targetRevision: $chart_version/" "apps/$chart_name/application.yaml"
sed -i "0,/repoURL: .*/s|repoURL: .*|repoURL: $repo_url|" "apps/$chart_name/application.yaml"
git add "apps/$chart_name/application.yaml"
git commit -m "chore: update $chart_name chart version from $current_version to $chart_version"
changes_made=true
echo "Updated $chart_name to version $chart_version"
else
echo "App directory for $chart_name not found in GitOps repository"
fi
fi
done
if [ "$changes_made" = true ]; then
git push origin HEAD
echo "✅ GitOps repository updated successfully"
else
echo "📄 No version changes needed - all charts are already at the correct versions"
fi