aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesus <heckyel@riseup.net>2023-09-25 09:51:35 +0800
committerJesus <heckyel@riseup.net>2023-09-25 09:51:35 +0800
commit288e0b0b247dceef67edd4983ce7271de97af6ee (patch)
treeada8ee53809fe80c321c0c7955f32e73e0e0c743
parentaa77d14f26da35b34ac160c56bdda483b550b3e8 (diff)
downloadhyperbola-docker-288e0b0b247dceef67edd4983ce7271de97af6ee.tar.lz
hyperbola-docker-288e0b0b247dceef67edd4983ce7271de97af6ee.tar.xz
hyperbola-docker-288e0b0b247dceef67edd4983ce7271de97af6ee.zip
Make script to building image to Docker Hub
-rw-r--r--.dockerignore4
-rw-r--r--Dockerfile-Hyperbola-v0315
-rw-r--r--Dockerfile.386 (renamed from Dockerfile-Hyperbola-v04)2
-rw-r--r--Dockerfile.amd6415
-rw-r--r--README.md20
-rw-r--r--make-hyperbola.sh134
6 files changed, 168 insertions, 22 deletions
diff --git a/.dockerignore b/.dockerignore
index 6a5b686..c5bae31 100644
--- a/.dockerignore
+++ b/.dockerignore
@@ -1,2 +1,4 @@
*
-!bootstrap.tar.gz \ No newline at end of file
+!bootstrap.tar.gz
+!hyperbola-bootstrap-x86_64.tar.gz
+!hyperbola-bootstrap-i686.tar.gz
diff --git a/Dockerfile-Hyperbola-v03 b/Dockerfile-Hyperbola-v03
deleted file mode 100644
index a32e2d1..0000000
--- a/Dockerfile-Hyperbola-v03
+++ /dev/null
@@ -1,15 +0,0 @@
-FROM scratch
-
-ADD bootstrap.tar.gz /
-
-RUN ldconfig
-
-RUN pacman-key --init && pacman-key --populate archlinux hyperbola
-
-RUN pacman -Su --noconfirm --noprogressbar --quiet gzip awk
-
-RUN pacman -Scc --noconfirm && paccache -r -k0
-
-ENV LANG en_US.UTF-8
-
-CMD ["/bin/bash"]
diff --git a/Dockerfile-Hyperbola-v04 b/Dockerfile.386
index 38c753d..73a35ae 100644
--- a/Dockerfile-Hyperbola-v04
+++ b/Dockerfile.386
@@ -1,6 +1,6 @@
FROM scratch
-ADD bootstrap.tar.gz /
+ADD hyperbola-bootstrap-i686.tar.gz /
RUN ldconfig
diff --git a/Dockerfile.amd64 b/Dockerfile.amd64
new file mode 100644
index 0000000..6e149bf
--- /dev/null
+++ b/Dockerfile.amd64
@@ -0,0 +1,15 @@
+FROM scratch
+
+ADD hyperbola-bootstrap-x86_64.tar.gz /
+
+RUN ldconfig
+
+RUN pacman-key --init && pacman-key --populate hyperbola
+
+RUN pacman -Suu --noconfirm --noprogressbar
+
+RUN pacman -Scc --noconfirm
+
+ENV LANG en_US.UTF-8
+
+CMD ["/bin/bash"]
diff --git a/README.md b/README.md
index 8196163..6a08b58 100644
--- a/README.md
+++ b/README.md
@@ -12,14 +12,24 @@ Usage
- `git clone` this repository and move to directory where you have cloned it.
- Generate bootstrap image with [hyperbola-bootstrap](https://git.sr.ht/~heckyel/hyperbola-bootstrap) or download file from [archive.fridu.us](https://archive.fridu.us/hyperbola/iso/)
-- Rename hyperbola-bootstrap to bootstrap.tar.gz image
+- Make sure you have `hyperbola-bootstrap-i686.tar.gz` or `hyperbola-bootstrap-x86_64.tar.gz` in the directory.
+- Build the image with a command like:
- mv -T hyperbola-bootstrap-x86_64.tar.gz bootstrap.tar.gz
+ docker build --no-cache --platform=linux/amd64 --tag rusian/hyperbola:v0.4.3-amd64 -f Dockerfile.amd64 .
+ docker build --no-cache --platform=linux/386 --tag rusian/hyperbola:v0.4.3-386 -f Dockerfile.386 .
-- Make sure you have my `Dockerfile`, `.dockerignore` and the `bootstrap.tar.gz` in one directory.
-- Build the image with a command like:
+- Optionally, you can use the provided **make-hyperbola.sh** script to build and push the images to Docker Hub, you can provide your username and password like environment variables or directly in the script.
+
+ export DOCKER_USERNAME="your_username"
+ export DOCKER_PASSWORD="your_password"
+
+- Run **make-hyperbola.sh**
+
+ bash make-hyperbola.sh
+
+- Clean environment variables
- docker build --tag hyperbola:v0.4.3 -f Dockerfile-Hyperbola-v04 .
+ unset DOCKER_USERNAME && unset DOCKER_PASSWORD
License
=======
diff --git a/make-hyperbola.sh b/make-hyperbola.sh
new file mode 100644
index 0000000..718c0f9
--- /dev/null
+++ b/make-hyperbola.sh
@@ -0,0 +1,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