|
| 1 | +name: Publish AnythingLLM Docker image on Release (amd64 & arm64) |
| 2 | + |
| 3 | +concurrency: |
| 4 | + group: build-${{ github.ref }} |
| 5 | + cancel-in-progress: true |
| 6 | + |
| 7 | +on: |
| 8 | + release: |
| 9 | + types: [published] |
| 10 | + |
| 11 | +jobs: |
| 12 | + push_multi_platform_to_registries: |
| 13 | + name: Push Docker multi-platform image to multiple registries |
| 14 | + runs-on: ubuntu-latest |
| 15 | + permissions: |
| 16 | + packages: write |
| 17 | + contents: read |
| 18 | + steps: |
| 19 | + - name: Check out the repo |
| 20 | + uses: actions/checkout@v4 |
| 21 | + |
| 22 | + - name: Check if DockerHub build needed |
| 23 | + shell: bash |
| 24 | + run: | |
| 25 | + # Check if the secret for USERNAME is set (don't even check for the password) |
| 26 | + if [[ -z "${{ secrets.DOCKER_USERNAME }}" ]]; then |
| 27 | + echo "DockerHub build not needed" |
| 28 | + echo "enabled=false" >> $GITHUB_OUTPUT |
| 29 | + else |
| 30 | + echo "DockerHub build needed" |
| 31 | + echo "enabled=true" >> $GITHUB_OUTPUT |
| 32 | + fi |
| 33 | + id: dockerhub |
| 34 | + |
| 35 | + - name: Set up QEMU |
| 36 | + uses: docker/setup-qemu-action@v3 |
| 37 | + |
| 38 | + - name: Set up Docker Buildx |
| 39 | + uses: docker/setup-buildx-action@v3 |
| 40 | + |
| 41 | + - name: Log in to Docker Hub |
| 42 | + uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a |
| 43 | + # Only login to the Docker Hub if the repo is mintplex/anythingllm, to allow for forks to build on GHCR |
| 44 | + if: steps.dockerhub.outputs.enabled == 'true' |
| 45 | + with: |
| 46 | + username: ${{ secrets.DOCKER_USERNAME }} |
| 47 | + password: ${{ secrets.DOCKER_PASSWORD }} |
| 48 | + |
| 49 | + - name: Log in to the Container registry |
| 50 | + uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 |
| 51 | + with: |
| 52 | + registry: ghcr.io |
| 53 | + username: ${{ github.actor }} |
| 54 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 55 | + |
| 56 | + - name: Extract metadata (tags, labels) for Docker |
| 57 | + id: meta |
| 58 | + uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 |
| 59 | + with: |
| 60 | + images: | |
| 61 | + ${{ steps.dockerhub.outputs.enabled == 'true' && 'mintplexlabs/anythingllm' || '' }} |
| 62 | + ghcr.io/${{ github.repository }} |
| 63 | + tags: | |
| 64 | + type=semver,pattern={{version}} |
| 65 | + type=semver,pattern={{major}}.{{minor}} |
| 66 | +
|
| 67 | + - name: Build and push multi-platform Docker image |
| 68 | + uses: docker/build-push-action@v6 |
| 69 | + with: |
| 70 | + context: . |
| 71 | + file: ./docker/Dockerfile |
| 72 | + push: true |
| 73 | + sbom: true |
| 74 | + provenance: mode=max |
| 75 | + platforms: linux/amd64,linux/arm64 |
| 76 | + tags: ${{ steps.meta.outputs.tags }} |
| 77 | + labels: ${{ steps.meta.outputs.labels }} |
| 78 | + cache-from: type=gha |
| 79 | + cache-to: type=gha,mode=max |
| 80 | + |
| 81 | + # For Docker scout there are some intermediary reported CVEs which exists outside |
| 82 | + # of execution content or are unreachable by an attacker but exist in image. |
| 83 | + # We create VEX files for these so they don't show in scout summary. |
| 84 | + - name: Collect known and verified CVE exceptions |
| 85 | + id: cve-list |
| 86 | + run: | |
| 87 | + # Collect CVEs from filenames in vex folder |
| 88 | + CVE_NAMES="" |
| 89 | + for file in ./docker/vex/*.vex.json; do |
| 90 | + [ -e "$file" ] || continue |
| 91 | + filename=$(basename "$file") |
| 92 | + stripped_filename=${filename%.vex.json} |
| 93 | + CVE_NAMES+=" $stripped_filename" |
| 94 | + done |
| 95 | + echo "CVE_EXCEPTIONS=$CVE_NAMES" >> $GITHUB_OUTPUT |
| 96 | + shell: bash |
| 97 | + |
| 98 | + # About VEX attestations https://docs.docker.com/scout/explore/exceptions/ |
| 99 | + # Justifications https://github.com/openvex/spec/blob/main/OPENVEX-SPEC.md#status-justifications |
| 100 | + - name: Add VEX attestations |
| 101 | + env: |
| 102 | + CVE_EXCEPTIONS: ${{ steps.cve-list.outputs.CVE_EXCEPTIONS }} |
| 103 | + run: | |
| 104 | + echo $CVE_EXCEPTIONS |
| 105 | + curl -sSfL https://raw.githubusercontent.com/docker/scout-cli/main/install.sh | sh -s -- |
| 106 | + for cve in $CVE_EXCEPTIONS; do |
| 107 | + for tag in "${{ join(fromJSON(steps.meta.outputs.json).tags, ' ') }}"; do |
| 108 | + echo "Attaching VEX exception $cve to $tag" |
| 109 | + docker scout attestation add \ |
| 110 | + --file "./docker/vex/$cve.vex.json" \ |
| 111 | + --predicate-type https://openvex.dev/ns/v0.2.0 \ |
| 112 | + $tag |
| 113 | + done |
| 114 | + done |
| 115 | + shell: bash |
0 commit comments