blob: 718c0f97a6518f3e29b3d554ead7806f3843de48 (
plain)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
#!/bin/bash
# Default tag
default_tag="v0.4.3"
default_release="2023.09.25"
latest_tag="latest"
# Function to display help
show_help() {
echo "Usage: $0 [-t TAG] [-h]"
echo " -t TAG Specify the tag (default: $default_tag)"
echo " -r VERSION Specify the release version (default: $default_release)"
echo " -h Show this help"
}
# Process command line options
while getopts ":t:h" opt; do
case $opt in
r)
release="$OPTARG"
;;
t)
tag="$OPTARG"
;;
h)
show_help && exit 0
;;
\?)
echo "Invalid option: -$OPTARG" >&2
show_help && exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
show_help && exit 1
;;
esac
done
# Use default tag if not specified
tag="${tag:-$default_tag}"
# Use default release version if not specified
release="${release:-$default_release}"
# Working directory
script_dir="$(cd "$(dirname "$0")" && pwd)"
# Check if files exist in the current directory
if [[ ! -e "$script_dir/hyperbola-bootstrap-i686.tar.gz" || ! -e "$script_dir/hyperbola-bootstrap-x86_64.tar.gz" ]]; then
echo "Downloading files for version $release..."
# Download files from the provided link
wget -P "$script_dir" "https://archive.fridu.us/hyperbola/iso/$release/hyperbola-bootstrap-i686.tar.gz"
wget -P "$script_dir" "https://archive.fridu.us/hyperbola/iso/$release/hyperbola-bootstrap-x86_64.tar.gz"
echo "Files downloaded successfully for version $release."
else
echo "Files already exist in the current directory. No download is required."
fi
# Logout docker
docker logout > /dev/null 2>&1
# Prompt user for credentials
if [[ -z "$DOCKER_USERNAME" ]]; then
read -p "Enter your Docker Hub username: " DOCKER_USERNAME
fi
if [[ -z "$DOCKER_PASSWORD" ]]; then
read -sp "Enter your Docker Hub password: " DOCKER_PASSWORD
echo
fi
# Log in to Docker Hub
echo "$DOCKER_PASSWORD" | docker login --username "$DOCKER_USERNAME" --password-stdin
# Build the images
docker build --no-cache --platform=linux/amd64 --tag "$DOCKER_USERNAME/hyperbola:$tag-amd64" -f Dockerfile.amd64 .
docker build --no-cache --platform=linux/386 --tag "$DOCKER_USERNAME/hyperbola:$tag-386" -f Dockerfile.386 .
# Push the images to Docker Hub
docker push "$DOCKER_USERNAME/hyperbola:$tag-amd64"
docker push "$DOCKER_USERNAME/hyperbola:$tag-386"
# Create and push the manifest for the specified tag
docker manifest create "$DOCKER_USERNAME/hyperbola:$tag" \
--amend "$DOCKER_USERNAME/hyperbola:$tag-amd64" \
--amend "$DOCKER_USERNAME/hyperbola:$tag-386"
docker manifest push "$DOCKER_USERNAME/hyperbola:$tag"
# Create and push the manifest for "latest"
docker manifest create "$DOCKER_USERNAME/hyperbola:$latest_tag" \
--amend "$DOCKER_USERNAME/hyperbola:$tag-amd64" \
--amend "$DOCKER_USERNAME/hyperbola:$tag-386"
docker manifest push "$DOCKER_USERNAME/hyperbola:$latest_tag"
# Get the token
token=$(curl -s -H 'Content-Type: application/json' -X POST -H 'Content-Type: application/json' -d "{\"username\":\"$DOCKER_USERNAME\", \"password\":\"$DOCKER_PASSWORD\"}" "https://hub.docker.com/v2/users/login/" | jq -r .token)
# Function to perform a curl with retries
function curl_with_retry() {
local url="$1"
local retries=3 # Number of retries
local delay=5 # Delay between retries in seconds
for ((i = 0; i < retries; i++)); do
response=$(curl -s -X DELETE -H "Authorization: JWT $token" "$url")
if [ $? -eq 0 ]; then
echo "$response"
return 0
else
echo "Attempt $((i+1)) failed. Retrying in $delay seconds..."
sleep $delay
fi
done
echo "All attempts failed. Curl command with URL '$url' has failed."
return 1
}
# Delete tags on Docker Hub
if curl_with_retry "https://hub.docker.com/v2/repositories/$DOCKER_USERNAME/hyperbola/tags/$tag-amd64/"; then
echo "Tag $tag-amd64 deleted successfully."
else
echo "Failed to delete tag $tag-amd64."
fi
if curl_with_retry "https://hub.docker.com/v2/repositories/$DOCKER_USERNAME/hyperbola/tags/$tag-386/"; then
echo "Tag $tag-386 deleted successfully."
else
echo "Failed to delete tag $tag-386."
fi
|