---
name: build and push images

on:
  push:
    branches: ['main']

  # Run manually from the GitHub UI
  workflow_dispatch:

  # Run automatically on the 1st of every month at 00:00 UTC
  schedule:
    - cron: '0 0 1 * *'

jobs:
  build-and-push-image:
    runs-on: ubuntu-latest

    env:
      ALPINE_VERSION: 3.21

    steps:
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v2

      - name: Log in to DockerHub
        uses: docker/login-action@v2
        with:
          registry: reg.dev.krd
          username: ${{ secrets.HARBOR_PUBLIC_USER }}
          password: ${{ secrets.HARBOR_PUBLIC_TOKEN }}

      - name: Build and push Docker image
        uses: docker/build-push-action@v4
        with:
          push: true
          tags: reg.dev.krd/db-backup-s3/db-backup-s3:alpine-${{ env.ALPINE_VERSION }}
          build-args: |
            ALPINE_VERSION=${{ env.ALPINE_VERSION }}
