Skip to content

feat: add the GitHub action to create a Docker image and push to Docker Registry #1

feat: add the GitHub action to create a Docker image and push to Docker Registry

feat: add the GitHub action to create a Docker image and push to Docker Registry #1

Workflow file for this run

name: Build and Push Docker Images
on:
schedule:
- cron: '0 0 1 *'* # Run monthly on the 1st

Check failure on line 4 in .github/workflows/docker-build.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/docker-build.yml

Invalid workflow file

You have an error in your yaml syntax on line 4
workflow_dispatch: # Allow manual triggers
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
TAG_DATE: ${{ format('{0}{1}{2}', github.event.repository.pushed_at.substring(0,4), github.event.repository.pushed_at.substring(5,7), github.event.repository.pushed_at.substring(8,10)) }}
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set current date
id: date
run: echo "DATE=$(date +'%Y%m%d')" >> $GITHUB_ENV
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest
type=raw,value=${{ env.DATE }}
- name: Build and push regular image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Build and push Alpine image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile-alpine
push: true
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:alpine
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:alpine-${{ env.DATE }}
labels: ${{ steps.meta.outputs.labels }}