diff --git a/.github/workflows/binaries_dev.yml b/.github/workflows/binaries_dev.yml index a8c8502655..6f46bd10ae 100644 --- a/.github/workflows/binaries_dev.yml +++ b/.github/workflows/binaries_dev.yml @@ -8,38 +8,44 @@ on: - 'go.mod' - 'go.sum' - '.github/workflows/binaries_dev.yml' + workflow_dispatch: +# Let an in-progress dev build finish. A new push replaces only the pending +# run; cancelling mid-build left the dev release without assets. concurrency: group: binaries-dev-${{ github.ref }} - cancel-in-progress: true + cancel-in-progress: false permissions: contents: read jobs: - cleanup: - permissions: - contents: write # for mknejp/delete-release-assets to delete release assets + prepare: runs-on: ubuntu-latest - + outputs: + build_time: ${{ steps.build_time.outputs.value }} steps: + - name: Ref guard + if: github.ref != 'refs/heads/master' + env: + GH_REF: ${{ github.ref }} + run: | + echo "dev builds only publish from master (got $GH_REF)" >&2 + exit 1 - - name: Delete old release assets - uses: mknejp/delete-release-assets@v1 - continue-on-error: true - with: - token: ${{ github.token }} - tag: dev - fail-if-no-assets: false - assets: | - weed-* + - name: Set BUILD_TIME + id: build_time + run: | + echo "value=$(date -u +%Y%m%d-%H%M)" >> "$GITHUB_OUTPUT" build_dev_linux_windows: permissions: contents: write # for wangyoucao577/go-release-action to upload release assets - needs: cleanup + needs: prepare runs-on: ubuntu-latest + env: + BUILD_TIME: ${{ needs.prepare.outputs.build_time }} strategy: matrix: goos: [linux, windows] @@ -47,12 +53,13 @@ jobs: steps: + - name: Validate BUILD_TIME + run: | + : "${BUILD_TIME:?prepare output missing}" + - name: Check out code into the Go module directory uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v2 - - name: Set BUILD_TIME env - run: echo BUILD_TIME=$(date -u +%Y%m%d-%H%M) >> ${GITHUB_ENV} - - name: Go Release Binaries Large Disk uses: wangyoucao577/go-release-action@279495102627de7960cbc33434ab01a12bae144b # v1.22 with: @@ -89,8 +96,10 @@ jobs: build_dev_darwin: permissions: contents: write # for wangyoucao577/go-release-action to upload release assets - needs: build_dev_linux_windows + needs: [prepare, build_dev_linux_windows] runs-on: ubuntu-latest + env: + BUILD_TIME: ${{ needs.prepare.outputs.build_time }} strategy: matrix: goos: [darwin] @@ -98,12 +107,13 @@ jobs: steps: + - name: Validate BUILD_TIME + run: | + : "${BUILD_TIME:?prepare output missing}" + - name: Check out code into the Go module directory uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v2 - - name: Set BUILD_TIME env - run: echo BUILD_TIME=$(date -u +%Y%m%d-%H%M) >> ${GITHUB_ENV} - - name: Go Release Binaries Large Disk uses: wangyoucao577/go-release-action@279495102627de7960cbc33434ab01a12bae144b # v1.22 with: @@ -136,3 +146,79 @@ jobs: project_path: weed binary_name: weed-normal-disk asset_name: "weed-${{ env.BUILD_TIME }}-${{ matrix.goos }}-${{ matrix.goarch }}" + + prune: + needs: [prepare, build_dev_linux_windows, build_dev_darwin] + runs-on: ubuntu-latest + timeout-minutes: 15 + permissions: + contents: write + env: + BUILD_TIME: ${{ needs.prepare.outputs.build_time }} + RELEASE_TAG: dev + steps: + - name: Delete dev binaries from older builds + env: + GH_TOKEN: ${{ github.token }} + run: | + set -euo pipefail + + : "${BUILD_TIME:?BUILD_TIME is empty}" + case "$BUILD_TIME" in + [0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]) ;; + *) echo "Invalid BUILD_TIME: $BUILD_TIME" >&2; exit 1 ;; + esac + + release_tag="${RELEASE_TAG:-dev}" + if ! release_json=$(gh api "repos/$GITHUB_REPOSITORY/releases/tags/$release_tag" 2>&1); then + case "$release_json" in + *"Not Found"*) echo "No $release_tag release; nothing to prune"; exit 0 ;; + esac + echo "Release lookup failed: $release_json" >&2 + exit 1 + fi + release_id=$(jq -r '.id // empty' <<<"$release_json") + if [ -z "$release_id" ]; then + echo "Release lookup returned no id" >&2 + exit 1 + fi + + assets_file=$(mktemp) + trap 'rm -f "$assets_file"' EXIT + if ! gh api "repos/$GITHUB_REPOSITORY/releases/$release_id/assets" --paginate \ + --jq '.[] | select((.name | startswith("weed-large-disk-")) or (.name | test("^weed-[0-9]"))) | [.id, .name] | @tsv' \ + > "$assets_file"; then + echo "Failed to list release assets" >&2 + exit 1 + fi + + total=$(awk 'END{print NR+0}' "$assets_file") + matching=$(awk -v s="-$BUILD_TIME-" 'index($0,s){n++} END{print n+0}' "$assets_file") + if [ "$matching" -eq 0 ]; then + echo "No assets carry stamp $BUILD_TIME; refusing to prune" >&2 + exit 1 + fi + + build_key=${BUILD_TIME/-/} + kept=0; newer=0; deleted=0; gone=0; failed=0 + while IFS=$'\t' read -r id name || [ -n "${name:-}" ]; do + [ -n "${id:-}" ] || continue + case "$name" in + *"-$BUILD_TIME-"*) kept=$((kept+1)); continue ;; + esac + if [[ "$name" =~ -([0-9]{8})-([0-9]{4})- ]] && [ "${BASH_REMATCH[1]}${BASH_REMATCH[2]}" -gt "$build_key" ]; then + newer=$((newer+1)); continue + fi + if out=$(gh api -X DELETE "repos/$GITHUB_REPOSITORY/releases/assets/$id" &1); then + deleted=$((deleted+1)) + else + case "$out" in + *"Not Found"*) gone=$((gone+1)) ;; + *) failed=$((failed+1)); echo "Failed to delete asset $name ($id): $out" >&2 ;; + esac + fi + done < "$assets_file" + + [ "$((kept+newer+deleted+gone+failed))" -eq "$total" ] || { echo "Processed $((kept+newer+deleted+gone+failed)) of $total assets" >&2; exit 1; } + echo "Kept $kept assets from this build and $newer from newer builds; deleted $deleted older assets; $gone already gone; $failed failures" + [ "$failed" -eq 0 ] || { echo "::warning::prune: $failed deletions failed"; exit 1; } diff --git a/.github/workflows/rust_binaries_dev.yml b/.github/workflows/rust_binaries_dev.yml index c190338101..1ea3ba016c 100644 --- a/.github/workflows/rust_binaries_dev.yml +++ b/.github/workflows/rust_binaries_dev.yml @@ -7,32 +7,43 @@ on: - 'seaweed-volume/**' - 'seaweed-common/**' - '.github/workflows/rust_binaries_dev.yml' + workflow_dispatch: + +# Serialize dev builds of the shared "dev" release without cancelling a run. +concurrency: + group: rust-binaries-dev-${{ github.ref }} + cancel-in-progress: false permissions: contents: read jobs: - cleanup: - permissions: - contents: write + prepare: runs-on: ubuntu-latest + outputs: + build_time: ${{ steps.build_time.outputs.value }} steps: - - name: Delete old Rust volume dev assets - uses: mknejp/delete-release-assets@v1 - continue-on-error: true - with: - token: ${{ github.token }} - tag: dev - fail-if-no-assets: false - assets: | - weed-volume-* + - name: Ref guard + if: github.ref != 'refs/heads/master' + env: + GH_REF: ${{ github.ref }} + run: | + echo "dev builds only publish from master (got $GH_REF)" >&2 + exit 1 + + - name: Set BUILD_TIME + id: build_time + run: | + echo "value=$(date -u +%Y%m%d-%H%M)" >> "$GITHUB_OUTPUT" build-rust-volume-dev-linux: permissions: contents: write - needs: cleanup + needs: prepare runs-on: ubuntu-24.04 + env: + BUILD_TIME: ${{ needs.prepare.outputs.build_time }} strategy: matrix: include: @@ -40,6 +51,11 @@ jobs: asset_suffix: linux-amd64 steps: + + - name: Validate BUILD_TIME + run: | + : "${BUILD_TIME:?prepare output missing}" + - uses: actions/checkout@v7 - name: Install Rust toolchain @@ -57,9 +73,6 @@ jobs: restore-keys: | rust-dev-${{ matrix.target }}- - - name: Set BUILD_TIME - run: echo BUILD_TIME=$(date -u +%Y%m%d-%H%M) >> "$GITHUB_ENV" - - name: Build Rust volume server (large disk) env: SEAWEEDFS_COMMIT: ${{ github.sha }} @@ -96,8 +109,10 @@ jobs: build-rust-volume-dev-darwin: permissions: contents: write - needs: build-rust-volume-dev-linux + needs: [prepare, build-rust-volume-dev-linux] runs-on: macos-latest + env: + BUILD_TIME: ${{ needs.prepare.outputs.build_time }} strategy: matrix: include: @@ -107,6 +122,11 @@ jobs: asset_suffix: darwin-amd64 steps: + + - name: Validate BUILD_TIME + run: | + : "${BUILD_TIME:?prepare output missing}" + - uses: actions/checkout@v7 - name: Install Rust toolchain @@ -126,9 +146,6 @@ jobs: restore-keys: | rust-dev-${{ matrix.target }}- - - name: Set BUILD_TIME - run: echo BUILD_TIME=$(date -u +%Y%m%d-%H%M) >> "$GITHUB_ENV" - - name: Build Rust volume server (large disk) env: SEAWEEDFS_COMMIT: ${{ github.sha }} @@ -161,3 +178,79 @@ jobs: weed-volume-${{ env.BUILD_TIME }}-${{ matrix.asset_suffix }}.tar.gz env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + prune: + needs: [prepare, build-rust-volume-dev-linux, build-rust-volume-dev-darwin] + runs-on: ubuntu-latest + timeout-minutes: 15 + permissions: + contents: write + env: + BUILD_TIME: ${{ needs.prepare.outputs.build_time }} + RELEASE_TAG: dev + steps: + - name: Delete Rust dev binaries from older builds + env: + GH_TOKEN: ${{ github.token }} + run: | + set -euo pipefail + + : "${BUILD_TIME:?BUILD_TIME is empty}" + case "$BUILD_TIME" in + [0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]) ;; + *) echo "Invalid BUILD_TIME: $BUILD_TIME" >&2; exit 1 ;; + esac + + release_tag="${RELEASE_TAG:-dev}" + if ! release_json=$(gh api "repos/$GITHUB_REPOSITORY/releases/tags/$release_tag" 2>&1); then + case "$release_json" in + *"Not Found"*) echo "No $release_tag release; nothing to prune"; exit 0 ;; + esac + echo "Release lookup failed: $release_json" >&2 + exit 1 + fi + release_id=$(jq -r '.id // empty' <<<"$release_json") + if [ -z "$release_id" ]; then + echo "Release lookup returned no id" >&2 + exit 1 + fi + + assets_file=$(mktemp) + trap 'rm -f "$assets_file"' EXIT + if ! gh api "repos/$GITHUB_REPOSITORY/releases/$release_id/assets" --paginate \ + --jq '.[] | select(.name | startswith("weed-volume-")) | [.id, .name] | @tsv' \ + > "$assets_file"; then + echo "Failed to list release assets" >&2 + exit 1 + fi + + total=$(awk 'END{print NR+0}' "$assets_file") + matching=$(awk -v s="-$BUILD_TIME-" 'index($0,s){n++} END{print n+0}' "$assets_file") + if [ "$matching" -eq 0 ]; then + echo "No assets carry stamp $BUILD_TIME; refusing to prune" >&2 + exit 1 + fi + + build_key=${BUILD_TIME/-/} + kept=0; newer=0; deleted=0; gone=0; failed=0 + while IFS=$'\t' read -r id name || [ -n "${name:-}" ]; do + [ -n "${id:-}" ] || continue + case "$name" in + *"-$BUILD_TIME-"*) kept=$((kept+1)); continue ;; + esac + if [[ "$name" =~ -([0-9]{8})-([0-9]{4})- ]] && [ "${BASH_REMATCH[1]}${BASH_REMATCH[2]}" -gt "$build_key" ]; then + newer=$((newer+1)); continue + fi + if out=$(gh api -X DELETE "repos/$GITHUB_REPOSITORY/releases/assets/$id" &1); then + deleted=$((deleted+1)) + else + case "$out" in + *"Not Found"*) gone=$((gone+1)) ;; + *) failed=$((failed+1)); echo "Failed to delete asset $name ($id): $out" >&2 ;; + esac + fi + done < "$assets_file" + + [ "$((kept+newer+deleted+gone+failed))" -eq "$total" ] || { echo "Processed $((kept+newer+deleted+gone+failed)) of $total assets" >&2; exit 1; } + echo "Kept $kept assets from this build and $newer from newer builds; deleted $deleted older assets; $gone already gone; $failed failures" + [ "$failed" -eq 0 ] || { echo "::warning::prune: $failed deletions failed"; exit 1; } diff --git a/README.md b/README.md index a4b2d9421e..8f7931d11b 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ Table of Contents * [Docker Compose](#docker-compose) * [Kubernetes with Helm](#kubernetes-with-helm) * [Build from source](#build-from-source) + * [Development builds](#development-builds) * [Scale out](#scale-out) * [Why SeaweedFS](#why-seaweedfs) * [Fast](#fast) @@ -175,6 +176,15 @@ cd seaweedfs/weed && make install `weed` lands in `$GOPATH/bin`. [Getting Started][GettingStarted] covers running master, volume, filer, and S3 as separate processes. +## Development builds ## + +Each dev build workflow publishes its latest successful build of `master`: + +- **Binaries**: the [`dev` release](https://github.com/seaweedfs/seaweedfs/releases/tag/dev) has Linux amd64, Windows amd64, and macOS amd64/arm64 archives named `weed---.tar.gz` (`.zip` on Windows) and `weed-large-disk---`, each with an `.md5` checksum. The Rust volume server is published there too as `weed-volume-*` for Linux amd64 (glibc) and macOS amd64/arm64. The Go archives contain `weed-normal-disk` or `weed-large-disk` (`.exe` on Windows) rather than `weed`, and the Rust archives contain `weed-volume-normal` or `weed-volume-large-disk` rather than `weed-volume`, so rename or symlink the one you want. The `.md5` files are published for the Go archives only. +- **Containers**: `docker pull chrislusf/seaweedfs:dev` or `ghcr.io/chrislusf/seaweedfs:dev`, built for `linux/amd64` and `linux/arm64`. The [dev compose file](docker/seaweedfs-dev-compose.yml) runs the Docker Hub image as master, volume, filer, S3, WebDAV, and admin. + +The timestamp in a binary name is the UTC start time of the run that built it. The Go binaries, the Rust volume server, and the `:dev` image come from three separate path-filtered workflows, so they can carry different timestamps and lag `master` by hours, or much longer when their paths were not touched. The release can list more than one timestamp for a while, for example after a failed or retried run; use the newest one for your platform. The `dev` release is marked pre-release, so it does not appear under [releases/latest](https://github.com/seaweedfs/seaweedfs/releases/latest); these builds come from `master`, can break at any commit, and are not recommended for production. + ## Scale out ## Capacity is a volume server. Start one on any machine with disk and point it at the master: diff --git a/docker/README.md b/docker/README.md index 731587ca19..fb599b3357 100644 --- a/docker/README.md +++ b/docker/README.md @@ -21,7 +21,9 @@ docker compose -f seaweedfs-compose.yml -p seaweedfs up ``` -## Try latest tip +## Try the latest development image + +The compose file below uses `chrislusf/seaweedfs:dev`, built from `master`. It is a development image, not a stable release, and can lag `master` by hours or more; the `org.opencontainers.image.revision` label records the commit it was built from, and pinning by digest keeps that exact build. See [Development builds](../README.md#development-builds) for the `dev` binaries and image details. ```bash