Skip to content

Commit

Permalink
Add Docker workflow for publishing Docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
viperadnan-git committed Feb 1, 2024
1 parent 611971d commit 2da2039
Show file tree
Hide file tree
Showing 3 changed files with 1,316 additions and 1 deletion.
96 changes: 96 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: Publish Docker image

on:
workflow_dispatch:
push:
branches:
- main
release:
types: [published]

env:
IMAGE_NAME: ${{ github.event.repository.name }}

jobs:
push-to-docker-hub:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v4

- name: Log in to Docker Hub
uses: docker/login-action@v3
if: github.event_name != 'pull_request'
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: ${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

- name: Update Docker Hub description
uses: peter-evans/dockerhub-description@v4
if: github.event_name != 'pull_request'
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
repository: ${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}

push-to-github-packages:
name: Push Docker image to GitHub Packages
runs-on: ubuntu-latest

env:
REGISTRY: ghcr.io

permissions:
contents: read
packages: write

steps:
- name: Check out the repo
uses: actions/checkout@v4

- name: Log in to GitHub Packages
uses: docker/login-action@v3
if: github.event_name != 'pull_request'
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ github.actor }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
node_modules/
package-lock.json
bun.lockb
build/
.env*
Loading

0 comments on commit 2da2039

Please sign in to comment.