Skip to content

Docker Build and Publish #16

Docker Build and Publish

Docker Build and Publish #16

name: Docker Build and Publish
on:
schedule:
- cron: '0 0 * * 0'
push:
branches: [ "main" ]
paths-ignore:
- '**/README.md'
- '**/LICENSE'
pull_request:
branches: [ "main" ]
paths-ignore:
- '**/README.md'
- '**/LICENSE'
workflow_dispatch:
env:
IMAGE_NAME: ${{ github.repository }}
jobs:
# define job to build and publish docker image
build-and-push-docker-image:
name: Build Docker image and push to DockerHub
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v3
# https://github.com/docker/login-action
- name: Login to Docker Hub
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64
push: ${{ github.event_name != 'pull_request' }}
tags: docker.io/${{ env.IMAGE_NAME }}:latest
cache-from: type=gha
cache-to: type=gha,mode=max
# https://github.com/peter-evans/dockerhub-description
- name: Update repo description
if: github.event_name != 'pull_request'
uses: peter-evans/dockerhub-description@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
repository: sebkeller/caddy-dns-ovh
- name: Image digest
run: echo ${{ steps.build-and-push.outputs.digest }}