name: Build & push base images
on:
  schedule:
    - cron: "0 0 * * *"
  pull_request:
  push:
    paths:
      - 'oci/base/alpine/Dockerfile'
      - 'oci/base/alpine-glibc/Dockerfile'
      - 'oci/base/alpine-awscli/Dockerfile'
      - 'oci/base/alpine-awscli-python3/Dockerfile'
      - 'oci/base/ubuntu/Dockerfile'
      - 'oci/base/debian/Dockerfile'
      - 'oci/base/debian-slim/Dockerfile'
      - '.github/workflows/base-images.yaml'
  workflow_dispatch:
    branches:
      - main

jobs:
  alpine:
    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

  debian:
    runs-on: ubuntu-latest
    name: Build debian 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/debian'
          build_file: 'Dockerfile' 
          image: base/debian
          tag: latest
          cache: true
          cache_registry: cache

  debian-slim:
    runs-on: ubuntu-latest
    name: Build debian-slim 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/debian-slim'
          build_file: 'Dockerfile' 
          image: base/debian-slim
          tag: latest
          cache: true
          cache_registry: cache

  ubuntu:
    runs-on: ubuntu-latest
    name: Build ubuntu 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/ubuntu'
          build_file: 'Dockerfile' 
          image: base/ubuntu
          tag: 22.04
          cache: true
          cache_registry: cache
  alpine-glibc:
    needs: [alpine]
    runs-on: ubuntu-latest
    name: Build alpine-glibc base image
    steps:
      - uses: actions/checkout@master

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

      - name: 'Artifact: build && push alpine-awscli image'
        uses: aevea/action-kaniko@master
        with:
          registry: artifact.onwalk.net
          username: admin 
          password: ${{ secrets.HELM_REPO_PASSWORD }}
          path: 'oci/base/alpine-awscli'
          build_file: 'Dockerfile'
          image: base/alpine-awscli
          tag: 2.6.1
          cache: true
          cache_registry: cache

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

      - name: 'Artifact: build && push alpine-awscli-python3 image'
        uses: aevea/action-kaniko@master
        with:
          registry: artifact.onwalk.net
          username: admin 
          password: ${{ secrets.HELM_REPO_PASSWORD }}
          path: 'oci/base/alpine-awscli-python3'
          build_file: 'Dockerfile'
          image: base/alpine-awscli-python3
          tag: latest
          cache: true
          cache_registry: cache
