From 69c2290648213fde61b3aa28b93faba8ffdd42a3 Mon Sep 17 00:00:00 2001 From: wartana Date: Tue, 24 Feb 2026 22:58:01 +0800 Subject: [PATCH] Add Dockerfile and build script for multi-arch build --- Dockerfile | 35 +++++++++++++++++++++++++++++++++++ build-and-push.sh | 31 +++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 Dockerfile create mode 100755 build-and-push.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..29d1659 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,35 @@ +FROM alpine:latest + +# Install jq, curl and ca-certificates +RUN apk add --no-cache jq curl ca-certificates bash tar + +# Create a directory for speedtest +WORKDIR /app + +# Download the appropriate speedtest binary based on architecture +ARG TARGETARCH +# Download the appropriate speedtest binary based on architecture +RUN set -ex; \ + if [ "$TARGETARCH" = "amd64" ]; then \ + ARCH="x86_64"; \ + elif [ "$TARGETARCH" = "arm64" ]; then \ + ARCH="aarch64"; \ + elif [ "$TARGETARCH" = "arm" ]; then \ + ARCH="armhf"; \ + else \ + echo "Unsupported architecture: $TARGETARCH" && exit 1; \ + fi; \ + URL="https://install.speedtest.net/app/cli/ookla-speedtest-1.2.0-linux-${ARCH}.tgz"; \ + echo "Downloading speedtest from: $URL"; \ + curl -sSLo speedtest.tgz "$URL"; \ + tar zxvf speedtest.tgz speedtest; \ + rm speedtest.tgz; \ + mv speedtest /usr/local/bin/; \ + chmod +x /usr/local/bin/speedtest + +# Copy the script +COPY send-speedtest.sh /usr/local/bin/send-speedtest.sh +RUN chmod +x /usr/local/bin/send-speedtest.sh + +# Run the script by default +ENTRYPOINT ["/usr/local/bin/send-speedtest.sh"] diff --git a/build-and-push.sh b/build-and-push.sh new file mode 100755 index 0000000..6a3e437 --- /dev/null +++ b/build-and-push.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +set -e + +# Default to "latest" if no tag is provided +TAG=${1:-latest} +IMAGE_NAME="gitea.oncloud.my.id/wartana/speedtest-ookla" +FULL_IMAGE_NAME="${IMAGE_NAME}:${TAG}" + +echo "Building and pushing multi-architecture image: $FULL_IMAGE_NAME" + +# Ensure buildx is set up and create a new builder instance if one doesn't exist +if ! docker buildx ls | grep -q 'speedtest-builder'; then + echo "Creating new buildx builder instance..." + docker buildx create --name speedtest-builder --use +else + echo "Using existing buildx builder instance..." + docker buildx use speedtest-builder +fi + +# Boot up the builder +docker buildx inspect --bootstrap + +# Build and push the image for amd64, arm64, and arm/v7 (arm32) +docker buildx build \ + --platform linux/amd64,linux/arm64,linux/arm/v7 \ + -t "$FULL_IMAGE_NAME" \ + --push \ + . + +echo "Successfully built and pushed $FULL_IMAGE_NAME"