Create and publish a ceph-libs image #8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
name: Create and publish a ceph-libs image | |
permissions: | |
actions: read | |
contents: read | |
id-token: write | |
packages: write | |
pull-requests: write | |
security-events: write | |
on: | |
pull_request: | |
paths: | |
- .github/workflows/container-build-ceph.yaml | |
- ContainerFiles/ceph-libs | |
schedule: | |
- cron: '0 0 * * 0' # Run Weekly at midnight UTC | |
workflow_dispatch: | |
inputs: | |
ceph-version: | |
description: 'Version of Ceph to use' | |
required: true | |
default: "v19.2.2" | |
type: choice | |
options: | |
- "v19.2.2" | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }}/ceph-libs | |
CATEGORY_NAME: ceph-libs | |
# NOTE(cloudnull): This is used to parse the workflow_dispatch inputs, sadly the inputs are not available in the | |
# workflow_dispatch event, so they're being stored in the environment variables. This is a | |
# workaround until there's a better way to handle this. | |
ceph_version: > | |
["v19.2.2"] | |
jobs: | |
init: | |
runs-on: ubuntu-latest | |
outputs: | |
ceph-version: ${{ steps.generate-matrix.outputs.ceph_version }} | |
steps: | |
- name: generate-matrix | |
id: generate-matrix | |
run: | | |
if [ "${{ github.event_name == 'workflow_dispatch' }}" = "true" ]; then | |
ceph_version="$(echo '${{ github.event.inputs.ceph-version }}' | jq -R '[select(length>0)]' | jq -c '.')" | |
fi | |
echo "ceph_version=${ceph_version:-${{ env.ceph_version }}}" >> $GITHUB_OUTPUT | |
build-and-push-image: | |
needs: | |
- init | |
strategy: | |
matrix: | |
ceph-libs-version: ${{ fromJSON(needs.init.outputs.ceph-version) }} | |
outputs: | |
MY_DATE: ${{ steps.mydate.outputs.MY_DATE }} | |
MY_CONTAINER: ${{ steps.mycontainer.outputs.MY_CONTAINER }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Cleanup disk space | |
run: | | |
echo "Before Cleanup"; df -h | |
sudo rm -rf /usr/local/lib/android || true | |
sudo rm -rf /usr/local/share/android || true | |
sudo rm -rf /usr/share/dotnet || true | |
sudo rm -rf /opt/ghc || true | |
sudo rm -rf /usr/local/.ghcup || true | |
sudo swapoff -a || true | |
sudo rm -f /mnt/swapfile || true | |
sudo rm -rf "/usr/local/share/boost" || true | |
sudo rm -rf "$AGENT_TOOLSDIRECTORY" || true | |
echo "After Cleanup"; df -h | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Log in to the Container registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
- name: Dynamically set MY_DATE environment variable | |
run: echo "MY_DATE=$(date +%s)" >> $GITHUB_ENV | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
file: ContainerFiles/ceph-libs | |
push: false | |
load: true | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
tags: | | |
${{ env.IMAGE_NAME }}:local | |
labels: ${{ steps.meta.outputs.labels }} | |
build-args: | | |
CEPH_VERSION=${{ matrix.ceph-libs-version }} | |
- name: Run Trivy vulnerability scanner | |
uses: aquasecurity/trivy-action@0.28.0 | |
with: | |
image-ref: '${{ env.IMAGE_NAME }}:local' | |
format: 'sarif' | |
output: 'trivy-results.sarif' | |
ignore-unfixed: true | |
severity: 'CRITICAL,HIGH' | |
- name: Upload Trivy scan results to GitHub Security tab | |
continue-on-error: true | |
if: ${{ github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' }} | |
uses: github/codeql-action/upload-sarif@v3 | |
with: | |
sarif_file: 'trivy-results.sarif' | |
category: "${{ env.IMAGE_NAME }}-${{ matrix.ceph-libs-version }}" | |
- name: Publish Trivy Output to Summary | |
run: | | |
if [[ -s trivy-results.sarif ]]; then | |
{ | |
echo "### Security Output" | |
echo "<details><summary>Click to expand</summary>" | |
echo "" | |
echo '```json' | |
cat trivy-results.sarif | |
echo '```' | |
echo "</details>" | |
} >> $GITHUB_STEP_SUMMARY | |
fi | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
file: ContainerFiles/ceph-libs | |
push: ${{ github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
tags: | | |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ matrix.ceph-libs-version }}-latest | |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ matrix.ceph-libs-version }}-${{ env.MY_DATE }} | |
labels: ${{ steps.meta.outputs.labels }} | |
build-args: | | |
CEPH_VERSION=${{ matrix.ceph-libs-version }} |