mirror of
https://github.com/BrenBroZAYT/gameyfin.git
synced 2026-06-16 00:30:02 +00:00
Also push image to ghcr.io/gameyfin/app
Use caching in Docker build Improve error handling
This commit is contained in:
@@ -0,0 +1,57 @@
|
|||||||
|
name: 'Docker Build and Push'
|
||||||
|
description: 'Builds and pushes Docker images to Docker Hub and GHCR with flexible tagging.'
|
||||||
|
runs:
|
||||||
|
using: 'composite'
|
||||||
|
steps:
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Log in to Docker Hub
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
username: ${{ inputs.dockerhub_username }}
|
||||||
|
password: ${{ inputs.dockerhub_token }}
|
||||||
|
|
||||||
|
- name: Log in to GitHub Container Registry
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: ghcr.io
|
||||||
|
username: ${{ inputs.ghcr_username }}
|
||||||
|
password: ${{ inputs.ghcr_token }}
|
||||||
|
|
||||||
|
- name: Build and push Docker image
|
||||||
|
uses: docker/build-push-action@v5
|
||||||
|
with:
|
||||||
|
context: ${{ inputs.context }}
|
||||||
|
file: ${{ inputs.dockerfile }}
|
||||||
|
platforms: ${{ inputs.platforms }}
|
||||||
|
push: true
|
||||||
|
tags: ${{ inputs.tags }}
|
||||||
|
cache-from: type=gha
|
||||||
|
cache-to: type=gha
|
||||||
|
|
||||||
|
inputs:
|
||||||
|
dockerhub_username:
|
||||||
|
required: true
|
||||||
|
description: 'Docker Hub username'
|
||||||
|
dockerhub_token:
|
||||||
|
required: true
|
||||||
|
description: 'Docker Hub token'
|
||||||
|
ghcr_username:
|
||||||
|
required: true
|
||||||
|
description: 'GHCR username'
|
||||||
|
ghcr_token:
|
||||||
|
required: true
|
||||||
|
description: 'GHCR token'
|
||||||
|
context:
|
||||||
|
required: true
|
||||||
|
description: 'Build context'
|
||||||
|
dockerfile:
|
||||||
|
required: true
|
||||||
|
description: 'Dockerfile path'
|
||||||
|
platforms:
|
||||||
|
required: true
|
||||||
|
description: 'Platforms to build for'
|
||||||
|
tags:
|
||||||
|
required: true
|
||||||
|
description: 'Comma-separated list of image tags'
|
||||||
@@ -9,6 +9,8 @@ jobs:
|
|||||||
delete-docker-tag:
|
delete-docker-tag:
|
||||||
if: startsWith(github.event.pull_request.head.ref, 'fix/')
|
if: startsWith(github.event.pull_request.head.ref, 'fix/')
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
packages: write
|
||||||
steps:
|
steps:
|
||||||
- name: Extract merged branch name
|
- name: Extract merged branch name
|
||||||
id: extract_branch
|
id: extract_branch
|
||||||
@@ -18,14 +20,50 @@ jobs:
|
|||||||
echo "tag=$TAG" >> $GITHUB_OUTPUT
|
echo "tag=$TAG" >> $GITHUB_OUTPUT
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
- name: Delete Docker tag from Docker Hub
|
- name: Delete image tag from Docker Hub
|
||||||
if: steps.extract_branch.outputs.tag != ''
|
if: steps.extract_branch.outputs.tag != ''
|
||||||
env:
|
env:
|
||||||
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
|
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
|
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
TAG: ${{ steps.extract_branch.outputs.tag }}
|
TAG: ${{ steps.extract_branch.outputs.tag }}
|
||||||
run: |
|
run: |
|
||||||
echo "Deleting Docker tag: $TAG"
|
echo "Deleting Docker tag from Docker Hub: $TAG"
|
||||||
curl -X DELETE -u "$DOCKERHUB_USERNAME:$DOCKERHUB_TOKEN" \
|
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" -X DELETE -u "$DOCKERHUB_USERNAME:$DOCKERHUB_TOKEN" \
|
||||||
"https://hub.docker.com/v2/repositories/grimsi/gameyfin/tags/$TAG/"
|
"https://hub.docker.com/v2/repositories/grimsi/gameyfin/tags/$TAG/")
|
||||||
|
if [ "$RESPONSE" != "204" ]; then
|
||||||
|
echo "Failed to delete Docker Hub tag: $TAG (HTTP $RESPONSE)" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
- name: Delete image tag from GHCR
|
||||||
|
if: steps.extract_branch.outputs.tag != ''
|
||||||
|
env:
|
||||||
|
GHCR_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
TAG: ${{ steps.extract_branch.outputs.tag }}
|
||||||
|
REPO: gameyfin/app
|
||||||
|
OWNER: ${{ github.repository_owner }}
|
||||||
|
run: |
|
||||||
|
echo "Deleting Docker tag from GHCR: $TAG"
|
||||||
|
# Get the package ID
|
||||||
|
PACKAGE_ID=$(curl -s -H "Authorization: Bearer $GHCR_TOKEN" \
|
||||||
|
"https://api.github.com/users/$OWNER/packages/container/$REPO" | jq -r '.id')
|
||||||
|
if [ "$PACKAGE_ID" = "null" ] || [ -z "$PACKAGE_ID" ]; then
|
||||||
|
echo "Failed to get GHCR package ID for $REPO" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
# Get the version ID for the tag
|
||||||
|
VERSION_ID=$(curl -s -H "Authorization: Bearer $GHCR_TOKEN" \
|
||||||
|
"https://api.github.com/users/$OWNER/packages/container/$REPO/versions" | jq -r ".[] | select(.metadata.container.tags[]? == \"$TAG\") | .id")
|
||||||
|
if [ -z "$VERSION_ID" ]; then
|
||||||
|
echo "Failed to find GHCR version for tag: $TAG" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
# Delete the version
|
||||||
|
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" -X DELETE -H "Authorization: Bearer $GHCR_TOKEN" \
|
||||||
|
"https://api.github.com/users/$OWNER/packages/container/$REPO/versions/$VERSION_ID")
|
||||||
|
if [ "$RESPONSE" != "204" ]; then
|
||||||
|
echo "Failed to delete GHCR tag: $TAG (HTTP $RESPONSE)" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
shell: bash
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
name: Build and Push Docker Image (develop)
|
name: Build and Push Docker Image
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
@@ -14,6 +14,8 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
build-and-push:
|
build-and-push:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
packages: write
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
@@ -29,20 +31,14 @@ jobs:
|
|||||||
GAMEYFIN_KEYSTORE_PASSWORD: ${{ secrets.GAMEYFIN_KEYSTORE_PASSWORD }}
|
GAMEYFIN_KEYSTORE_PASSWORD: ${{ secrets.GAMEYFIN_KEYSTORE_PASSWORD }}
|
||||||
run: ./gradlew clean build -Pvaadin.productionMode=true
|
run: ./gradlew clean build -Pvaadin.productionMode=true
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v3
|
|
||||||
|
|
||||||
- name: Log in to Docker Hub
|
|
||||||
uses: docker/login-action@v3
|
|
||||||
with:
|
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
||||||
|
|
||||||
- name: Build and push Docker image
|
- name: Build and push Docker image
|
||||||
uses: docker/build-push-action@v5
|
uses: ./.github/actions/docker-build-push
|
||||||
with:
|
with:
|
||||||
|
dockerhub_username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
|
dockerhub_token: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
|
ghcr_username: ${{ github.actor }}
|
||||||
|
ghcr_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
context: .
|
context: .
|
||||||
file: docker/Dockerfile
|
dockerfile: docker/Dockerfile
|
||||||
platforms: linux/arm64/v8,linux/amd64
|
platforms: linux/arm64/v8,linux/amd64
|
||||||
push: true
|
tags: grimsi/gameyfin:${{ inputs.image_tag || 'develop' }},ghcr.io/gameyfin/app:${{ inputs.image_tag || 'develop' }}
|
||||||
tags: grimsi/gameyfin:${{ inputs.image_tag || 'develop' }}
|
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
build-and-push:
|
build-and-push:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
packages: write
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
@@ -23,15 +25,6 @@ jobs:
|
|||||||
GAMEYFIN_KEYSTORE_PASSWORD: ${{ secrets.GAMEYFIN_KEYSTORE_PASSWORD }}
|
GAMEYFIN_KEYSTORE_PASSWORD: ${{ secrets.GAMEYFIN_KEYSTORE_PASSWORD }}
|
||||||
run: ./gradlew clean build -Pvaadin.productionMode=true
|
run: ./gradlew clean build -Pvaadin.productionMode=true
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v3
|
|
||||||
|
|
||||||
- name: Log in to Docker Hub
|
|
||||||
uses: docker/login-action@v3
|
|
||||||
with:
|
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
||||||
|
|
||||||
- name: Extract tag from branch name
|
- name: Extract tag from branch name
|
||||||
id: extract_tag
|
id: extract_tag
|
||||||
run: |
|
run: |
|
||||||
@@ -40,11 +33,13 @@ jobs:
|
|||||||
echo "tag=$TAG" >> $GITHUB_OUTPUT
|
echo "tag=$TAG" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: Build and push Docker image
|
- name: Build and push Docker image
|
||||||
uses: docker/build-push-action@v5
|
uses: ./.github/actions/docker-build-push
|
||||||
with:
|
with:
|
||||||
|
dockerhub_username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
|
dockerhub_token: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
|
ghcr_username: ${{ github.actor }}
|
||||||
|
ghcr_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
context: .
|
context: .
|
||||||
file: docker/Dockerfile
|
dockerfile: docker/Dockerfile
|
||||||
platforms: linux/arm64/v8,linux/amd64
|
platforms: linux/arm64/v8,linux/amd64
|
||||||
push: true
|
tags: grimsi/gameyfin:${{ steps.extract_tag.outputs.tag }},ghcr.io/gameyfin/app:${{ steps.extract_tag.outputs.tag }}
|
||||||
tags: grimsi/gameyfin:${{ steps.extract_tag.outputs.tag }}
|
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ jobs:
|
|||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Get version from build.gradle.kts if not provided
|
- name: Get version from build.gradle.kts if not provided
|
||||||
id: get_version
|
id: get_version
|
||||||
run: |
|
run: |
|
||||||
@@ -37,14 +38,17 @@ jobs:
|
|||||||
echo "release_version=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
|
echo "release_version=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
|
||||||
echo "RELEASE_VERSION=${{ github.event.inputs.version }}" >> $GITHUB_ENV
|
echo "RELEASE_VERSION=${{ github.event.inputs.version }}" >> $GITHUB_ENV
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Update version in build.gradle.kts
|
- name: Update version in build.gradle.kts
|
||||||
if: ${{ github.event.inputs.update_version }}
|
if: ${{ github.event.inputs.update_version }}
|
||||||
run: |
|
run: |
|
||||||
sed -i "s/^version = .*/version = \"$RELEASE_VERSION\"/" build.gradle.kts
|
sed -i "s/^version = .*/version = \"$RELEASE_VERSION\"/" build.gradle.kts
|
||||||
|
|
||||||
- name: Update version in app/package.json
|
- name: Update version in app/package.json
|
||||||
if: ${{ github.event.inputs.update_version }}
|
if: ${{ github.event.inputs.update_version }}
|
||||||
run: |
|
run: |
|
||||||
jq ".version = \"$RELEASE_VERSION\"" app/package.json > app/package.json.tmp && mv app/package.json.tmp app/package.json
|
jq ".version = \"$RELEASE_VERSION\"" app/package.json > app/package.json.tmp && mv app/package.json.tmp app/package.json
|
||||||
|
|
||||||
- name: Upload modified files
|
- name: Upload modified files
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
@@ -56,15 +60,19 @@ jobs:
|
|||||||
docker:
|
docker:
|
||||||
needs: setup
|
needs: setup
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
packages: write
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Download modified files
|
- name: Download modified files
|
||||||
uses: actions/download-artifact@v4
|
uses: actions/download-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: modified-files
|
name: modified-files
|
||||||
|
|
||||||
- name: Set up JDK 21
|
- name: Set up JDK 21
|
||||||
uses: actions/setup-java@v4
|
uses: actions/setup-java@v4
|
||||||
with:
|
with:
|
||||||
@@ -72,25 +80,39 @@ jobs:
|
|||||||
java-version: '21'
|
java-version: '21'
|
||||||
- name: Setup Gradle
|
- name: Setup Gradle
|
||||||
uses: gradle/actions/setup-gradle@v4
|
uses: gradle/actions/setup-gradle@v4
|
||||||
|
|
||||||
- name: Run production build
|
- name: Run production build
|
||||||
env:
|
env:
|
||||||
GAMEYFIN_KEYSTORE_PASSWORD: ${{ secrets.GAMEYFIN_KEYSTORE_PASSWORD }}
|
GAMEYFIN_KEYSTORE_PASSWORD: ${{ secrets.GAMEYFIN_KEYSTORE_PASSWORD }}
|
||||||
run: ./gradlew clean build -Pvaadin.productionMode=true
|
run: ./gradlew clean build -Pvaadin.productionMode=true
|
||||||
- name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v3
|
- name: Generate container image tags
|
||||||
- name: Log in to Docker Hub
|
id: docker_tags
|
||||||
uses: docker/login-action@v3
|
run: |
|
||||||
with:
|
VERSION="${{ needs.setup.outputs.release_version }}"
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
DOCKERHUB_TAGS="grimsi/gameyfin:$VERSION"
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
GHCR_TAGS="ghcr.io/gameyfin/app:$VERSION"
|
||||||
|
if [[ "$VERSION" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
|
||||||
|
MAJOR=${BASH_REMATCH[1]}
|
||||||
|
MINOR=${BASH_REMATCH[2]}
|
||||||
|
PATCH=${BASH_REMATCH[3]}
|
||||||
|
DOCKERHUB_TAGS="grimsi/gameyfin:latest,grimsi/gameyfin:$VERSION,grimsi/gameyfin:$MAJOR.$MINOR,grimsi/gameyfin:$MAJOR"
|
||||||
|
GHCR_TAGS="ghcr.io/gameyfin/app:latest,ghcr.io/gameyfin/app:$VERSION,ghcr.io/gameyfin/app:$MAJOR.$MINOR,ghcr.io/gameyfin/app:$MAJOR"
|
||||||
|
fi
|
||||||
|
TAGS="$DOCKERHUB_TAGS,$GHCR_TAGS"
|
||||||
|
echo "tags=$TAGS" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: Build and push Docker image
|
- name: Build and push Docker image
|
||||||
uses: docker/build-push-action@v5
|
uses: ./.github/actions/docker-build-push
|
||||||
with:
|
with:
|
||||||
|
dockerhub_username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
|
dockerhub_token: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
|
ghcr_username: ${{ github.actor }}
|
||||||
|
ghcr_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
context: .
|
context: .
|
||||||
file: docker/Dockerfile
|
dockerfile: docker/Dockerfile
|
||||||
platforms: linux/arm64/v8,linux/amd64
|
platforms: linux/arm64/v8,linux/amd64
|
||||||
push: true
|
tags: ${{ steps.docker_tags.outputs.tags }}
|
||||||
tags: grimsi/gameyfin:${{ needs.setup.outputs.release_version }}
|
|
||||||
|
|
||||||
plugin_api:
|
plugin_api:
|
||||||
needs: setup
|
needs: setup
|
||||||
@@ -100,17 +122,21 @@ jobs:
|
|||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Download modified files
|
- name: Download modified files
|
||||||
uses: actions/download-artifact@v4
|
uses: actions/download-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: modified-files
|
name: modified-files
|
||||||
|
|
||||||
- name: Set up JDK 21
|
- name: Set up JDK 21
|
||||||
uses: actions/setup-java@v4
|
uses: actions/setup-java@v4
|
||||||
with:
|
with:
|
||||||
distribution: 'temurin'
|
distribution: 'temurin'
|
||||||
java-version: '21'
|
java-version: '21'
|
||||||
|
|
||||||
- name: Setup Gradle
|
- name: Setup Gradle
|
||||||
uses: gradle/actions/setup-gradle@v4
|
uses: gradle/actions/setup-gradle@v4
|
||||||
|
|
||||||
- name: Build and push Plugin-API
|
- name: Build and push Plugin-API
|
||||||
run: ./gradlew publishAndReleaseToMavenCentral --no-configuration-cache
|
run: ./gradlew publishAndReleaseToMavenCentral --no-configuration-cache
|
||||||
env:
|
env:
|
||||||
@@ -127,16 +153,19 @@ jobs:
|
|||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Download modified files
|
- name: Download modified files
|
||||||
uses: actions/download-artifact@v4
|
uses: actions/download-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: modified-files
|
name: modified-files
|
||||||
|
|
||||||
- name: Commit version bump
|
- name: Commit version bump
|
||||||
if: ${{ github.event.inputs.update_version }}
|
if: ${{ github.event.inputs.update_version }}
|
||||||
uses: stefanzweifel/git-auto-commit-action@v6
|
uses: stefanzweifel/git-auto-commit-action@v6
|
||||||
with:
|
with:
|
||||||
commit_message: 'chore: release v${{ github.event.inputs.version }}'
|
commit_message: 'chore: release v${{ github.event.inputs.version }}'
|
||||||
tagging_message: v${{ github.event.inputs.version }}
|
tagging_message: v${{ github.event.inputs.version }}
|
||||||
|
|
||||||
- name: Detect prerelease
|
- name: Detect prerelease
|
||||||
id: detect_prerelease
|
id: detect_prerelease
|
||||||
run: |
|
run: |
|
||||||
@@ -147,6 +176,7 @@ jobs:
|
|||||||
echo "IS_PRERELEASE=true" >> $GITHUB_ENV
|
echo "IS_PRERELEASE=true" >> $GITHUB_ENV
|
||||||
echo "MAKE_LATEST=false" >> $GITHUB_ENV
|
echo "MAKE_LATEST=false" >> $GITHUB_ENV
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Create GitHub release
|
- name: Create GitHub release
|
||||||
if: ${{ github.event.inputs.update_version }}
|
if: ${{ github.event.inputs.update_version }}
|
||||||
uses: softprops/action-gh-release@v2
|
uses: softprops/action-gh-release@v2
|
||||||
|
|||||||
Reference in New Issue
Block a user