Skip to content

Commit

Permalink
feat: Build images for forks (#108)
Browse files Browse the repository at this point in the history
Signed-off-by: Mriyam Tamuli <[email protected]>
  • Loading branch information
mbtamuli authored Jan 13, 2024
1 parent 2da2ca1 commit 1d90ef4
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 39 deletions.
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2
updates:
# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
60 changes: 60 additions & 0 deletions .github/workflows/images-build-and-push.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Create and publish the container image.

on:
push:
branches:
tags:

env:
BASE_REPOSITORY: warmmetal/csi-driver-image
BASE_DEFAULT_BRANCH: master
BASE_IMAGE_NAME: warmmetal/csi-image
FORK_IMAGE_NAME: ghcr.io/${{ github.repository }}

jobs:
build-and-push-image:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Login to Docker Hub
uses: docker/login-action@v3
if: github.repository == env.BASE_REPOSITORY
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Log in to the GitHub Container registry
uses: docker/login-action@v3
if: github.repository != env.BASE_REPOSITORY
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: |
name=${{ env.BASE_IMAGE_NAME }},enable=${{ github.repository == env.BASE_REPOSITORY }}
name=${{ env.FORK_IMAGE_NAME }},enable=${{ github.repository != env.BASE_REPOSITORY }}
tags: |
# set 'latest' tag for default branch
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', env.BASE_DEFAULT_BRANCH) }}
# set image tag based on GitHub release tag
type=semver,pattern={{version}},prefix=v
# set the image tag based on the branch
# https://github.com/docker/metadata-action/issues/247#issuecomment-1511259674
type=ref,event=branch,enable=${{ github.ref_name != env.BASE_DEFAULT_BRANCH }}
flavor: |
latest=false
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
27 changes: 27 additions & 0 deletions .github/workflows/images-cleanup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Delete old container images

on:
schedule:
- cron: "0 0 * * *" # Source: https://crontab.guru/every-day

permissions:
packages: write

env:
BASE_REPOSITORY: warmmetal/csi-driver-image

jobs:
clean-ghcr:
name: Delete old unused container images
runs-on: ubuntu-latest
steps:
- uses: actions/delete-package-versions@v4
if: github.repository != env.BASE_REPOSITORY
with:
owner: ${{ github.repository_owner }}
package-name: ${{ github.event.repository.name }}
package-type: 'container'
min-versions-to-keep: 1
# https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
# Ignore any semver or 'latest'
ignore-versions: '^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?|latest$'
39 changes: 0 additions & 39 deletions .github/workflows/images.yaml

This file was deleted.

0 comments on commit 1d90ef4

Please sign in to comment.