name: ifconfig

on: push

jobs:
  release-ifconfig:
    runs-on: act_runner
    container:
      image: catthehacker/ubuntu:act-latest
    env:
      RUNNER_TOOL_CACHE: /toolcache
    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Set up QEMU
        uses: docker/setup-qemu-action@v2

      - name: Get Meta
        id: meta
        run: |
          repo_version="$(git describe --tags --always)"
          repo_version="${repo_version#v}"
          docker_org="${GITHUB_REPOSITORY%%/*}"
          repo_name="${GITHUB_REPOSITORY#*/}"
          repo_name="${repo_name#docker-}"
          docker_tag="${DOCKER_TAG:-latest}"
          docker_hub="${DOCKER_HUB:-docker.io}"
          printf 'DATE_TAG=%s\n' "$(date +'%y%m')" >> "$GITHUB_OUTPUT"
          printf 'REPO_VERSION=%s\n' "$repo_version" >> "$GITHUB_OUTPUT"
          printf 'DOCKER_ORG=%s\n' "$docker_org" >> "$GITHUB_OUTPUT"
          printf 'DOCKER_TAG=%s\n' "$docker_tag" >> "$GITHUB_OUTPUT"
          printf 'DOCKER_HUB=%s\n' "$docker_hub" >> "$GITHUB_OUTPUT"
          printf 'REPO_NAME=%s\n' "$repo_name" >> "$GITHUB_OUTPUT"
          printf '%s\n' "$docker_hub/$docker_org/$repo_name:$docker_tag"

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

      - name: Login to DockerHub
        uses: docker/login-action@v2
        with:
          password: ${{ secrets.DOCKER_TOKEN }}
          username: ${{ secrets.DOCKER_USERNAME }}
          registry: ${{ steps.meta.outputs.DOCKER_HUB }}

      - name: Build and push
        uses: docker/build-push-action@v4
        with:
          context: .
          file: ./Dockerfile
          platforms: |
            linux/amd64
            linux/arm64
          push: true
          build-args: |
            IMAGE_NAME=${{ steps.meta.outputs.REPO_NAME }}
            BUILD_DATE=$(date -u +'%Y%m%d%H%M')
            BUILD_VERSION=$(date -u +'%Y%m%d%H%M')
            GIT_COMMIT=${{ github.sha }}
            TIMEZONE=America/New_York
            LANGUAGE=en_US.UTF-8
            LICENSE=WTFPL
            TZ=America/New_York
          tags: |
            ${{ steps.meta.outputs.DOCKER_HUB }}/${{ steps.meta.outputs.DOCKER_ORG }}/${{ steps.meta.outputs.REPO_NAME }}:${{ steps.meta.outputs.DATE_TAG }}
            ${{ steps.meta.outputs.DOCKER_HUB }}/${{ steps.meta.outputs.DOCKER_ORG }}/${{ steps.meta.outputs.REPO_NAME }}:${{ steps.meta.outputs.DOCKER_TAG }}

