Skip to content

Commit 20aadf5

Browse files
committed
chore: add staging scripts to dependencies
Signed-off-by: Prateek Chandra <[email protected]>
1 parent cbe07ea commit 20aadf5

File tree

5 files changed

+476
-1
lines changed

5 files changed

+476
-1
lines changed

scripts/release.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,6 @@ HELM_DEP_UPDATE=${HELM_DEP_UPDATE:-"false"}
696696
binaries_check "${COMMON_BINS[@]}"
697697
helm_check
698698

699-
cd "$SCRIPT_DIR/.."
699+
cd "$PARENT_ROOT"
700700

701701
trap cleanup_tars EXIT

scripts/staging/kubectl-oci.sh

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
#!/usr/bin/env bash
2+
# Manage kubectl plugin binaries as OCI artifacts.
3+
# Supports both pushing and pulling operations.
4+
# Usage:
5+
# Push: ./kubectl-oci.sh push --tag <tag> --namespace <namespace> [--username <user> --password <token>]
6+
# Pull: ./kubectl-oci.sh pull --tag <tag> --namespace <namespace> [--username <user> --password <token>]
7+
8+
set -euo pipefail
9+
10+
SCRIPT_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]:-"$0"}")")"
11+
ROOT_DIR="$SCRIPT_DIR/../"
12+
13+
# shellcheck source=../utils/log.sh
14+
source "$ROOT_DIR/utils/log.sh"
15+
16+
ACTION=""
17+
TAG=""
18+
NAMESPACE=""
19+
USERNAME=""
20+
PASSWORD=""
21+
REGISTRY="ghcr.io"
22+
PLUGIN="${PLUGIN:-"mayastor"}"
23+
NO_LOGIN=false
24+
25+
usage() {
26+
cat << EOF
27+
Usage: $0 <action> [options]
28+
29+
Actions:
30+
push Push kubectl binaries to $REGISTRY as OCI artifacts
31+
pull Pull kubectl binaries from $REGISTRY OCI artifacts
32+
33+
Options:
34+
--tag <tag> Release tag (required)
35+
--registry <registry> The registry to push/pull from [default=$REGISTRY]
36+
--namespace <namespace> Namespace path (required)
37+
--username <username> Registry username (optional if already logged in)
38+
--password <password> Registry token/password (optional if already logged in)
39+
--no-login Skip login check (useful for CI/CD with pre-auth)
40+
-h, --help Show this help message
41+
42+
Examples:
43+
$0 push --tag v1.0.0 --namespace $PLUGIN/dev --username user --password token
44+
$0 pull --tag v1.0.0 --namespace $PLUGIN/dev
45+
EOF
46+
}
47+
48+
parse_args() {
49+
if [[ $# -lt 1 ]]; then
50+
usage
51+
log_fatal "Error: Action required (push or pull)"
52+
fi
53+
54+
ACTION="$1"
55+
shift
56+
57+
case "$ACTION" in
58+
push|pull)
59+
;;
60+
*)
61+
usage
62+
log_fatal "Error: Invalid action '$ACTION'. Must be 'push' or 'pull'"
63+
;;
64+
esac
65+
66+
while [[ $# -gt 0 ]]; do
67+
case $1 in
68+
--tag)
69+
TAG="$2"
70+
shift 2
71+
;;
72+
--namespace)
73+
NAMESPACE="$2"
74+
shift 2
75+
;;
76+
--registry)
77+
REGISTRY="$2"
78+
shift 2
79+
;;
80+
--username)
81+
USERNAME="$2"
82+
shift 2
83+
;;
84+
--password)
85+
PASSWORD="$2"
86+
shift 2
87+
;;
88+
--no-login)
89+
NO_LOGIN=true
90+
shift
91+
;;
92+
-h|--help)
93+
usage
94+
exit 0
95+
;;
96+
*)
97+
usage
98+
log_fatal "Unknown option: $1"
99+
;;
100+
esac
101+
done
102+
103+
if [[ -z "$TAG" ]] || [[ -z "$NAMESPACE" ]]; then
104+
usage
105+
log_fatal "Error: --tag and --namespace are required"
106+
fi
107+
108+
if [[ -z "${USERNAME:-}" || -z "${PASSWORD:-}" ]]; then
109+
echo "⚠️ No username/password provided — will attempt to use existing oras login session for ${REGISTRY}"
110+
fi
111+
112+
REPOSITORY="${REGISTRY}/${NAMESPACE}/kubectl-${PLUGIN}"
113+
}
114+
115+
# Login to registry (only if needed)
116+
login_registry() {
117+
echo "Checking login status for ${REGISTRY}..."
118+
119+
if oras login "${REGISTRY}" --get >/dev/null 2>&1; then
120+
echo "Already logged in to ${REGISTRY}"
121+
return 0
122+
fi
123+
124+
if [[ -z "${USERNAME:-}" || -z "${PASSWORD:-}" ]]; then
125+
log_fatal "Error: Not logged in to ${REGISTRY} and no credentials provided. Use --username and --password."
126+
fi
127+
128+
echo "Logging in to ${REGISTRY}..."
129+
echo "${PASSWORD}" | oras login "${REGISTRY}" --username "${USERNAME}" --password-stdin
130+
}
131+
132+
# Push kubectl binaries to registry
133+
push_artifacts() {
134+
echo "Pushing kubectl binaries to ${REPOSITORY} with tag ${TAG}"
135+
136+
# Check if artifacts directory exists
137+
if [[ ! -d "artifacts" ]]; then
138+
log_fatal "Error: artifacts directory not found"
139+
fi
140+
141+
# Create a combined tarball of all kubectl binaries
142+
echo "Creating combined tarball of all kubectl binaries..."
143+
local combined_tar="kubectl-$PLUGIN-all-platforms-${TAG}.tar.gz"
144+
145+
tar -czf "${combined_tar}" -C artifacts .
146+
147+
echo "Pushing combined tarball to ${REPOSITORY}:${TAG}"
148+
149+
oras push "${REPOSITORY}:${TAG}" \
150+
--artifact-type application/vnd.$PLUGIN.kubectl.bundle.v1+tar+gzip \
151+
"${combined_tar}"
152+
153+
rm -f "${combined_tar}"
154+
155+
echo "All kubectl binaries pushed successfully as a single bundle!"
156+
echo "Bundle available at: ${REPOSITORY}:${TAG}"
157+
}
158+
159+
# Pull kubectl binaries from registry
160+
pull_artifacts() {
161+
echo "Pulling kubectl binaries bundle from ${REPOSITORY} for release ${TAG}"
162+
163+
echo "Pulling kubectl bundle..."
164+
oras pull "${REPOSITORY}:${TAG}"
165+
166+
local bundle_tar="kubectl-$PLUGIN-all-platforms-${TAG}.tar.gz"
167+
168+
if [[ ! -f "$bundle_tar" ]]; then
169+
log_fatal "Error: Could not find kubectl bundle tarball"
170+
fi
171+
172+
echo "Extracting bundle to artifacts directory"
173+
174+
mkdir -p artifacts/
175+
tar -xzf "$bundle_tar" -C artifacts/
176+
rm -f "$bundle_tar"
177+
178+
echo "Contents of artifacts directory after extraction:"
179+
ls -la artifacts/
180+
181+
echo "All kubectl binaries pulled successfully!"
182+
}
183+
184+
main() {
185+
parse_args "$@"
186+
187+
if [[ "$NO_LOGIN" == false ]]; then
188+
login_registry
189+
fi
190+
191+
case "$ACTION" in
192+
push)
193+
push_artifacts
194+
;;
195+
pull)
196+
pull_artifacts
197+
;;
198+
esac
199+
}
200+
201+
main "$@"

