feat: improve Docker build with version selection and remove fallback mechanism (#185)

- Add version input parameter to docker.yml workflow_dispatch
- Support main-latest, latest, dev-xxx, and specific version patterns
- Remove complex fallback mechanism from all Dockerfile variants
- Add clear error handling with helpful user guidance
- Create main-latest versions for development builds
- Ensure Docker builds require explicit VERSION parameter
- Update all Docker variants (production, alpine, ubuntu) consistently

This change solves the build dependency issue where Docker builds
could fail when expected binary artifacts don't exist, by providing
a clean version selection mechanism without unpredictable fallbacks.
This commit is contained in:
安正超
2025-07-12 11:09:44 +08:00
committed by GitHub
parent 99ca405279
commit a8fbced928
5 changed files with 232 additions and 93 deletions

View File

@@ -44,37 +44,62 @@ RUN wget https://github.com/google/flatbuffers/releases/download/v25.2.10/Linux.
&& mv flatc /usr/local/bin/ && chmod +x /usr/local/bin/flatc \
&& rm -rf Linux.flatc.binary.g++-13.zip
# Option A: Download pre-built binary (faster)
RUN if [ -n "$VERSION" ]; then \
# Map TARGETARCH to our naming convention
case "${TARGETARCH}" in \
amd64) ARCH="x86_64" ;; \
arm64) ARCH="aarch64" ;; \
*) echo "Unsupported architecture: ${TARGETARCH}" && exit 1 ;; \
esac; \
\
# Handle VERSION with potential dev- prefix using variable expansion
if [[ "$VERSION" == dev-* ]]; then \
DOWNLOAD_PATH="artifacts/rustfs/dev"; \
FILENAME="rustfs-linux-${ARCH}-dev-${VERSION#dev-}.zip"; \
else \
DOWNLOAD_PATH="artifacts/rustfs/release"; \
FILENAME="rustfs-linux-${ARCH}-v${VERSION}.zip"; \
fi; \
\
# Download the binary
DOWNLOAD_URL="https://dl.rustfs.com/${DOWNLOAD_PATH}/${FILENAME}"; \
echo "Downloading RustFS binary from: ${DOWNLOAD_URL}"; \
curl -Lo /tmp/rustfs.zip "${DOWNLOAD_URL}"; \
unzip -o /tmp/rustfs.zip -d /tmp; \
mv /tmp/rustfs /usr/local/bin/rustfs; \
chmod +x /usr/local/bin/rustfs; \
rm -rf /tmp/*; \
else \
echo "No VERSION provided, will build from source"; \
echo "Source build not yet implemented in Alpine variant"; \
# Download pre-built binary (VERSION is required)
RUN if [ -z "$VERSION" ]; then \
echo "❌ ERROR: VERSION build argument is required"; \
echo "Please provide VERSION (e.g., main-latest, latest, v1.0.0, dev-abc123)"; \
exit 1; \
fi
fi; \
\
# Map TARGETARCH to our naming convention
case "${TARGETARCH}" in \
amd64) ARCH="x86_64" ;; \
arm64) ARCH="aarch64" ;; \
*) echo "❌ Unsupported architecture: ${TARGETARCH}" && exit 1 ;; \
esac; \
\
# Handle VERSION with different patterns
if [[ "$VERSION" == "main-latest" ]]; then \
DOWNLOAD_PATH="artifacts/rustfs/dev"; \
FILENAME="rustfs-linux-${ARCH}-main-latest.zip"; \
elif [[ "$VERSION" == "latest" ]]; then \
DOWNLOAD_PATH="artifacts/rustfs/release"; \
FILENAME="rustfs-linux-${ARCH}-latest.zip"; \
elif [[ "$VERSION" == dev-* ]]; then \
DOWNLOAD_PATH="artifacts/rustfs/dev"; \
FILENAME="rustfs-linux-${ARCH}-dev-${VERSION#dev-}.zip"; \
else \
DOWNLOAD_PATH="artifacts/rustfs/release"; \
FILENAME="rustfs-linux-${ARCH}-v${VERSION}.zip"; \
fi; \
\
# Download the binary
DOWNLOAD_URL="https://dl.rustfs.com/${DOWNLOAD_PATH}/${FILENAME}"; \
echo "🔽 Downloading RustFS binary from: ${DOWNLOAD_URL}"; \
\
# Download with clear error handling
if ! curl -fsSL --connect-timeout 30 --max-time 120 -o /tmp/rustfs.zip "${DOWNLOAD_URL}"; then \
echo "❌ Failed to download binary from: ${DOWNLOAD_URL}"; \
echo "💡 Please ensure the binary exists or trigger a build first"; \
echo "💡 Available options:"; \
echo " - For main-latest: Push to main branch or run build workflow"; \
echo " - For latest: Create a release tag"; \
echo " - For dev-xxx: Run build workflow with specific commit"; \
exit 1; \
fi; \
\
# Extract binary
if ! unzip -o /tmp/rustfs.zip -d /tmp >/dev/null 2>&1; then \
echo "❌ Failed to extract downloaded binary"; \
exit 1; \
fi; \
\
# Install binary
mv /tmp/rustfs /usr/local/bin/rustfs; \
chmod +x /usr/local/bin/rustfs; \
rm -rf /tmp/*; \
\
echo "✅ Successfully downloaded and installed RustFS binary (${VERSION})"
# Final Alpine runtime image
FROM alpine:3.18

View File

@@ -63,38 +63,62 @@ ENV PATH="/root/.cargo/bin:${PATH}"
# Copy cargo config for Chinese users
COPY .docker/cargo.config.toml /root/.cargo/config.toml
# If VERSION is provided, download pre-built binary (for runtime use)
# Otherwise, this acts as a development environment
RUN if [ -n "$VERSION" ]; then \
# Map TARGETARCH to our naming convention
case "${TARGETARCH}" in \
amd64) ARCH="x86_64" ;; \
arm64) ARCH="aarch64" ;; \
*) echo "Unsupported architecture: ${TARGETARCH}" && exit 1 ;; \
esac; \
\
# Handle VERSION with potential dev- prefix using variable expansion
if [[ "$VERSION" == dev-* ]]; then \
DOWNLOAD_PATH="artifacts/rustfs/dev"; \
FILENAME="rustfs-linux-${ARCH}-dev-${VERSION#dev-}.zip"; \
else \
DOWNLOAD_PATH="artifacts/rustfs/release"; \
FILENAME="rustfs-linux-${ARCH}-v${VERSION}.zip"; \
fi; \
\
# Download the binary
DOWNLOAD_URL="https://dl.rustfs.com/${DOWNLOAD_PATH}/${FILENAME}"; \
echo "Downloading RustFS binary from: ${DOWNLOAD_URL}"; \
curl -Lo /tmp/rustfs.zip "${DOWNLOAD_URL}" || { \
echo "Failed to download, continuing as development environment"; \
}; \
if [ -f /tmp/rustfs.zip ]; then \
unzip -o /tmp/rustfs.zip -d /tmp; \
mv /tmp/rustfs /usr/local/bin/rustfs; \
chmod +x /usr/local/bin/rustfs; \
rm -rf /tmp/*; \
fi; \
fi
# Download pre-built binary (VERSION is required)
RUN if [ -z "$VERSION" ]; then \
echo "❌ ERROR: VERSION build argument is required"; \
echo "Please provide VERSION (e.g., main-latest, latest, v1.0.0, dev-abc123)"; \
exit 1; \
fi; \
\
# Map TARGETARCH to our naming convention
case "${TARGETARCH}" in \
amd64) ARCH="x86_64" ;; \
arm64) ARCH="aarch64" ;; \
*) echo "❌ Unsupported architecture: ${TARGETARCH}" && exit 1 ;; \
esac; \
\
# Handle VERSION with different patterns
if [[ "$VERSION" == "main-latest" ]]; then \
DOWNLOAD_PATH="artifacts/rustfs/dev"; \
FILENAME="rustfs-linux-${ARCH}-main-latest.zip"; \
elif [[ "$VERSION" == "latest" ]]; then \
DOWNLOAD_PATH="artifacts/rustfs/release"; \
FILENAME="rustfs-linux-${ARCH}-latest.zip"; \
elif [[ "$VERSION" == dev-* ]]; then \
DOWNLOAD_PATH="artifacts/rustfs/dev"; \
FILENAME="rustfs-linux-${ARCH}-dev-${VERSION#dev-}.zip"; \
else \
DOWNLOAD_PATH="artifacts/rustfs/release"; \
FILENAME="rustfs-linux-${ARCH}-v${VERSION}.zip"; \
fi; \
\
# Download the binary
DOWNLOAD_URL="https://dl.rustfs.com/${DOWNLOAD_PATH}/${FILENAME}"; \
echo "🔽 Downloading RustFS binary from: ${DOWNLOAD_URL}"; \
\
# Download with clear error handling
if ! curl -fsSL --connect-timeout 30 --max-time 120 -o /tmp/rustfs.zip "${DOWNLOAD_URL}"; then \
echo "❌ Failed to download binary from: ${DOWNLOAD_URL}"; \
echo "💡 Please ensure the binary exists or trigger a build first"; \
echo "💡 Available options:"; \
echo " - For main-latest: Push to main branch or run build workflow"; \
echo " - For latest: Create a release tag"; \
echo " - For dev-xxx: Run build workflow with specific commit"; \
exit 1; \
fi; \
\
# Extract binary
if ! unzip -o /tmp/rustfs.zip -d /tmp >/dev/null 2>&1; then \
echo "❌ Failed to extract downloaded binary"; \
exit 1; \
fi; \
\
# Install binary
mv /tmp/rustfs /usr/local/bin/rustfs; \
chmod +x /usr/local/bin/rustfs; \
rm -rf /tmp/*; \
\
echo "✅ Successfully downloaded and installed RustFS binary (${VERSION})"
# Create rustfs user for security
RUN groupadd -g 1000 rustfs && \

View File

@@ -383,6 +383,36 @@ jobs:
echo "✅ Latest version uploaded: $LATEST_FILE"
fi
# For development builds on main branch, also create a main-latest version
if [[ "$BUILD_TYPE" == "development" ]] && [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
# Extract platform and arch from package name
PACKAGE_NAME="${{ steps.package.outputs.package_name }}"
# Create main-latest version filename
# Convert from rustfs-linux-x86_64-dev-abc123 to rustfs-linux-x86_64-main-latest
MAIN_LATEST_NAME=$(echo "$PACKAGE_NAME" | sed 's/-dev-[a-f0-9]\{7\}$/-main-latest/')
MAIN_LATEST_FILE="${MAIN_LATEST_NAME}.zip"
# Copy the original file to main-latest version
cp "${{ steps.package.outputs.package_file }}" "$MAIN_LATEST_FILE"
# Upload the main-latest version
echo "Uploading main-latest version: $MAIN_LATEST_FILE to $OSS_PATH..."
$OSSUTIL_BIN cp "$MAIN_LATEST_FILE" "$OSS_PATH" --force
echo "✅ Main-latest version uploaded: $MAIN_LATEST_FILE"
# Also create a generic main-latest for Docker builds
if [[ "${{ matrix.platform }}" == "linux" ]]; then
DOCKER_MAIN_LATEST_NAME="rustfs-linux-${{ matrix.target == 'x86_64-unknown-linux-musl' && 'x86_64' || 'aarch64' }}-main-latest"
DOCKER_MAIN_LATEST_FILE="${DOCKER_MAIN_LATEST_NAME}.zip"
cp "${{ steps.package.outputs.package_file }}" "$DOCKER_MAIN_LATEST_FILE"
$OSSUTIL_BIN cp "$DOCKER_MAIN_LATEST_FILE" "$OSS_PATH" --force
echo "✅ Docker main-latest version uploaded: $DOCKER_MAIN_LATEST_FILE"
fi
fi
echo "✅ Upload completed successfully"
# Build summary

View File

@@ -55,6 +55,11 @@ on:
required: false
default: true
type: boolean
version:
description: "Version to build (latest, main-latest, or specific version like v1.0.0 or dev-abc123)"
required: false
default: "main-latest"
type: string
env:
CARGO_TERM_COLOR: always
@@ -102,7 +107,37 @@ jobs:
fi
# Determine build type and version
if [[ "${{ startsWith(github.ref, 'refs/tags/') }}" == "true" ]]; then
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]] && [[ -n "${{ github.event.inputs.version }}" ]]; then
# Manual trigger with version input
input_version="${{ github.event.inputs.version }}"
version="${input_version}"
case "$input_version" in
"latest")
build_type="release"
create_latest=true
echo "🚀 Docker manual build with latest version"
;;
"main-latest")
build_type="development"
version="main-latest"
echo "🛠️ Docker manual build with main-latest version"
;;
v*.*.*)
build_type="release"
create_latest=true
echo "📦 Docker manual build with specific release version: $input_version"
;;
dev-*)
build_type="development"
echo "🔧 Docker manual build with specific dev version: $input_version"
;;
*)
build_type="development"
echo "🔧 Docker manual build with custom version: $input_version"
;;
esac
elif [[ "${{ startsWith(github.ref, 'refs/tags/') }}" == "true" ]]; then
# Tag push - release or prerelease
tag_name="${GITHUB_REF#refs/tags/}"
version="${tag_name}"

View File

@@ -44,37 +44,62 @@ RUN wget https://github.com/google/flatbuffers/releases/download/v25.2.10/Linux.
&& mv flatc /usr/local/bin/ && chmod +x /usr/local/bin/flatc \
&& rm -rf Linux.flatc.binary.g++-13.zip
# Option A: Download pre-built binary (faster)
RUN if [ -n "$VERSION" ]; then \
# Map TARGETARCH to our naming convention
case "${TARGETARCH}" in \
amd64) ARCH="x86_64" ;; \
arm64) ARCH="aarch64" ;; \
*) echo "Unsupported architecture: ${TARGETARCH}" && exit 1 ;; \
esac; \
\
# Handle VERSION with potential dev- prefix using variable expansion
if [[ "$VERSION" == dev-* ]]; then \
DOWNLOAD_PATH="artifacts/rustfs/dev"; \
FILENAME="rustfs-linux-${ARCH}-dev-${VERSION#dev-}.zip"; \
else \
DOWNLOAD_PATH="artifacts/rustfs/release"; \
FILENAME="rustfs-linux-${ARCH}-v${VERSION}.zip"; \
fi; \
\
# Download the binary
DOWNLOAD_URL="https://dl.rustfs.com/${DOWNLOAD_PATH}/${FILENAME}"; \
echo "Downloading RustFS binary from: ${DOWNLOAD_URL}"; \
curl -Lo /tmp/rustfs.zip "${DOWNLOAD_URL}"; \
unzip -o /tmp/rustfs.zip -d /tmp; \
mv /tmp/rustfs /usr/local/bin/rustfs; \
chmod +x /usr/local/bin/rustfs; \
rm -rf /tmp/*; \
else \
echo "No VERSION provided, will build from source"; \
echo "Source build not yet implemented in Alpine variant"; \
# Download pre-built binary (VERSION is required)
RUN if [ -z "$VERSION" ]; then \
echo "❌ ERROR: VERSION build argument is required"; \
echo "Please provide VERSION (e.g., main-latest, latest, v1.0.0, dev-abc123)"; \
exit 1; \
fi
fi; \
\
# Map TARGETARCH to our naming convention
case "${TARGETARCH}" in \
amd64) ARCH="x86_64" ;; \
arm64) ARCH="aarch64" ;; \
*) echo "❌ Unsupported architecture: ${TARGETARCH}" && exit 1 ;; \
esac; \
\
# Handle VERSION with different patterns
if [[ "$VERSION" == "main-latest" ]]; then \
DOWNLOAD_PATH="artifacts/rustfs/dev"; \
FILENAME="rustfs-linux-${ARCH}-main-latest.zip"; \
elif [[ "$VERSION" == "latest" ]]; then \
DOWNLOAD_PATH="artifacts/rustfs/release"; \
FILENAME="rustfs-linux-${ARCH}-latest.zip"; \
elif [[ "$VERSION" == dev-* ]]; then \
DOWNLOAD_PATH="artifacts/rustfs/dev"; \
FILENAME="rustfs-linux-${ARCH}-dev-${VERSION#dev-}.zip"; \
else \
DOWNLOAD_PATH="artifacts/rustfs/release"; \
FILENAME="rustfs-linux-${ARCH}-v${VERSION}.zip"; \
fi; \
\
# Download the binary
DOWNLOAD_URL="https://dl.rustfs.com/${DOWNLOAD_PATH}/${FILENAME}"; \
echo "🔽 Downloading RustFS binary from: ${DOWNLOAD_URL}"; \
\
# Download with clear error handling
if ! curl -fsSL --connect-timeout 30 --max-time 120 -o /tmp/rustfs.zip "${DOWNLOAD_URL}"; then \
echo "❌ Failed to download binary from: ${DOWNLOAD_URL}"; \
echo "💡 Please ensure the binary exists or trigger a build first"; \
echo "💡 Available options:"; \
echo " - For main-latest: Push to main branch or run build workflow"; \
echo " - For latest: Create a release tag"; \
echo " - For dev-xxx: Run build workflow with specific commit"; \
exit 1; \
fi; \
\
# Extract binary
if ! unzip -o /tmp/rustfs.zip -d /tmp >/dev/null 2>&1; then \
echo "❌ Failed to extract downloaded binary"; \
exit 1; \
fi; \
\
# Install binary
mv /tmp/rustfs /usr/local/bin/rustfs; \
chmod +x /usr/local/bin/rustfs; \
rm -rf /tmp/*; \
\
echo "✅ Successfully downloaded and installed RustFS binary (${VERSION})"
# Final Alpine runtime image
FROM alpine:3.18