diff --git a/.github/workflows/build-and-push.yml b/.github/workflows/build-and-push.yml new file mode 100644 index 0000000..8d8ad91 --- /dev/null +++ b/.github/workflows/build-and-push.yml @@ -0,0 +1,49 @@ +# .github/workflows/build-and-push.yml +name: Build and Push Docker Image + +on: + push: + branches: + - main + - 'v*.*.*' + workflow_dispatch: + +jobs: + build-and-push: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract version + id: vars + run: | + if [ "${GITHUB_REF_TYPE}" == "tag" ]; then + VERSION=${GITHUB_REF_NAME#refs/tags/v} + else + VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo "0.0.0") + fi + echo "VERSION=${VERSION}" >> $GITHUB_ENV + + - name: Build and push Docker image + uses: docker/build-push-action@v4 + with: + context: . + push: true + tags: | + ghcr.io/heavybullets8/zfs-scrubber:latest + ghcr.io/heavybullets8/zfs-scrubber:${{ env.VERSION }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..71f672a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +# Dockerfile +FROM alpine:3.20 + +# Install ZFS utilities +RUN apk add --no-cache zfs + +# Copy the entrypoint script +COPY entrypoint.sh /entrypoint.sh + +# Make the script executable +RUN chmod +x /entrypoint.sh + +# Set the entrypoint +ENTRYPOINT ["/entrypoint.sh"] diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..2fb1b90 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +# entrypoint.sh +set -e + +if [ -z "$ZFS_POOL" ]; then + echo "Error: No ZFS_POOL specified. Exiting." + exit 1 +fi + +echo "Starting scrub on pool: $ZFS_POOL" + +if zpool scrub -w "$ZFS_POOL"; then + echo "Scrub failed on pool: $ZFS_POOL" + exit 1 +fi + +echo "Scrub completed on pool: $ZFS_POOL"