# Copyright 2024 RustFS Team # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # Multi-purpose Ubuntu-based Dockerfile # Can be used as development environment or ubuntu runtime variant FROM ubuntu:22.04 # Build arguments for dynamic artifact download (when used as runtime) ARG VERSION="" ARG BUILD_TYPE="release" ARG TARGETARCH ENV LANG=C.UTF-8 ENV DEBIAN_FRONTEND=noninteractive # Use faster mirrors for better build performance RUN sed -i s@http://.*archive.ubuntu.com@http://repo.huaweicloud.com@g /etc/apt/sources.list # Install dependencies RUN apt-get clean && apt-get update && apt-get install -y \ wget \ git \ curl \ unzip \ gcc \ pkg-config \ libssl-dev \ lld \ libdbus-1-dev \ libwayland-dev \ libwebkit2gtk-4.1-dev \ libxdo-dev \ ca-certificates \ bash \ && rm -rf /var/lib/apt/lists/* # Install protoc RUN wget https://github.com/protocolbuffers/protobuf/releases/download/v31.1/protoc-31.1-linux-x86_64.zip \ && unzip protoc-31.1-linux-x86_64.zip -d protoc3 \ && mv protoc3/bin/* /usr/local/bin/ && chmod +x /usr/local/bin/protoc \ && mv protoc3/include/* /usr/local/include/ && rm -rf protoc-31.1-linux-x86_64.zip protoc3 # Install flatc RUN wget https://github.com/google/flatbuffers/releases/download/v25.2.10/Linux.flatc.binary.g++-13.zip \ && unzip Linux.flatc.binary.g++-13.zip \ && mv flatc /usr/local/bin/ && chmod +x /usr/local/bin/flatc && rm -rf Linux.flatc.binary.g++-13.zip # Install rust (for development use) RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y ENV PATH="/root/.cargo/bin:${PATH}" # Copy cargo config for Chinese users COPY .docker/cargo.config.toml /root/.cargo/config.toml # 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 && \ useradd -d /app -g rustfs -u 1000 -s /bin/bash rustfs WORKDIR /app # Create data directories RUN mkdir -p /data && chown -R rustfs:rustfs /data /app # Environment variables ENV RUSTFS_ACCESS_KEY=rustfsadmin \ RUSTFS_SECRET_KEY=rustfsadmin \ RUSTFS_ADDRESS=":9000" \ RUSTFS_CONSOLE_ENABLE=true \ RUSTFS_VOLUMES=/data \ RUST_LOG=warn EXPOSE 9000 # Health check (only if rustfs binary exists) HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ CMD if [ -f /usr/local/bin/rustfs ]; then wget --no-verbose --tries=1 --spider http://localhost:9000/health || exit 1; else exit 0; fi # Default command: if rustfs binary exists, run it; otherwise, keep container alive for development CMD if [ -f /usr/local/bin/rustfs ]; then \ echo "Starting RustFS server..."; \ exec /usr/local/bin/rustfs; \ else \ echo "Running in development mode..."; \ echo "RustFS source code should be mounted at /app"; \ exec bash -c "while true; do sleep 1; done"; \ fi