Skip to content

Commit 87a766e

Browse files
committed
update scripts
Signed-off-by: Anand Kumar Singh <anandrkskd@gmail.com>
1 parent c01f9c1 commit 87a766e

2 files changed

Lines changed: 103 additions & 14 deletions

File tree

helm-chart/publish-stage.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,10 @@ info "Chart.yaml updated successfully"
173173

174174
# Update values.yaml in the copy - set image repository for stage release
175175
info "Updating values.yaml in the copy with new image repository for stage release..."
176-
IMAGE_REPO="quay.io/redhat-user-workloads/rh-openshift-gitops-tenant/argocd-agent-rhel8"
176+
IMAGE_REPO="registry.redhat.io/openshift-gitops-1/argocd-agent-rhel8"
177177
IMAGE_FULL="${IMAGE_REPO}:${TAG}"
178178
info "Setting image repository to: ${IMAGE_REPO}"
179-
"${YQ}" eval '.image.repository = "quay.io/redhat-user-workloads/rh-openshift-gitops-tenant/argocd-agent-rhel8"' -i "${TEMP_VALUES_YAML}"
179+
"${YQ}" eval '.image.repository = "registry.redhat.io/openshift-gitops-1/argocd-agent-rhel8"' -i "${TEMP_VALUES_YAML}"
180180

181181
# Update values.yaml in the copy - set image tag
182182
info "Setting image tag to: ${TAG}"

helm-chart/publish.sh

Lines changed: 101 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@
66
# The script accepts the image tag as input parameter.
77
#
88
# Usage:
9-
# ./helm-chart/publish.sh <tag>
9+
# ./helm-chart/publish.sh [--stage] <tag>
1010
#
1111
# Arguments:
1212
# tag - The image tag (e.g., v1.18.1-2) to use for the argocd-agent image
1313
#
14+
# Options:
15+
# --stage - Enable stage mode (packages and pushes chart to OCI registry)
16+
#
1417
# Prerequisites:
1518
# - git submodule initialized
1619
# - yq installed (available in bin/yq)
1720
# - helm-docs installed and available in PATH
21+
# - helm installed and available in PATH (required for --stage mode)
1822
#
1923

2024
set -euo pipefail
@@ -24,6 +28,11 @@ REPO_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
2428
CHART_DIR="${REPO_ROOT}/sources/argocd-agent/install/helm-repo/argocd-agent-agent"
2529
CONFIG_YAML="${REPO_ROOT}/config.yaml"
2630
YQ="${REPO_ROOT}/bin/yq"
31+
# Use HELM_OCI_REGISTRY environment variable if set, otherwise use default
32+
HELM_OCI_REGISTRY="${HELM_OCI_REGISTRY:-oci://quay.io/anandrkskd/argocd-agent}"
33+
34+
# Default to release mode
35+
STAGE_MODE=false
2736

2837
# Colors for output
2938
RED='\033[0;31m'
@@ -45,15 +54,35 @@ error() {
4554
}
4655

