Skip to content

Commit

Permalink
Add config repo tag updater script and install yq
Browse files Browse the repository at this point in the history
  • Loading branch information
nihaldivyam authored and ashish1099 committed Oct 30, 2024
1 parent 885d998 commit 38ba0c1
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
8 changes: 7 additions & 1 deletion .gitea/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ WORKDIR /tmp

RUN apt-get update \
&& apt-get install software-properties-common -y \
&& add-apt-repository ppa:rmescandon/yq -y \
&& add-apt-repository ppa:longsleep/golang-backports -y \
&& apt-get update \
&& apt-get install -y \
shellcheck \
prometheus \
golang-1.19
golang-1.19 \
yq

# jsonnet
RUN go install github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb@v0.5.1
Expand All @@ -30,3 +32,7 @@ RUN ./get_helm.sh --version v3.9.1
# OPA
RUN wget https://github.com/open-policy-agent/opa/releases/download/v0.43.0/opa_linux_amd64_static -O /usr/local/bin/opa
RUN chmod +x /usr/local/bin/opa

# tag script
RUN curl -fsSL -o tag-update.sh https://raw.githubusercontent.com/Obmondo/kubeaid/refs/heads/master/bin/tag-update.sh
RUN chmod +x tag-update.sh
56 changes: 56 additions & 0 deletions bin/tag-update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/bash

# Function to display usage
usage() {
echo "Usage: $0 -c <cluster-name> -s <source-yaml-file> -r <new-target-revision>"
exit 1
}

# Parse command-line options
while getopts ":c:s:r:" opt; do
case ${opt} in
c )
CLUSTER_NAME="$OPTARG"
;;
s )
SOURCE_YAML_FILE="$OPTARG"
;;
r )
NEW_TARGET_REVISION="$OPTARG"
;;
\? )
usage
;;
esac
done

# Check if all required arguments are provided
if [ -z "$CLUSTER_NAME" ] || [ -z "$SOURCE_YAML_FILE" ] || [ -z "$NEW_TARGET_REVISION" ]; then
usage
fi

TEMPLATES_DIR="${CLUSTER_NAME}/argocd-apps/templates"

# Extract labels.name using yq
LABELS_NAMES=($(yq eval '.spec.groups[].rules[].labels.name' "$SOURCE_YAML_FILE"))

# Loop through each label name and update the corresponding YAML file
for label_name in "${LABELS_NAMES[@]}"; do
yaml_file="${label_name}.yaml" # Assuming the YAML files are named after the labels
file_path="${TEMPLATES_DIR}/${yaml_file}"

# Check if the file exists
if [[ -f "$file_path" ]]; then
echo "Updating targetRevision in $file_path"

# Use yq to update the targetRevision only if the repoURL contains kubeaid.git or k8id.git
yq eval -i "(.spec.sources[] | select(.repoURL | test(\"kubeaid\\.git|k8id\\.git\")) | .targetRevision) = \"$NEW_TARGET_REVISION\"" "$file_path"

echo "Updated targetRevision in $file_path"
else
echo "File $file_path does not exist, skipping."
fi
done

echo "All specified YAML files have been processed."

0 comments on commit 38ba0c1

Please sign in to comment.