Skip to content

Weekly Docker Hub Release #18

Weekly Docker Hub Release

Weekly Docker Hub Release #18

name: Weekly Docker Hub Release
on:
schedule:
- cron: '0 4 * * 0' # Every Sunday at 4 AM UTC
workflow_dispatch:
permissions:
contents: read
packages: read
env:
GHCR_IMAGE: ghcr.io/${{ github.repository }}
DOCKERHUB_IMAGE: fok666/gitlab-selfhosted-runner
jobs:
release-to-dockerhub:
name: Release ${{ matrix.profile }} to Docker Hub
runs-on: ubuntu-latest
strategy:
matrix:
profile: ['full', 'minimal', 'k8s', 'iac', 'iac-pwsh']
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to GitHub Container Registry
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Log in to Docker Hub
uses: docker/login-action@v4
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Fetch all tags for profile from GitHub Packages
id: fetch-tags
run: |
REPO_OWNER="$(echo ${{ github.repository }} | cut -d'/' -f1)"
REPO_NAME="$(echo ${{ github.repository }} | cut -d'/' -f2)"
# Fetch all package versions
TAGS=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github+json" \
"https://api.github.com/users/${REPO_OWNER}/packages/container/${REPO_NAME}/versions" | \
jq -r '[.[] | .metadata.container.tags[] | select(endswith("${{ matrix.profile }}"))] | unique | .[]')
echo "Found tags:"
echo "$TAGS"
# Save tags to file
echo "$TAGS" > tags.txt
- name: Pull and push all tags to Docker Hub
run: |
while IFS= read -r tag; do
if [ -n "$tag" ]; then
echo "Processing tag: $tag"
docker pull ${{ env.GHCR_IMAGE }}:${tag}
docker tag ${{ env.GHCR_IMAGE }}:${tag} ${{ env.DOCKERHUB_IMAGE }}:${tag}
docker push ${{ env.DOCKERHUB_IMAGE }}:${tag}
fi
done < tags.txt
- name: Push "latest" tag for full profile
if: matrix.profile == 'full'
run: |
docker pull ${{ env.GHCR_IMAGE }}:latest-full
docker tag ${{ env.GHCR_IMAGE }}:latest-full ${{ env.DOCKERHUB_IMAGE }}:latest
docker push ${{ env.DOCKERHUB_IMAGE }}:latest