-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkpush
More file actions
executable file
·55 lines (44 loc) · 1.49 KB
/
kpush
File metadata and controls
executable file
·55 lines (44 loc) · 1.49 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
#!/usr/bin/env bash
set -euo pipefail
# Push an image to a remote k8s node
# Usage: kpush [-q] [-r host] [-T tarball] <image:tag>
# Examples:
# kpush myapp:1.0 Push to host from kubectl context
# kpush -r bigfish myapp:1.0 Push to specific host
# kpush -T image.tar myapp:1.0 Push from tarball instead of docker save
# kpush -q myapp:1.0 Quiet mode
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
readonly SCRIPT_DIR
source "$SCRIPT_DIR/lib.sh"
usage() {
sed -n '4,9p' "$0"
exit 0
}
quiet=false
host=""
tarball=""
while [[ $# -gt 0 && "$1" == -* ]]; do
case "$1" in
-h|--help) usage ;;
-q|--quiet) quiet=true; shift ;;
-r|--remote) require_optarg "$1" "${2:-}"; host="$2"; shift 2 ;;
-T|--tarball) require_optarg "$1" "${2:-}"; tarball="$2"; shift 2 ;;
*) echo "Unknown option: $1" >&2; exit 1 ;;
esac
done
readonly IMAGE="${1:?Usage: kpush [-q] [-r host] [-T tarball] <image:tag>}"
[[ -z "$host" ]] && host=$(resolve_host)
require_host "$host" || exit 1
ctr_cmd=$(ctr_import_cmd)
if [[ -n "$tarball" && ! -f "$tarball" ]]; then
echo "error: tarball not found: $tarball" >&2
exit 1
fi
$quiet || echo -n " Pushing image..." >&2
if [[ -n "$tarball" ]]; then
remote_exec "$host" "$ctr_cmd - >/dev/null 2>&1" < "$tarball"
else
docker save "$IMAGE" | remote_exec "$host" "$ctr_cmd - >/dev/null 2>&1" \
|| { echo "error: failed to save or push image '$IMAGE'" >&2; exit 1; }
fi
$quiet || echo " done" >&2