---
name: Dockle

on:
  push:
    branches:
      - master
      - develop
  pull_request:

jobs:
  dockle:
    runs-on: ubuntu-latest

    env:
      DOCKER_CONTENT_TRUST: 1
      DOCKLE_VERSION: 0.4.15

    steps:
      - uses: actions/checkout@v6.0.1

      - name: Download and install dockle v${{ env.DOCKLE_VERSION }}
        run: |
          set -eux
          curl -L -o dockle.deb "https://github.com/goodwithtech/dockle/releases/download/v${DOCKLE_VERSION}/dockle_${DOCKLE_VERSION}_Linux-64bit.deb"
          sudo dpkg -i dockle.deb

      - name: Build web image (docker build)
        run: |
          set -eux
          docker build -t "misskey-web:ci" .
          docker image ls

      - name: Mount tmpfs for Dockle tar
        env:
          TMPFS_SIZE: 8G
        run: |
          set -eux
          sudo mkdir -p /mnt/dockle-tmp
          sudo mount -t tmpfs -o size=${{ env.TMPFS_SIZE }} tmpfs /mnt/dockle-tmp
          free -h
          df -h

      - name: Save image tar into tmpfs
        run: |
          set -eux
          docker save misskey-web:ci -o /mnt/dockle-tmp/misskey-web.tar
          ls -lh /mnt/dockle-tmp/misskey-web.tar

      - name: Run Dockle Scan (tar input)
        run: |
          set -eux
          dockle --exit-code 1 --input /mnt/dockle-tmp/misskey-web.tar
