diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index dde5ce5..96b4966 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -1,38 +1,47 @@ -name: Docker Image CI +name: Docker Multi-Architecture Image CI on: push: - tags: - - v* + pull_request: -permissions: +permissions: packages: write - + env: APP_NAME: rdtclient DOCKER_FILE: ./Dockerfile - DOCKER_PLATFORMS: "linux/arm64/v8,linux/amd64" ENABLE_DOCKERHUB: 1 ENABLE_GHCR: 1 - + +concurrency: ${{ github.sha }} + jobs: - build: - - runs-on: ubuntu-latest - + strategy: + matrix: + config: + - arch: amd64 + runs-on: ubuntu-latest + platform: linux/amd64 + - arch: arm64 + runs-on: ubuntu-24.04-arm + platform: linux/arm64/v8 + runs-on: ${{ matrix.config.runs-on }} steps: - - name: Checkout Code - uses: actions/checkout@v3 - - - name: Docker Metadata action - id: meta - uses: docker/metadata-action@v4.3.0 - with: - images: | - ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.APP_NAME }} - ghcr.io/${{ secrets.DOCKERHUB_USERNAME }}/${{ env.APP_NAME }} - tags: | + - name: Checkout Code + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Docker Metadata action + id: meta + uses: docker/metadata-action@v5 + with: + images: | + ${{ github.ref_type == 'tag' && format('{0}/{1}', secrets.DOCKERHUB_USERNAME, env.APP_NAME) || ''}} + ghcr.io/${{ github.repository_owner }}/${{ env.APP_NAME }} + tags: | type=schedule type=ref,event=branch type=ref,event=pr @@ -40,59 +49,119 @@ jobs: type=semver,pattern={{major}}.{{minor}} type=semver,pattern={{major}} type=sha - # List of custom labels - # labels: # optional - - name: Docker Setup QEMU - uses: docker/setup-qemu-action@v2.1.0 - - - name: Docker Setup Buildx - uses: docker/setup-buildx-action@v2.5.0 - with: - buildkitd-flags: --debug - - - name: Docker Login - if: ${{ github.event_name != 'pull_request' && env.ENABLE_DOCKERHUB == 1 }} - uses: docker/login-action@v2.1.0 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Login to GHCR - if: ${{ github.event_name != 'pull_request' && env.ENABLE_GHCR == 1 }} - uses: docker/login-action@v2.1.0 - with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Build and push Docker images - uses: docker/build-push-action@v4.0.0 - with: - context: . - file: ${{ env.DOCKER_FILE }} - platforms: ${{ env.DOCKER_PLATFORMS }} - push: ${{ github.event_name != 'pull_request' }} - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} + - name: Build and save image + uses: docker/build-push-action@v5 + with: + context: . + file: ${{ env.DOCKER_FILE }} + platforms: ${{ matrix.config.platform }} + push: false + load: true + outputs: type=docker,dest=${{ runner.temp }}/${{ matrix.config.arch }}.tar + tags: ${{ env.APP_NAME }}:${{ github.sha }}-${{ matrix.config.arch }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha,scope=${{ matrix.config.arch }} + cache-to: type=gha,mode=max,scope=${{ matrix.config.arch }} - - name: Docker Hub Registry Description - if: ${{ env.ENABLE_DOCKERHUB == 1 }} - uses: peter-evans/dockerhub-description@v3.3.0 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - repository: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.APP_NAME }} - short-description: | - a web interface to manage your torrents on Real-Debrid, AllDebrid or Premiumize. - readme-filepath: ./README-DOCKER.md - - # - name: Github Registry Description - # if: ${{ env.ENABLE_GHCR == 1 }} - # uses: peter-evans/dockerhub-description@v3.3.0 - # with: - # username: ${{ github.repository_owner }} - # password: ${{ secrets.GITHUB_TOKEN }} - # short-description: | - # A web interface to manage your torrents on Real-Debrid, AllDebrid or Premiumize. - # readme-filepath: ./README-DOCKER.md + # Upload the tarball as an artifact + - name: Upload image tarball + uses: actions/upload-artifact@v4 + with: + name: image-${{ matrix.config.arch }} + path: ${{ runner.temp }}/${{ matrix.config.arch }}.tar + retention-days: 1 + + # Push to registries + push-images: + needs: build + runs-on: ubuntu-latest + if: ${{ github.event_name != 'pull_request' }} + steps: + - name: Download all image tarballs + uses: actions/download-artifact@v4 + with: + path: /tmp/images + pattern: image-* + merge-multiple: true + + - name: Docker Metadata action + id: meta + uses: docker/metadata-action@v5 + with: + images: | + ${{ github.ref_type == 'tag' && format('{0}/{1}', secrets.DOCKERHUB_USERNAME, env.APP_NAME) || ''}} + ghcr.io/${{ secrets.DOCKERHUB_USERNAME }}/${{ env.APP_NAME }} + tags: | + type=schedule + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=sha + + - name: Setup Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to DockerHub + if: ${{ env.ENABLE_DOCKERHUB == 1 }} + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Login to GHCR + if: ${{ env.ENABLE_GHCR == 1 }} + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Load images + run: | + docker load --input /tmp/images/amd64.tar + docker load --input /tmp/images/arm64.tar + + - name: Create and push manifests + run: | + # Process each tag + echo "${{ steps.meta.outputs.tags }}" | while read -r TAG; do + # Skip empty lines + [ -z "$TAG" ] && continue + + echo "Processing tag: $TAG" + + docker tag ${{ env.APP_NAME }}:${{ github.sha }}-amd64 $TAG-amd64 + docker tag ${{ env.APP_NAME }}:${{ github.sha }}-arm64 $TAG-arm64 + + docker push $TAG-arm64 + docker push $TAG-amd64 + + docker manifest create $TAG \ + $TAG-amd64 \ + $TAG-arm64 + + docker manifest push $TAG + done + + # Update Docker Hub description + update-description: + needs: push-images + runs-on: ubuntu-latest + if: ${{ github.event_name != 'pull_request' }} + steps: + - name: Checkout Code + uses: actions/checkout@v4 + + - name: Docker Hub Registry Description + if: ${{ env.ENABLE_DOCKERHUB == 1 }} + uses: peter-evans/dockerhub-description@v4 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + repository: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.APP_NAME }} + short-description: | + a web interface to manage your torrents on Real-Debrid, AllDebrid or Premiumize. + readme-filepath: ./README-DOCKER.md \ No newline at end of file