Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion .github/workflows/check-for-updates-and-update-dockerfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:

jobs:
check-version-updates:
name: Check for new versions
runs-on: ubuntu-latest
outputs:
unrar_version: ${{ steps.get_latest_unrar_version.outputs.version }}
Expand All @@ -33,8 +34,11 @@ jobs:
return release.data.tag_name.replace(/^v/, ''); // Remove 'v' prefix

update-dockerfile:
name: Update Dockerfile with new versions
runs-on: ubuntu-latest
needs: check-version-updates
outputs:
changed: ${{ steps.git_diff.outputs.changed }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -56,11 +60,48 @@ jobs:
echo "changed=true" >> $GITHUB_OUTPUT
fi

- name: Commit Dockerfile updates
- name: Upload updated Dockerfile
if: steps.git_diff.outputs.changed == 'true'
uses: actions/upload-artifact@v4
with:
name: updated-dockerfile
path: Dockerfile

commit-changes:
name: Commit and push Dockerfile changes
runs-on: ubuntu-latest
needs: [check-version-updates, update-dockerfile]
if: needs.update-dockerfile.outputs.changed == 'true'
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Download updated Dockerfile
uses: actions/download-artifact@v4
with:
name: updated-dockerfile

- name: Commit Dockerfile updates
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "[email protected]"
git add Dockerfile
git commit -m "Update Dockerfile ARG values: rar=${{ needs.check-version-updates.outputs.unrar_version }}, rar2fs=${{ needs.check-version-updates.outputs.rar2fs_version }}"
git push

trigger-build:
name: Trigger build workflow
runs-on: ubuntu-latest
needs: [check-version-updates, update-dockerfile, commit-changes]
if: needs.update-dockerfile.outputs.changed == 'true'
steps:
- name: Trigger build workflow
uses: actions/github-script@v7
with:
script: |
await github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'docker-build-and-publish.yaml',
ref: 'main'
});
110 changes: 71 additions & 39 deletions .github/workflows/docker-build-and-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,36 @@ on:
push:
branches:
- "main"
workflow_dispatch:

env:
ORGANIZATION: zimme
IMAGE_NAME: rar2fs

jobs:
docker:
prepare:
name: Prepare build metadata
runs-on: ubuntu-latest

outputs:
tag-latest: ${{ steps.set-tags.outputs.tag-latest }}
tag-detailed: ${{ steps.set-tags.outputs.tag-detailed }}
tag-ghcr-latest: ${{ steps.set-tags.outputs.tag-ghcr-latest }}
tag-ghcr-detailed: ${{ steps.set-tags.outputs.tag-ghcr-detailed }}
unrar-version: ${{ steps.extract-versions.outputs.unrar-version }}
rar2fs-version: ${{ steps.extract-versions.outputs.rar2fs-version }}
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker buildx
uses: docker/setup-buildx-action@v3

- name: Extract versions from Dockerfile
id: extract-versions
run: |
# Extract RUNTIME_IMAGE from ARG
RUNTIME_IMAGE=$(grep '^ARG RUNTIME_IMAGE=' Dockerfile | awk -F'=' '{print $2}' | tr -d ' ')
if [ -z "$RUNTIME_IMAGE" ]; then
echo "Error: RUNTIME_IMAGE not found in Dockerfile."
exit 1
fi
echo "RUNTIME_IMAGE=$RUNTIME_IMAGE" >> $GITHUB_ENV

# Extract base image name and version
BASE_IMAGE_NAME=$(echo $RUNTIME_IMAGE | cut -d':' -f1)
Expand All @@ -40,52 +42,55 @@ jobs:
echo "Error: Failed to parse BASE_IMAGE_NAME or BASE_IMAGE_VERSION."
exit 1
fi
echo "BASE_IMAGE_NAME=$BASE_IMAGE_NAME" >> $GITHUB_ENV
echo "BASE_IMAGE_VERSION=$BASE_IMAGE_VERSION" >> $GITHUB_ENV

# Extract UNRAR_VERSION from ARG
UNRAR_VERSION=$(grep '^ARG UNRAR_VERSION=' Dockerfile | awk -F'=' '{print $2}' | tr -d ' ')
if [ -z "$UNRAR_VERSION" ]; then
echo "Error: UNRAR_VERSION not found in Dockerfile."
exit 1
fi
echo "UNRAR_VERSION=$UNRAR_VERSION" >> $GITHUB_ENV

