Skip to content

bump(m365): bump terraform providers and image dependencies #303

bump(m365): bump terraform providers and image dependencies

bump(m365): bump terraform providers and image dependencies #303

name: M365 Image Build
on:
schedule:
- cron: '16 11 * * 1'
push:
branches: [ "**" ]
# Publish semver tags as releases.
tags: [ 'v*.*.*' ]
pull_request:
branches: [ "main" ]
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}-m365
jobs:
build:
name: Build
runs-on: windows-latest
# This condition prevents duplicate runs.
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
# based on https://github.com/orgs/community/discussions/26253#discussioncomment-6745038
# intent is to run on current ref, unless this is a scheduled run, then run on list defined below
strategy:
matrix:
version:
# to maintain multiple versions for scheduled builds, list here refs for this repo
- ref: main
scheduled:
- ${{ github.event_name == 'schedule' }}
exclude:
- { scheduled: false }
include:
- ref: ${{ github.head_ref || github.ref_name }}
permissions:
contents: read
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ matrix.version.ref }}
# Install the cosign tool except on PR
# https://github.com/sigstore/cosign-installer
- name: Install cosign
if: github.event_name != 'pull_request'
uses: sigstore/cosign-installer@v3
with:
cosign-release: 'v2.2.4'
# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
context: git
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
# set latest tag for default branch
type=raw,value=latest,enable={{is_default_branch}}
type=schedule,pattern={{date 'YYYYMMDD'}}
type=semver,pattern={{major}}.{{minor}}
type=ref,event=branch
# Build and push Docker image
- name: Build and push Docker image
id: build-and-push
env:
TAGS: ${{ steps.meta.outputs.tags }}
LABELS: ${{ steps.meta.outputs.labels }}
PUSH: ${{ github.event_name != 'pull_request' }}
IMAGE: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
shell: powershell
run: |
$docker_args = New-Object System.Collections.ArrayList
$Env:TAGS.Split([Environment]::NewLine) | Where-Object { $_ -ne "" } | ForEach {
$docker_args.Add("--tag")
$docker_args.Add($_)
}
$Env:LABELS.Split([Environment]::NewLine) | Where-Object { $_ -ne "" } | ForEach {
$docker_args.Add("--label")
$docker_args.Add($_)
}
docker build $docker_args m365/image
echo "digest=$(docker images --no-trunc --quiet $Env:IMAGE.ToLower())" >> $Env:GITHUB_OUTPUT
echo "image=$($Env:IMAGE.ToLower())" >> $Env:GITHUB_OUTPUT
if ($Env:PUSH -eq "true") {
docker push $Env:IMAGE.ToLower() --all-tags
}
exit $LASTEXITCODE
# Sign the resulting Docker image digest except on PRs.
# This will only write to the public Rekor transparency log when the Docker
# repository is public to avoid leaking data. If you would like to publish
# transparency data even for private images, pass --force to cosign below.
# https://github.com/sigstore/cosign
- name: Sign the published Docker image
if: ${{ github.event_name != 'pull_request' }}
env:
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
TAGS: ${{ steps.meta.outputs.tags }}
DIGEST: ${{ steps.build-and-push.outputs.digest }}
# This step uses the identity token to provision an ephemeral certificate
# against the sigstore community Fulcio instance.
run: |
$digest = $Env:DIGEST.Split(" ") | Where-Object { $_ -ne "" } | Select-Object -First 1
$Env:TAGS.Split("`n") | Where-Object { $_ -ne "" } | ForEach {
cosign sign --yes "$_@$digest"
}
exit 0
outputs:
image: ${{ steps.build-and-push.outputs.image }}
scan:
name: Scan
# This condition prevents duplicate runs.
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
permissions:
security-events: write
needs: build
runs-on: ubuntu-latest
steps:
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@0.28.0
with:
image-ref: ${{ needs.build.outputs.image }}:latest
format: 'sarif'
output: 'trivy-results.sarif'
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: 'trivy-results.sarif'
category: m365-image