name: Docker Image CI

on:

  workflow_dispatch:
jobs:


  build-bochs-builder:
    runs-on: [ubuntu-latest]
    steps:

      - name: Free Disk Space (Ubuntu)
        uses: jlumbroso/free-disk-space@main
        with:
          tool-cache: false
          android: true
          dotnet: true
          haskell: true
          large-packages: true
          docker-images: true
          swap-storage: true

      - name: Checkout
        uses: actions/checkout@v4

      - name: Get short SHA
        id: short-sha
        uses: benjlevesque/short-sha@v2.2

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

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

      - name: Login to GHCR
        uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Build and Push - Bochs Builder
        uses: docker/build-push-action@v5
        with:
          context: .devcontainer
          platforms: linux/amd64,linux/arm64
          file: .devcontainer/Dockerfile
          target: bochs-builder
          push: true
          tags: ghcr.io/${{ github.repository }}/bochs-builder:${{ steps.short-sha.outputs.sha }}

  build-gcc-builder:
    runs-on: [ubuntu-latest]
    steps:

      - name: Free Disk Space (Ubuntu)
        uses: jlumbroso/free-disk-space@main
        with:
          tool-cache: false
          android: true
          dotnet: true
          haskell: true
          large-packages: true
          docker-images: true
          swap-storage: true
          
      - name: Checkout
        uses: actions/checkout@v4

      - name: Get short SHA
        id: short-sha
        uses: benjlevesque/short-sha@v2.2

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

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

      - name: Login to GHCR
        uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ github.repository_owner }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Build and Push - GCC Builder
        uses: docker/build-push-action@v5
        with:
          context: .devcontainer
          platforms: linux/amd64,linux/arm64
          file: .devcontainer/Dockerfile
          target: gcc-builder
          push: true
          tags: ghcr.io/${{ github.repository }}/gcc-builder:${{ steps.short-sha.outputs.sha }}

  build-devcontainer:
    runs-on: [ubuntu-latest]
    steps:

      - name: Free Disk Space (Ubuntu)
        uses: jlumbroso/free-disk-space@main
        with:
          tool-cache: false
          android: true
          dotnet: true
          haskell: true
          large-packages: true
          docker-images: true
          swap-storage: true

      - name: Checkout
        uses: actions/checkout@v4

      - name: Get short SHA
        id: short-sha
        uses: benjlevesque/short-sha@v2.2

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

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

      - name: Login to GHCR
        uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ github.repository_owner }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Build and Push - Devcontainer
        uses: docker/build-push-action@v5
        with:
          context: .devcontainer
          platforms: linux/amd64,linux/arm64
          file: .devcontainer/Dockerfile
          target: devcontainer
          push: true
          tags: ghcr.io/${{ github.repository }}/devcontainer:${{ steps.short-sha.outputs.sha }}

  build-devcontainer-webgui:
    runs-on: [ubuntu-latest]
    steps:

      - name: Free Disk Space (Ubuntu)
        uses: jlumbroso/free-disk-space@main
        with:
          tool-cache: false
          android: true
          dotnet: true
          haskell: true
          large-packages: true
          docker-images: true
          swap-storage: true

      - name: Checkout
        uses: actions/checkout@v4

      - name: Get short SHA
        id: short-sha
        uses: benjlevesque/short-sha@v2.2

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

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

      - name: Login to GHCR
        uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ github.repository_owner }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Build and Push - Devcontainer with WebGUI
        uses: docker/build-push-action@v5
        with:
          context: .devcontainer
          platforms: linux/amd64,linux/arm64
          file: .devcontainer/Dockerfile
          target: devcontainer-webgui
          push: true
          tags: ghcr.io/${{ github.repository }}/devcontainer-webgui:${{ steps.short-sha.outputs.sha }}
