From 9154fd92169027cea35d57d765070b7ea4d1e534 Mon Sep 17 00:00:00 2001 From: "Ehsan.Asadi" Date: Tue, 30 Dec 2025 20:18:56 +0330 Subject: [PATCH] fix: install bun before reflex export to avoid network download failures - Pre-install bun with retry mechanism before reflex export - Add bun to PATH to ensure reflex can find it - Fixes connection reset errors during Docker build --- .woodpecker.yml | 85 +++++++++++++++++++++++++------------------------ Dockerfile | 12 +++++++ 2 files changed, 55 insertions(+), 42 deletions(-) diff --git a/.woodpecker.yml b/.woodpecker.yml index b557e3b..dcaf25f 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -1,51 +1,52 @@ +# Peikarband Platform - Woodpecker CI/CD Pipeline +# Harbor Registry: hub.peikarband.ir +# Best Practices Applied + steps: build: - image: docker:24-dind - environment: - DOCKER_BUILDKIT: 1 - commands: - - echo "🔨 Building Docker image..." - - docker buildx create --use --name builder || true - - docker buildx build \ - --platform linux/amd64 \ - --build-arg VERSION=${CI_COMMIT_SHA:0:8} \ - --build-arg BUILD_DATE=${CI_PIPELINE_CREATED} \ - --build-arg PYTHON_VERSION=3.11 \ - --build-arg NODE_VERSION=20 \ - --label org.opencontainers.image.created=${CI_PIPELINE_CREATED} \ - --label org.opencontainers.image.source=${CI_REPO_LINK} \ - --label org.opencontainers.image.url=${CI_REPO_LINK} \ - --label org.opencontainers.image.revision=${CI_COMMIT_SHA} \ - --label org.opencontainers.image.version=${CI_COMMIT_SHA:0:8} \ - --label org.opencontainers.image.title="Peikarband Landing" \ - --label org.opencontainers.image.description="Peikarband hosting platform landing page" \ - --tag hub.peikarband.ir/peikarband/landing:${CI_COMMIT_SHA:0:8} \ - --tag hub.peikarband.ir/peikarband/landing:latest \ - --load \ - --file Dockerfile \ - . - - echo "✅ Build completed" - volumes: - - /var/run/docker.sock:/var/run/docker.sock + image: woodpeckerci/plugin-docker-buildx + settings: + repo: hub.peikarband.ir/peikarband/landing + tags: + - latest + - ${CI_COMMIT_SHA:0:8} + dockerfile: Dockerfile + context: . + platforms: linux/amd64 + build_args: + - VERSION=${CI_COMMIT_SHA:0:8} + - BUILD_DATE=${CI_PIPELINE_CREATED} + - PYTHON_VERSION=3.11 + - NODE_VERSION=20 + labels: + - org.opencontainers.image.created=${CI_PIPELINE_CREATED} + - org.opencontainers.image.source=${CI_REPO_LINK} + - org.opencontainers.image.url=${CI_REPO_LINK} + - org.opencontainers.image.revision=${CI_COMMIT_SHA} + - org.opencontainers.image.version=${CI_COMMIT_SHA:0:8} + - org.opencontainers.image.title=Peikarband Landing + - org.opencontainers.image.description=Peikarband hosting platform landing page + cache: inline + provenance: true + push: false timeout: 30m when: event: [push, tag, manual] push: - image: docker:24-dind - environment: - DOCKER_BUILDKIT: 1 - commands: - - echo "📤 Pushing Docker image..." - - echo $${HARBOR_PASSWORD} | docker login hub.peikarband.ir -u $${HARBOR_USERNAME} --password-stdin - - docker push hub.peikarband.ir/peikarband/landing:${CI_COMMIT_SHA:0:8} - - docker push hub.peikarband.ir/peikarband/landing:latest - - echo "✅ Push completed" - secrets: - - HARBOR_USERNAME - - HARBOR_PASSWORD - volumes: - - /var/run/docker.sock:/var/run/docker.sock - timeout: 10m + image: woodpeckerci/plugin-docker-buildx + settings: + registry: hub.peikarband.ir + repo: hub.peikarband.ir/peikarband/landing + username: + from_secret: HARBOR_USERNAME + password: + from_secret: HARBOR_PASSWORD + tags: + - latest + - ${CI_COMMIT_SHA:0:8} + push: true + insecure: false + timeout: 30m when: event: [push, tag, manual] diff --git a/Dockerfile b/Dockerfile index 40ff487..8623fea 100644 --- a/Dockerfile +++ b/Dockerfile @@ -41,6 +41,17 @@ RUN curl -fsSL https://deb.nodesource.com/setup_${NODE_VERSION}.x | bash - \ && apt-get install -y --no-install-recommends nodejs \ && rm -rf /var/lib/apt/lists/* +# Install bun (required by Reflex for frontend build) +# Retry mechanism for network issues +RUN set -ex && \ + for i in 1 2 3 4 5; do \ + curl -fsSL https://bun.sh/install | bash && break || \ + (echo "Attempt $i failed, retrying in 5 seconds..." && sleep 5); \ + done || (echo "Failed to install bun after 5 attempts" && exit 1) + +# Add bun to PATH +ENV PATH="/root/.bun/bin:${PATH}" + # Copy only requirements first (for better layer caching) COPY requirements.txt . @@ -53,6 +64,7 @@ COPY --chown=root:root . . # Build and export Reflex app for production # Export creates .web directory with frontend static files +# bun is now pre-installed, so reflex export won't try to download it RUN python -m reflex export --no-zip # Aggressive cleanup to reduce layer size