Skip to content

Update CI workflow permissions to include attestations for improved s… #36

Update CI workflow permissions to include attestations for improved s…

Update CI workflow permissions to include attestations for improved s… #36

Workflow file for this run

name: Lua Docker - Image CI
on:
push:
branches: [ main, image-attestation-and-ghcr ]
pull_request:
branches: [ main ]
# Add permissions needed for GitHub Container Registry
permissions:
contents: read
packages: write
attestations: write
id-token: write
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
lua-version: ['5.1.4', '5.2.3', '5.3.4', '5.4.7']
luarocks-version: ['3.11.1']
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Set image name variables
id: image_names
run: |
DOCKERHUB_IMAGE="evandarwin/lua"
# Convert GitHub repository owner to lowercase using tr
OWNER=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')
GHCR_IMAGE="ghcr.io/${OWNER}/lua"
echo "dockerhub_image=$DOCKERHUB_IMAGE" >> $GITHUB_OUTPUT
echo "ghcr_image=$GHCR_IMAGE" >> $GITHUB_OUTPUT
- name: Login to Docker Hub
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract version components
id: version
run: |
FULL_VERSION=${{ matrix.lua-version }}
MAJOR_VERSION=$(echo $FULL_VERSION | cut -d'.' -f1)
MAJOR_MINOR_VERSION=$(echo $FULL_VERSION | cut -d'.' -f1,2)
echo "full_version=$FULL_VERSION" >> $GITHUB_OUTPUT
echo "major_version=$MAJOR_VERSION" >> $GITHUB_OUTPUT
echo "major_minor_version=$MAJOR_MINOR_VERSION" >> $GITHUB_OUTPUT
- name: Install Syft for SBOM generation
run: |
curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b /usr/local/bin
- name: Extract metadata from Docker Hub
uses: docker/metadata-action@v4
with:
images: ${{ steps.image_names.outputs.dockerhub_image }},${{ steps.image_names.outputs.ghcr_image }}
- name: Build and push
id: push
uses: docker/build-push-action@v4
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: |
${{ steps.image_names.outputs.dockerhub_image }}:${{ steps.version.outputs.full_version }}
${{ steps.image_names.outputs.dockerhub_image }}:${{ steps.version.outputs.major_minor_version }}
${{ steps.image_names.outputs.dockerhub_image }}:${{ steps.version.outputs.major_version }}
${{ matrix.lua-version == '5.4.7' && format('{0}:latest', steps.image_names.outputs.dockerhub_image) || '' }}
${{ steps.image_names.outputs.ghcr_image }}:${{ steps.version.outputs.full_version }}
${{ steps.image_names.outputs.ghcr_image }}:${{ steps.version.outputs.major_minor_version }}
${{ steps.image_names.outputs.ghcr_image }}:${{ steps.version.outputs.major_version }}
${{ matrix.lua-version == '5.4.7' && format('{0}:latest', steps.image_names.outputs.ghcr_image) || '' }}
# Enable provenance attestation for both registries
provenance: mode=max
outputs: |
type=image,name=${{ steps.image_names.outputs.dockerhub_image }}:${{ steps.version.outputs.full_version }}
build-args: |
BUILD_DATE=${{ github.event.repository.updated_at }}
VCS_REF=${{ github.sha }}
LUA_VERSION=${{ matrix.lua-version }}
LUAROCKS_VERSION=${{ matrix.luarocks-version }}
- name: Generate artifact attestation for Docker Hub
uses: actions/attest-build-provenance@v2
with:
subject-name: index.docker.io/${{ steps.image_names.outputs.dockerhub_image }}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true
- name: Generate SBOM
if: github.event_name != 'pull_request'
run: |
# Create output directory
mkdir -p sbom
# Generate SBOM in multiple formats
syft ${{ steps.image_names.outputs.dockerhub_image }}:${{ steps.version.outputs.full_version }} -o spdx-json=sbom/spdx.json
syft ${{ steps.image_names.outputs.dockerhub_image }}:${{ steps.version.outputs.full_version }} -o cyclonedx-json=sbom/cyclonedx.json
# Optional: Generate human-readable text version
syft ${{ steps.image_names.outputs.dockerhub_image }}:${{ steps.version.outputs.full_version }} -o text=sbom/sbom.txt
- name: Upload SBOM as artifact
if: github.event_name != 'pull_request'
uses: actions/upload-artifact@v4
with:
name: sbom-files-${{ matrix.lua-version }}
path: sbom/
retention-days: 90