Skip to content

Commit 0a4e4cf

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

File tree

4 files changed

+448
-0
lines changed

4 files changed

+448
-0
lines changed

scripts/staging/kubectl-oci.sh

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
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+
source "$ROOT_DIR/utils/log.sh"
14+
15+
ACTION=""
16+
TAG=""
17+
NAMESPACE=""
18+
USERNAME=""
19+
PASSWORD=""
20+
REGISTRY="ghcr.io"
21+
PLUGIN="${PLUGIN:-"mayastor"}"
22+
23+
usage() {
24+
cat << EOF
25+
Usage: $0 <action> [options]
26+
27+
Actions:
28+
push Push kubectl binaries to $REGISTRY as OCI artifacts
29+
pull Pull kubectl binaries from $REGISTRY OCI artifacts
30+
31+
Options:
32+
--tag <tag> Release tag (required)
33+
--registry <registry> The registry to push/pull from [default=$REGISTRY]
34+
--namespace <namespace> Namespace path (required)
35+
--username <username> Registry username (required)
36+
--password <password> Registry token/password (required)
37+
38+
Examples:
39+
$0 push --tag v1.0.0 --namespace $PLUGIN/dev --username user --password token
40+
$0 pull --tag v1.0.0 --namespace $PLUGIN/dev --username user --password token
41+
EOF
42+
}
43+
44+
parse_args() {
45+
if [[ $# -lt 1 ]]; then
46+
usage
47+
log_fatal "Error: Action required (push or pull)"
48+
fi
49+
50+
ACTION="$1"
51+
shift
52+
53+
case "$ACTION" in
54+
push|pull)
55+
;;
56+
*)
57+
usage
58+
log_fatal "Error: Invalid action '$ACTION'. Must be 'push' or 'pull'"
59+
;;
60+
esac
61+
62+
while [[ $# -gt 0 ]]; do
63+
case $1 in
64+
--tag)
65+
TAG="$2"
66+
shift 2
67+
;;
68+
--namespace)
69+
NAMESPACE="$2"
70+
shift 2
71+
;;
72+
--registry)
73+
REGISTRY="$2"
74+
shift 2
75+
;;
76+
--username)
77+
USERNAME="$2"
78+
shift 2
79+
;;
80+
--password)
81+
PASSWORD="$2"
82+
shift 2
83+
;;
84+
-h|--help)
85+
usage
86+
exit 0
87+
;;
88+
*)
89+
usage
90+
log_fatal "Unknown option: $1"
91+
;;
92+
esac
93+
done
94+
95+
if [[ -z "$TAG" ]] || [[ -z "$NAMESPACE" ]] || [[ -z "$USERNAME" ]] || [[ -z "$PASSWORD" ]]; then
96+
usage
97+
log_fatal "Error: All options (--tag, --namespace, --username, --password) are required"
98+
fi
99+
100+
REPOSITORY=${REGISTRY}/${NAMESPACE}/kubectl-${PLUGIN}
101+
}
102+
103+
# Login to registry
104+
login_registry() {
105+
echo "Logging in to ${REGISTRY}..."
106+
echo "${PASSWORD}" | oras login "${REGISTRY}" --username "${USERNAME}" --password-stdin
107+
}
108+
109+
# Push kubectl binaries to registry
110+
push_artifacts() {
111+
echo "Pushing kubectl binaries to ${REPOSITORY} with tag ${TAG}"
112+
113+
# Check if artifacts directory exists
114+
if [[ ! -d "artifacts" ]]; then
115+
log_fatal "Error: artifacts directory not found"
116+
fi
117+
118+
# Create a combined tarball of all kubectl binaries
119+
echo "Creating combined tarball of all kubectl binaries..."
120+
local combined_tar="kubectl-$PLUGIN-all-platforms-${TAG}.tar.gz"
121+
122+
tar -czf "${combined_tar}" -C artifacts .
123+
124+
echo "Pushing combined tarball to ${REPOSITORY}:${TAG}"
125+
126+
oras push "${REPOSITORY}:${TAG}" \
127+
--artifact-type application/vnd.$PLUGIN.kubectl.bundle.v1+tar+gzip \
128+
"${combined_tar}"
129+
130+
rm -f "${combined_tar}"
131+
132+
echo "✓ All kubectl binaries pushed successfully as a single bundle!"
133+
echo "Bundle available at: ${REPOSITORY}:${TAG}"
134+
}
135+
136+
# Pull kubectl binaries from registry
137+
pull_artifacts() {
138+
echo "Pulling kubectl binaries bundle from ${REPOSITORY} for release ${TAG}"
139+
140+
echo "Pulling kubectl bundle..."
141+
oras pull "${REPOSITORY}:${TAG}"
142+
143+
local bundle_tar="kubectl-$PLUGIN-all-platforms-${TAG}.tar.gz"
144+
145+
if [[ ! -f "$bundle_tar" ]]; then
146+
log_fatal "Error: Could not find kubectl bundle tarball"
147+
fi
148+
149+
echo "Extracting bundle to artifacts directory"
150+
151+
mkdir -p artifacts/
152+
tar -xzf "$bundle_tar" -C artifacts/
153+
rm -f "$bundle_tar"
154+
155+
echo "Contents of artifacts directory after extraction:"
156+
ls -la artifacts/
157+
158+
echo "✓ All kubectl binaries pulled successfully!"
159+
}
160+
161+
main() {
162+
parse_args "$@"
163+
login_registry
164+
165+
case "$ACTION" in
166+
push)
167+
push_artifacts
168+
;;
169+
pull)
170+
pull_artifacts
171+
;;
172+
esac
173+
}
174+
175+
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)