ci: onyl build arm64; fix image-ref for Trivy #29
This file contains 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: Build and Push Docker Image | |
# on: | |
# release: | |
# types: [published] | |
on: | |
push: | |
branches: | |
- "**" | |
tags: | |
- "v*.*.*" | |
pull_request: | |
jobs: | |
docker: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: | | |
ghcr.io/${{ github.repository }} | |
tags: | | |
type=schedule | |
type=ref,event=branch | |
type=ref,event=pr | |
type=semver,pattern={{version}} | |
type=semver,pattern={{major}}.{{minor}} | |
type=semver,pattern={{major}} | |
type=sha | |
- name: Login to GHCR | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Create .env file for main branch | |
if: github.ref == 'refs/heads/main' | |
run: | | |
touch .env | |
echo "${{ secrets.PROD_SECRETS }}" >> .env | |
- name: Create .env file for other branches | |
if: github.ref != 'refs/heads/main' | |
run: | | |
touch .env | |
echo "${{ secrets.DEV_SECRETS }}" >> .env | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Build Docker image | |
id: build | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
# platforms: linux/amd64,linux/arm64 | |
platforms: linux/arm64 | |
push: false | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
- name: Run Trivy vulnerability scanner | |
uses: aquasecurity/[email protected] | |
with: | |
image-ref: "ghcr.io/${{ github.repository }}:${{ github.sha }}" | |
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" | |
- name: Push Docker image | |
if: success() | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
# platforms: linux/amd64,linux/arm64 | |
platforms: linux/arm64 | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} |