4756
# Parse command-line arguments
48-
if [ $# -eq 0 ]; then
57+
while [[ $# -gt 0 ]]; do
58+
case $1 in
59+
--stage)
60+
STAGE_MODE=true
61+
shift
62+
;;
63+
*)
64+
if [ -z "${TAG:-}" ]; then
65+
TAG="$1"
66+
else
67+
error "Unexpected argument: $1"
68+
echo "Usage: $0 [--stage] <tag>"
69+
echo "Example: $0 v1.18.1-2"
70+
echo "Example: $0 --stage v1.18.1-2"
71+
exit 1
72+
fi
73+
shift
74+
;;
75+
esac
76+
done
77+
78+
if [ -z "${TAG:-}" ]; then
4979
error "Tag argument is required"
50-
echo "Usage: $0 <tag>"
80+
echo "Usage: $0 [--stage] <tag>"
5181
echo "Example: $0 v1.18.1-2"
82+
echo "Example: $0 --stage v1.18.1-2"
5283
exit 1
5384
fi
5485

55-
TAG="$1"
56-
5786
# Validate tag format (should be like v1.18.1-2)
5887
if [[ ! "${TAG}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9]+)?$ ]]; then
5988
error "Invalid tag format. Expected format: v<major>.<minor>.<patch>[-<build>]"
@@ -62,6 +91,11 @@ if [[ ! "${TAG}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9]+)?$ ]]; then
6291
exit 1
6392
fi
6493

94+
if [ "${STAGE_MODE}" = true ]; then
95+
info "Running in STAGE mode"
96+
else
97+
info "Running in RELEASE mode"
98+
fi
6599
info "Using image tag: ${TAG}"
66100

67101
# Check if yq is available
@@ -77,6 +111,15 @@ if ! command -v helm-docs &> /dev/null; then
77111
exit 1
78112
fi
79113

114+
# Check if helm is available (required for stage mode)
115+
if [ "${STAGE_MODE}" = true ]; then
116+
if ! command -v helm &> /dev/null; then
117+
error "helm is not installed. Please install helm."
118+
error "Installation: https://helm.sh/docs/intro/install/"
119+
exit 1
120+
fi
121+
fi
122+
80123
# Check if config.yaml exists
81124
if [ ! -f "${CONFIG_YAML}" ]; then
82125
error "config.yaml not found: ${CONFIG_YAML}"
@@ -139,7 +182,11 @@ if [ ! -f "${VALUES_YAML}" ]; then
139182
fi
140183

141184
# Copy helm chart to directory under helm-chart with commit-ref naming
142-
HELM_CHART_OUTPUT_DIR="${SCRIPT_DIR}/${ARGOCD_AGENT_COMMIT}-${ARGOCD_AGENT_REF}"
185+
if [ "${STAGE_MODE}" = true ]; then
186+
HELM_CHART_OUTPUT_DIR="${SCRIPT_DIR}/${ARGOCD_AGENT_COMMIT}-${ARGOCD_AGENT_REF}-stage"
187+
else
188+
HELM_CHART_OUTPUT_DIR="${SCRIPT_DIR}/${ARGOCD_AGENT_COMMIT}-${ARGOCD_AGENT_REF}"
189+
fi
143190
info "Copying helm chart to directory: ${HELM_CHART_OUTPUT_DIR}"
144191

145192
# Create output directory
@@ -193,10 +240,52 @@ helm-docs --chart-search-root . --output-file README.md || {
193240
cd "${REPO_ROOT}"
194241
info "Helm chart documentation generated successfully"
195242

196-
info "Helm chart update completed successfully!"
197-
info "Chart name: redhat-argocd-agent"
198-
info "Image repository: ${IMAGE_REPO}"
199-
info "Image tag: ${TAG}"
200-
info "Full image: ${IMAGE_FULL}"
201-
info "Output chart directory: ${HELM_CHART_OUTPUT_DIR}"
243+
# Package and push the helm chart to OCI registry (only in stage mode)
244+
if [ "${STAGE_MODE}" = true ]; then
245+
info "Packaging helm chart..."
246+
cd "${HELM_CHART_OUTPUT_DIR}"
247+
helm package . || {
248+
error "Failed to package helm chart"
249+
exit 1
250+
}
251+
cd "${REPO_ROOT}"
252+
253+
# Get the chart name and version from Chart.yaml
254+
CHART_NAME=$("${YQ}" eval '.name' "${TEMP_CHART_YAML}")
255+
CHART_VERSION=$("${YQ}" eval '.version' "${TEMP_CHART_YAML}")
256+
CHART_PACKAGE="${HELM_CHART_OUTPUT_DIR}/${CHART_NAME}-${CHART_VERSION}.tgz"
257+
258+
if [ ! -f "${CHART_PACKAGE}" ]; then
259+
error "Chart package not found: ${CHART_PACKAGE}"
260+
exit 1
261+
fi
262+
263+
info "Chart packaged successfully: ${CHART_PACKAGE}"
264+
265+
# Push the chart to OCI registry
266+
info "Pushing helm chart to OCI registry: ${HELM_OCI_REGISTRY}"
267+
helm push "${CHART_PACKAGE}" "${HELM_OCI_REGISTRY}" || {
268+
error "Failed to push helm chart to OCI registry"
269+
exit 1
270+
fi
271+
272+
info "Helm chart pushed successfully to: ${HELM_OCI_REGISTRY}"
273+
274+
info "Helm chart stage release completed successfully!"
275+
info "Chart name: ${CHART_NAME}"
276+
info "Chart version: ${CHART_VERSION}"
277+
info "Image repository: ${IMAGE_REPO}"
278+
info "Image tag: ${TAG}"
279+
info "Full image: ${IMAGE_FULL}"
280+
info "Output chart directory: ${HELM_CHART_OUTPUT_DIR}"
281+
info "Chart package: ${CHART_PACKAGE}"
282+
info "OCI registry: ${HELM_OCI_REGISTRY}"
283+
else
284+
info "Helm chart update completed successfully!"
285+
info "Chart name: redhat-argocd-agent"
286+
info "Image repository: ${IMAGE_REPO}"
287+
info "Image tag: ${TAG}"
288+
info "Full image: ${IMAGE_FULL}"
289+
info "Output chart directory: ${HELM_CHART_OUTPUT_DIR}"
290+
fi
202291

0 commit comments

Comments
 (0)