diff --git a/.github/workflows/beta-docker.yml b/.github/workflows/beta-docker.yml index eb932b0..0626ee6 100644 --- a/.github/workflows/beta-docker.yml +++ b/.github/workflows/beta-docker.yml @@ -17,17 +17,14 @@ jobs: - name: Calculate beta version id: calculate_version run: | - # Get the latest tag LATEST_TAG=$(git tag | grep -v 'beta' | sort -V | tail -n1) echo "Found latest tag: ${LATEST_TAG}" - # Split the version IFS='.' read -r -a VERSION_PARTS <<< "$LATEST_TAG" MAJOR="${VERSION_PARTS[0]}" MINOR="${VERSION_PARTS[1]}" PATCH="${VERSION_PARTS[2]}" - # Increment patch version NEW_PATCH=$((PATCH + 1)) BETA_VERSION="${MAJOR}.${MINOR}.${NEW_PATCH}" @@ -40,19 +37,45 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 + - name: Cache Docker layers + uses: actions/cache@v3 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + + # Login to Docker Hub - name: Login to Docker Hub uses: docker/login-action@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} + # Login to GitHub Container Registry + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Build and push beta Docker image uses: docker/build-push-action@v5 with: context: . platforms: linux/amd64,linux/arm64,linux/arm/v7 push: true - tags: cy01/blackhole:beta + tags: | + cy01/blackhole:beta + ghcr.io/${{ github.repository_owner }}/blackhole:beta + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max build-args: | VERSION=${{ env.beta_version }} - CHANNEL=beta \ No newline at end of file + CHANNEL=beta + + - name: Move cache + run: | + rm -rf /tmp/.buildx-cache + mv /tmp/.buildx-cache-new /tmp/.buildx-cache \ No newline at end of file diff --git a/.github/workflows/release-docker.yml b/.github/workflows/release-docker.yml index ef180fa..973558f 100644 --- a/.github/workflows/release-docker.yml +++ b/.github/workflows/release-docker.yml @@ -12,7 +12,7 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 with: - fetch-depth: 0 + fetch-depth: 1 - name: Get tag name id: get_tag @@ -26,12 +26,29 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 + - name: Cache Docker layers + uses: actions/cache@v3 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + + # Login to Docker Hub - name: Login to Docker Hub uses: docker/login-action@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} + # Login to GitHub Container Registry + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Build and push release Docker image uses: docker/build-push-action@v5 with: @@ -41,6 +58,15 @@ jobs: tags: | cy01/blackhole:latest cy01/blackhole:${{ env.tag_name }} + ghcr.io/${{ github.repository_owner }}/blackhole:latest + ghcr.io/${{ github.repository_owner }}/blackhole:${{ env.tag_name }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max build-args: | VERSION=${{ env.tag_name }} - CHANNEL=stable \ No newline at end of file + CHANNEL=stable + + - name: Move cache + run: | + rm -rf /tmp/.buildx-cache + mv /tmp/.buildx-cache-new /tmp/.buildx-cache \ No newline at end of file diff --git a/pkg/arr/arr.go b/pkg/arr/arr.go index 0075326..35ee8f9 100644 --- a/pkg/arr/arr.go +++ b/pkg/arr/arr.go @@ -3,6 +3,7 @@ package arr import ( "bytes" "encoding/json" + "fmt" "github.com/sirrobot01/debrid-blackhole/internal/config" "github.com/sirrobot01/debrid-blackhole/internal/request" "net/http" @@ -67,6 +68,20 @@ func (a *Arr) Request(method, endpoint string, payload interface{}) (*http.Respo return client.Do(req) } +func (a *Arr) Validate() error { + if a.Token == "" || a.Host == "" { + return nil + } + resp, err := a.Request("GET", "/api/v3/health", nil) + if err != nil { + return err + } + if resp.StatusCode != http.StatusOK { + return fmt.Errorf("arr test failed: %s", resp.Status) + } + return nil +} + type Storage struct { Arrs map[string]*Arr // name -> arr mu sync.RWMutex diff --git a/pkg/qbit/http.go b/pkg/qbit/http.go index 1c1fdb3..f58a10f 100644 --- a/pkg/qbit/http.go +++ b/pkg/qbit/http.go @@ -100,6 +100,16 @@ func HashesCtx(next http.Handler) http.Handler { } func (q *QBit) handleLogin(w http.ResponseWriter, r *http.Request) { + ctx := r.Context() + _arr := ctx.Value("arr").(*arr.Arr) + if _arr == nil { + // No arr + _, _ = w.Write([]byte("Ok.")) + return + } + if err := _arr.Validate(); err != nil { + q.logger.Info().Msgf("Error validating arr: %v", err) + } _, _ = w.Write([]byte("Ok.")) } diff --git a/pkg/qbit/routes.go b/pkg/qbit/routes.go index c992571..ca6f29a 100644 --- a/pkg/qbit/routes.go +++ b/pkg/qbit/routes.go @@ -8,10 +8,9 @@ import ( func (q *QBit) Routes() http.Handler { r := chi.NewRouter() r.Use(q.CategoryContext) - r.Post("/auth/login", q.handleLogin) - r.Group(func(r chi.Router) { r.Use(q.authContext) + r.Post("/auth/login", q.handleLogin) r.Route("/torrents", func(r chi.Router) { r.Use(HashesCtx) r.Get("/info", q.handleTorrentsInfo)