# Extract RAR2FS_VERSION from ARG
RAR2FS_VERSION=$(grep '^ARG RAR2FS_VERSION=' Dockerfile | awk -F'=' '{print $2}' | tr -d ' ')
if [ -z "$RAR2FS_VERSION" ]; then
echo "Error: RAR2FS_VERSION not found in Dockerfile."
exit 1
fi
echo "RAR2FS_VERSION=$RAR2FS_VERSION" >> $GITHUB_ENV

- name: Set Tag Variables
# Set outputs for use in other jobs
echo "unrar-version=$UNRAR_VERSION" >> $GITHUB_OUTPUT
echo "rar2fs-version=$RAR2FS_VERSION" >> $GITHUB_OUTPUT
echo "base-image-name=$BASE_IMAGE_NAME" >> $GITHUB_OUTPUT
echo "base-image-version=$BASE_IMAGE_VERSION" >> $GITHUB_OUTPUT

- name: Set tag variables
id: set-tags
run: |
# Define tag variables based on extracted and static environment variables
# Define tag variables based on extracted versions
TAG_LATEST="${ORGANIZATION}/${IMAGE_NAME}:latest"
TAG_DETAILED="${ORGANIZATION}/${IMAGE_NAME}:${RAR2FS_VERSION}-unrar${UNRAR_VERSION}-${BASE_IMAGE_NAME}${BASE_IMAGE_VERSION}"
TAG_DETAILED="${ORGANIZATION}/${IMAGE_NAME}:${{ steps.extract-versions.outputs.rar2fs-version }}-unrar${{ steps.extract-versions.outputs.unrar-version }}-${{ steps.extract-versions.outputs.base-image-name }}${{ steps.extract-versions.outputs.base-image-version }}"
TAG_GHCR_LATEST="ghcr.io/${TAG_LATEST}"
TAG_GHCR_DETAILED="ghcr.io/${TAG_DETAILED}"

# Export the detailed tags to be used in subsequent steps
echo "TAG_TEST=$TAG_TEST" >> $GITHUB_ENV
echo "TAG_LATEST=$TAG_LATEST" >> $GITHUB_ENV
echo "TAG_DETAILED=$TAG_DETAILED" >> $GITHUB_ENV
echo "TAG_GHCR_LATEST=$TAG_GHCR_LATEST" >> $GITHUB_ENV
echo "TAG_GHCR_DETAILED=$TAG_GHCR_DETAILED" >> $GITHUB_ENV
# Set outputs for use in other jobs
echo "tag-latest=$TAG_LATEST" >> $GITHUB_OUTPUT
echo "tag-detailed=$TAG_DETAILED" >> $GITHUB_OUTPUT
echo "tag-ghcr-latest=$TAG_GHCR_LATEST" >> $GITHUB_OUTPUT
echo "tag-ghcr-detailed=$TAG_GHCR_DETAILED" >> $GITHUB_OUTPUT

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
build-test:
name: Build and test Docker image
runs-on: ubuntu-latest
needs: prepare
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker buildx
uses: docker/setup-buildx-action@v3

- name: Build Docker image for testing
uses: docker/build-push-action@v6
Expand All @@ -95,11 +100,38 @@ jobs:
cache-to: type=gha,mode=max
load: true
tags: |
${{ env.TAG_LATEST }}
${{ needs.prepare.outputs.tag-latest }}

- name: Test Docker image
run: |
docker run --rm ${{ env.TAG_LATEST }} --version
docker run --rm ${{ needs.prepare.outputs.tag-latest }} --version

publish:
name: Publish Docker images
runs-on: ubuntu-latest
needs: [prepare, build-test]
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker buildx
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- 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 Docker images
uses: docker/build-push-action@v6
Expand All @@ -110,7 +142,7 @@ jobs:
platforms: linux/amd64,linux/arm64
push: true
tags: |
${{ env.TAG_LATEST }}
${{ env.TAG_DETAILED }}
${{ env.TAG_GHCR_LATEST }}
${{ env.TAG_GHCR_DETAILED }}
${{ needs.prepare.outputs.tag-latest }}
${{ needs.prepare.outputs.tag-detailed }}
${{ needs.prepare.outputs.tag-ghcr-latest }}
${{ needs.prepare.outputs.tag-ghcr-detailed }}