name: Build & push flux-cd images
on:
  schedule:
    - cron: "0 0 * * *"
  pull_request:
  push:
    paths:
      - '.github/workflows/fluxcd-images.yaml'
      - 'oci/fluxcd/flux-cli/Dockerfile'
      - 'oci/fluxcd/flux-helm-controller/Dockerfile'
      - 'oci/fluxcd/flux-source-controller/Dockerfile'
      - 'oci/fluxcd/flux-kustomize-controller/Dockerfile'
      - 'oci/fluxcd/flux-notification-controller/Dockerfile'
      - 'oci/fluxcd/flux-image-automation-controller/Dockerfile'
      - 'oci/fluxcd/flux-image-reflector-controller/Dockerfile'
  workflow_dispatch:
    branches:
      - main

jobs:
  base-image:
    runs-on: ubuntu-latest
    name: Build alpine base image
    steps:
      - uses: actions/checkout@master

      - name: 'Artifact: build && push alpine with custom ca image'
        uses: aevea/action-kaniko@master
        with:
          registry: artifact.onwalk.net
          username: admin
          password: ${{ secrets.HELM_REPO_PASSWORD }}
          path: './oci/base/alpine'
          build_file: 'Dockerfile'
          image: base/alpine
          tag: latest
          cache: true
          cache_registry: cache
  flux-cli:
    name: Build flux-cli image
    runs-on: ubuntu-latest
    needs: [base-image]
    steps:
      - uses: actions/checkout@master

      - name: 'Artifact: build && push fluxcd/flux-cli image'
        uses: aevea/action-kaniko@master
        with:
          registry: artifact.onwalk.net
          username: admin
          password: ${{ secrets.HELM_REPO_PASSWORD }}
          path: oci/fluxcd/flux-cli/
          image: public/fluxcd/flux-cli
          tag: v0.31.3
          cache: true
          cache_registry: cache
  fluxcd-helm-controller:
    name: Build fluxcd-helm-controller image
    runs-on: ubuntu-latest
    needs: [base-image]
    steps:
      - uses: actions/checkout@master

      - name: 'Artifact: build && push fluxcd/helm-controller image'
        uses: aevea/action-kaniko@master
        with:
          registry: artifact.onwalk.net
          username: admin
          password: ${{ secrets.HELM_REPO_PASSWORD }}
          path: oci/fluxcd/flux-helm-controller/
          image: public/fluxcd/helm-controller
          tag: v0.31.1
          cache: true
          cache_registry: cache
  fluxcd-image-automation-controller:
    name: Build fluxcd-image-automation-controller image
    runs-on: ubuntu-latest
    needs: [base-image]
    steps:
      - uses: actions/checkout@master

      - name: 'Artifact: build && push fluxcd/image-automation-controller image'
        uses: aevea/action-kaniko@v0.10.0
        with:
          registry: artifact.onwalk.net
          username: admin
          password: ${{ secrets.HELM_REPO_PASSWORD }}
          path: oci/fluxcd/flux-image-automation-controller/
          image: public/fluxcd/image-automation-controller
          tag: v0.31.0
          cache: true
          cache_registry: cache
  flux-image-reflector-controller:
    name: Build flux-image-reflector-controller image
    runs-on: ubuntu-latest
    needs: [base-image]
    steps:
      - uses: actions/checkout@master

      - name: 'Artifact: build && push fluxcd/image-reflector-controller image'
        uses: aevea/action-kaniko@v0.10.0
        with:
          registry: artifact.onwalk.net
          username: admin
          password: ${{ secrets.HELM_REPO_PASSWORD }}
          path: oci/fluxcd/flux-image-reflector-controller/
          image: public/fluxcd/image-reflector-controller
          tag: v0.26.0
          cache: true
          cache_registry: cache
  flux-kustomize-controller:
    name: Build flux-kustomize-controller image
    runs-on: ubuntu-latest
    needs: [base-image]
    steps:
      - uses: actions/checkout@master

      - name: 'Artifact: build && push fluxcd/kustomize-controller image'
        uses: aevea/action-kaniko@v0.10.0
        with:
          registry: artifact.onwalk.net
          username: admin
          password: ${{ secrets.HELM_REPO_PASSWORD }}
          path: 'oci/fluxcd/flux-kustomize-controller/'
          image: public/fluxcd/kustomize-controller
          tag: v0.35.0
          cache: true
          cache_registry: cache
  flux-notification-controller:
    name: Build flux-notification-controller image
    runs-on: ubuntu-latest
    needs: [base-image]
    steps:
      - uses: actions/checkout@master

      - name: 'Artifact: build && push fluxcd/notification-controller image'
        uses: aevea/action-kaniko@v0.10.0
        with:
          registry: artifact.onwalk.net
          username: admin
          password: ${{ secrets.HELM_REPO_PASSWORD }}
          path: oci/fluxcd/flux-notification-controller/
          image: public/fluxcd/notification-controller
          tag: v0.33.0
          cache: true
          cache_registry: cache
  flux-source-controller:
    name: Build flux-source-controller image
    runs-on: ubuntu-latest
    needs: [base-image]
    steps:
      - uses: actions/checkout@master

      - name: 'Artifact: build && push fluxcd/source-controller image'
        uses: aevea/action-kaniko@v0.10.0
        with:
          registry: artifact.onwalk.net
          username: admin
          password: ${{ secrets.HELM_REPO_PASSWORD }}
          path: oci/fluxcd/flux-source-controller/
          image: public/fluxcd/source-controller
          tag: v0.36.0
          cache: true
          cache_registry: cache
