Skip to content

Commit

Permalink
refactor(ci-cd): define reusable workflows for pushing images to ghcr…
Browse files Browse the repository at this point in the history
… and docker hub
  • Loading branch information
WarriorsSami committed Sep 18, 2024
1 parent 9b450bd commit 3555496
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/step-deploy-to-docker-hub.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: "Step - Push Docker image to Docker Hub Registry"

on:
workflow_call:
inputs:
namespace:
type: string
required: true
repository:
type: string
required: true
build_context:
type: string
required: true

jobs:
deploy:
name: "Deploy to Docker Hub"
runs-on: ubuntu-latest

permissions:
contents: read
packages: write

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ inputs.namespace }}/${{ inputs.repository }}

- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: ${{ inputs.build_context }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
47 changes: 47 additions & 0 deletions .github/workflows/step-deploy-to-ghcr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: "Step - Push Docker image to GitHub Container Registry (GHCR)"

on:
workflow_call:
inputs:
image_name:
type: string
required: true
build_context:
type: string
required: true

jobs:
deploy:
name: "Deploy to GHCR"
runs-on: ubuntu-latest

permissions:
contents: read
packages: write

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository_owner }}/${{ inputs.image_name }}
tags: |
type=semver,pattern={{version}}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: ${{ inputs.build_context }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

0 comments on commit 3555496

Please sign in to comment.