Docker Build Image from Repository #18
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Docker Build Image from Repository | |
on: | |
schedule: | |
- cron: "0 0 * * 0" | |
push: | |
branches: | |
- "*" | |
tags: | |
- "v*.*.*" | |
pull_request: | |
branches: | |
- "*" | |
workflow_dispatch: | |
env: | |
REGISTRY1: ghcr.io | |
REGISTRY2: docker.io | |
IMAGE_NAME1: ${{ github.repository }} | |
IMAGE_NAME2: ${{ vars.DOCKERHUB_REPO }} | |
jobs: | |
cleanup-untagged-images: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Delete all containers from package without tags | |
uses: actions/delete-package-versions@v5 | |
with: | |
package-name: ${{ vars.IMAGE_NAME }} | |
package-type: container | |
delete-only-untagged-versions: true | |
build-packages: | |
if: ${{ github.event_name != 'pull_request' }} | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Setup Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY1 }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Get & Set Container Metadata | |
id: meta-packages | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.REGISTRY1 }}/${{ env.IMAGE_NAME1 }} | |
- name: Build & Push | |
id: build-and-push-packages | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ${{ steps.meta-packages.outputs.tags }} | |
labels: ${{ steps.meta-packages.outputs.labels }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
build-docker: | |
if: ${{ github.event_name != 'pull_request' }} | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Setup Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY2 }} | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Get & Set Container Metadata | |
id: meta-packages | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.REGISTRY2 }}/${{ env.IMAGE_NAME2 }} | |
- name: Build & Push | |
id: build-and-push-packages | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ${{ steps.meta-packages.outputs.tags }} | |
labels: ${{ steps.meta-packages.outputs.labels }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max |