2022-12-04 17:09:15 -05:00
|
|
|
name: Build
|
2021-06-02 13:11:41 -04:00
|
|
|
|
|
|
|
on:
|
|
|
|
workflow_dispatch:
|
|
|
|
push:
|
2022-09-11 07:53:58 -04:00
|
|
|
branches:
|
|
|
|
- main
|
|
|
|
# Ignore Markdown files
|
|
|
|
paths-ignore:
|
|
|
|
- '**.md'
|
2021-06-02 13:11:41 -04:00
|
|
|
schedule:
|
2024-06-12 06:23:19 -04:00
|
|
|
# Build the image daily
|
|
|
|
- cron: '0 0 * * *'
|
2021-06-02 13:11:41 -04:00
|
|
|
|
2022-09-11 07:53:58 -04:00
|
|
|
env:
|
|
|
|
REGISTRY: ghcr.io
|
2022-12-04 17:09:15 -05:00
|
|
|
IMAGE_NAME: tommytran732/synapse
|
2022-09-11 07:53:58 -04:00
|
|
|
|
2021-06-02 13:11:41 -04:00
|
|
|
jobs:
|
|
|
|
build:
|
2023-04-21 22:10:56 -04:00
|
|
|
name: Build & push new image
|
2024-07-20 01:04:45 -04:00
|
|
|
runs-on: ubuntu-24.04
|
2022-09-11 07:53:58 -04:00
|
|
|
permissions:
|
|
|
|
contents: read
|
|
|
|
packages: write
|
|
|
|
id-token: write
|
|
|
|
|
2021-06-02 13:11:41 -04:00
|
|
|
steps:
|
|
|
|
- name: Checkout code
|
2024-05-28 04:53:27 -04:00
|
|
|
uses: actions/checkout@v4
|
2021-06-02 13:11:41 -04:00
|
|
|
|
2024-06-15 22:11:19 -04:00
|
|
|
- name: Extract version for tags
|
|
|
|
run: |
|
|
|
|
echo "FULL_VERSION=$(grep -oP '(?<=SYNAPSE_VERSION=).*' Dockerfile)" >> $GITHUB_ENV
|
|
|
|
echo "MAJOR_VERSION=$(grep -oP '(?<=SYNAPSE_VERSION=).*' Dockerfile | head -c5)" >> $GITHUB_ENV
|
|
|
|
|
2022-09-11 07:53:58 -04:00
|
|
|
- name: Install cosign
|
|
|
|
if: github.event_name != 'pull_request'
|
2024-05-28 04:59:31 -04:00
|
|
|
uses: sigstore/cosign-installer@v3
|
2022-09-11 07:53:58 -04:00
|
|
|
|
|
|
|
- name: Set up Docker Buildx
|
2024-05-28 04:59:31 -04:00
|
|
|
uses: docker/setup-buildx-action@v3
|
2022-09-11 07:53:58 -04:00
|
|
|
|
|
|
|
- name: Login to registry
|
|
|
|
if: github.event_name != 'pull_request'
|
2024-05-28 04:59:31 -04:00
|
|
|
uses: docker/login-action@v3
|
2021-06-02 13:11:41 -04:00
|
|
|
with:
|
2022-09-11 07:53:58 -04:00
|
|
|
registry: ${{ env.REGISTRY }}
|
|
|
|
username: ${{ github.repository_owner }}
|
|
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
|
|
|
|
- name: Set Docker metadata
|
|
|
|
id: meta
|
2024-05-28 04:59:31 -04:00
|
|
|
uses: docker/metadata-action@v5
|
2022-09-11 07:53:58 -04:00
|
|
|
with:
|
|
|
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
|
|
|
tags: |
|
|
|
|
latest
|
2024-06-15 22:11:19 -04:00
|
|
|
${{ env.FULL_VERSION }}
|
|
|
|
${{ env.MAJOR_VERSION }}
|
2022-09-11 07:53:58 -04:00
|
|
|
|
|
|
|
- name: Build and push Docker image
|
|
|
|
id: build-and-push
|
2024-06-17 05:52:50 -04:00
|
|
|
uses: docker/build-push-action@v6
|
2022-09-11 07:53:58 -04:00
|
|
|
with:
|
|
|
|
context: .
|
|
|
|
push: ${{ github.event_name != 'pull_request' }}
|
|
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
|
|
|
|
|
|
- name: Sign the published Docker image
|
|
|
|
if: ${{ github.event_name != 'pull_request' }}
|
2023-03-16 19:43:13 -04:00
|
|
|
run: cosign sign ${TAGS} -y
|
2022-09-11 07:53:58 -04:00
|
|
|
env:
|
2023-03-16 19:43:13 -04:00
|
|
|
TAGS: ${{ steps.meta.outputs.tags }}
|
2023-04-21 21:50:36 -04:00
|
|
|
|
2024-06-12 06:23:19 -04:00
|
|
|
trivy:
|
|
|
|
name: Scan current image with Trivy
|
2023-04-21 22:02:01 -04:00
|
|
|
needs: build
|
2024-06-12 06:23:19 -04:00
|
|
|
permissions:
|
|
|
|
security-events: write
|
2024-07-20 01:04:45 -04:00
|
|
|
runs-on: ubuntu-24.04
|
2023-04-21 21:59:33 -04:00
|
|
|
steps:
|
2023-04-21 21:50:36 -04:00
|
|
|
- name: Run Trivy vulnerability scanner
|
|
|
|
uses: aquasecurity/trivy-action@master
|
|
|
|
with:
|
2024-07-20 01:04:45 -04:00
|
|
|
image-ref: ghcr.io/tommytran732/synapse
|
|
|
|
format: template
|
2023-04-21 21:50:36 -04:00
|
|
|
template: '@/contrib/sarif.tpl'
|
2024-07-20 01:04:45 -04:00
|
|
|
output: trivy-results.sarif
|
|
|
|
severity: UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL
|
|
|
|
vuln-type: os,library
|
2023-04-21 21:50:36 -04:00
|
|
|
|
|
|
|
- name: Upload Trivy scan results to GitHub Security tab
|
2024-05-30 14:46:03 -04:00
|
|
|
uses: github/codeql-action/upload-sarif@v3
|
2023-04-21 21:50:36 -04:00
|
|
|
with:
|
2024-07-20 01:04:45 -04:00
|
|
|
sarif_file: trivy-results.sarif
|
|
|
|
category: trivy
|
2024-06-12 06:23:19 -04:00
|
|
|
|
|
|
|
grype:
|
|
|
|
name: Scan current image with Grype
|
|
|
|
needs: build
|
|
|
|
permissions:
|
|
|
|
security-events: write
|
2024-07-20 01:04:45 -04:00
|
|
|
runs-on: ubuntu-24.04
|
2024-06-12 06:23:19 -04:00
|
|
|
steps:
|
|
|
|
- name: Run Grype vulnerability scanner
|
2024-07-10 22:06:41 -04:00
|
|
|
uses: anchore/scan-action@v4
|
2024-06-12 06:23:19 -04:00
|
|
|
id: grype
|
|
|
|
with:
|
2024-07-20 01:04:45 -04:00
|
|
|
image: ghcr.io/tommytran732/synapse
|
2024-06-12 06:23:19 -04:00
|
|
|
fail-build: false
|
|
|
|
|
|
|
|
- name: Upload Grype scan results to GitHub Security tab
|
|
|
|
uses: github/codeql-action/upload-sarif@v3
|
|
|
|
with:
|
|
|
|
sarif_file: ${{ steps.grype.outputs.sarif }}
|
|
|
|
category: grype
|