diff --git a/.drone.yml b/.drone.yml index aa6ba08..b3e6205 100644 --- a/.drone.yml +++ b/.drone.yml @@ -3,68 +3,81 @@ kind: pipeline type: docker name: default -# Platform specification for ARM64 runners +# ARM64 platform (for your Pi runner) platform: os: linux arch: arm64 +# Mount host Docker socket so steps can use Docker CLI +volumes: + - name: docker_sock + host: + path: /var/run/docker.sock + +workspace: + path: /drone/src + steps: - # Step 1: Check if Docker image for current version already exists + # Step 1: Check if image for the latest tag exists locally - name: check-version image: docker:24 - environment: - DOCKER_HOST: unix:///var/run/docker.sock + volumes: + - name: docker_sock + path: /var/run/docker.sock commands: - apk add --no-cache git - git fetch --tags - | - # Get the latest Git tag LATEST_TAG=$(git describe --tags --abbrev=0) echo "Latest Git tag: $LATEST_TAG" - - # Check if Docker image exists + if docker image inspect apps/homepage:$LATEST_TAG > /dev/null 2>&1; then - echo "Docker image apps/homepage:$LATEST_TAG already exists — skipping build" - exit 0 + echo "✅ Docker image apps/homepage:$LATEST_TAG already exists — skipping build" + exit 78 # tells Drone to stop pipeline gracefully else - echo "Docker image apps/homepage:$LATEST_TAG not found — building..." + echo "⚙️ Docker image apps/homepage:$LATEST_TAG not found — proceeding to build..." fi - # Step 2: Build Docker image with dynamic Git tag + # Step 2: Build Docker image (dynamic tag) - name: build-image image: docker:24 - environment: - DOCKER_HOST: unix:///var/run/docker.sock + volumes: + - name: docker_sock + path: /var/run/docker.sock commands: - - IMAGE_TAG=${DRONE_TAG:-latest} - - echo "Building Docker image apps/homepage:$IMAGE_TAG ..." - - docker build -t apps/homepage:$IMAGE_TAG . + - | + IMAGE_TAG=${DRONE_TAG:-latest} + echo "🔨 Building Docker image apps/homepage:$IMAGE_TAG ..." + docker build -t apps/homepage:$IMAGE_TAG . - # Step 3: Stop old container if exists + # Step 3: Stop old container (if exists) - name: stop-old image: docker:24 - environment: - DOCKER_HOST: unix:///var/run/docker.sock + volumes: + - name: docker_sock + path: /var/run/docker.sock commands: - - IMAGE_TAG=${DRONE_TAG:-latest} - - echo "Stopping old container..." - - docker rm -f homepage || true + - | + echo "🛑 Stopping old container..." + docker rm -f homepage || true - # Step 4: Run container with dynamic tag + # Step 4: Run container - name: run-container image: docker:24 - environment: - DOCKER_HOST: unix:///var/run/docker.sock + volumes: + - name: docker_sock + path: /var/run/docker.sock commands: - - IMAGE_TAG=${DRONE_TAG:-latest} - - echo "Starting container apps/homepage:$IMAGE_TAG ..." - - docker run -d \ + - | + IMAGE_TAG=${DRONE_TAG:-latest} + echo "🚀 Starting container apps/homepage:$IMAGE_TAG ..." + docker run -d \ --name homepage \ -p 3001:3000 \ -e NODE_ENV=production \ apps/homepage:$IMAGE_TAG -# Trigger pipeline on Git tags +# Trigger rules trigger: event: - push