Skip to content

build and publish a Docker image #211

build and publish a Docker image

build and publish a Docker image #211

Workflow file for this run

name: build and publish a Docker image
on:
push:
workflow_dispatch:
schedule:
- cron: '0 0 * * *'
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Check if the base image changed
id: check
uses: cantorgymnasium/is-my-docker-parent-image-out-of-date@main
with:
my-image: ghcr.io/cantorgymnasium/caddy:main
parent-image: docker.io/library/caddy:2-alpine
- name: Log in to the Container registry
uses: docker/login-action@v3
if: github.event_name == 'push' || steps.check.outputs.out-of-date == 'true'
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v4
if: github.event_name == 'push' || steps.check.outputs.out-of-date == 'true'
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
if: github.event_name == 'push' || steps.check.outputs.out-of-date == 'true'
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}