Add Dockerfile and build script for multi-arch build
This commit is contained in:
35
Dockerfile
Normal file
35
Dockerfile
Normal file
@@ -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"]
|
||||
31
build-and-push.sh
Executable file
31
build-and-push.sh
Executable file
@@ -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"
|
||||
Reference in New Issue
Block a user