scripts/staging/mirror-images.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env bash
2+
3+
# Mirror container images from source registry to target registry using crane.
4+
# Preserves multi-platform support and image digests.
5+
6+
set -euo pipefail
7+
8+
SCRIPT_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]:-"$0"}")")"
9+
ROOT_DIR="${SCRIPT_DIR}/../.."
10+
11+
# if PARENT_ROOT_DIR is not defined use the one below
12+
: "${PARENT_ROOT_DIR:=$ROOT_DIR}"
13+
14+
source "$ROOT_DIR/scripts/utils/log.sh"
15+
NO_RUN=true . "$PARENT_ROOT_DIR/scripts/release.sh"
16+
17+
IMAGES=()
18+
for name in $DEFAULT_IMAGES; do
19+
image=$($NIX_EVAL -f "$PARENT_ROOT_DIR" "images.$BUILD_TYPE.$name.imageName" --raw --quiet --argstr product_prefix "$PRODUCT_PREFIX")
20+
IMAGES+=("${image##*/}")
21+
done
22+
23+
SOURCE=""
24+
TARGET=""
25+
TAG=""
26+
27+
while [[ $# -gt 0 ]]; do
28+
case $1 in
29+
--source)
30+
SOURCE="$2"
31+
shift 2
32+
;;
33+
--target)
34+
TARGET="$2"
35+
shift 2
36+
;;
37+
--tag)
38+
TAG="$2"
39+
shift 2
40+
;;
41+
*)
42+
log_fatal "Unknown option: $1"
43+
;;
44+
esac
45+
done
46+
47+
if [[ -z "$SOURCE" ]] || [[ -z "$TARGET" ]] || [[ -z "$TAG" ]]; then
48+
log_fatal "Usage: $0 --source <source> --target <target> --tag <tag>"
49+
fi
50+
51+
echo "Mirroring images from ${SOURCE} to ${TARGET} with tag ${TAG}"
52+
53+
for IMAGE in "${IMAGES[@]}"; do
54+
echo "Mirroring ${IMAGE}:${TAG}..."
55+
56+
SRC="${SOURCE}/${IMAGE}:${TAG}"
57+
DEST="${TARGET}/${IMAGE}:${TAG}"
58+
crane copy --platform all "${SRC}" "${DEST}"
59+
60+
echo "✓ Successfully mirrored ${IMAGE}:${TAG}"
61+
done

scripts/staging/shell.nix

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{ pkgs ? import (import ../../nix/sources.nix).nixpkgs {
2+
overlays = [ (_: _: { inherit (import ../../nix/sources.nix); }) (import ../../nix/overlay.nix { }) ];
3+
}
4+
}:
5+
pkgs.mkShellNoCC {
6+
name = "staging-shell";
7+
buildInputs = with pkgs; [
8+
oras
9+
crane
10+
yq-go
11+
jq
12+
] ++ pkgs.lib.optional (builtins.getEnv "IN_NIX_SHELL" == "pure" && pkgs.system != "aarch64-darwin") [
13+
docker
14+
git
15+
curl
16+
nix
17+
kubernetes-helm-wrapped
18+
cacert
19+
];
20+
}

0 commit comments

Comments
 (0)