Skip to content

Remove solution file and update project files to target .NET 10.0; up… #33

Remove solution file and update project files to target .NET 10.0; up…

Remove solution file and update project files to target .NET 10.0; up… #33

Workflow file for this run

name: Docker Image CI
on:
workflow_dispatch:
push:
branches: [main]
paths:
- 'src/**'
pull_request:
branches: [main]
paths:
- 'src/**'
jobs:
build:
runs-on: ubuntu-latest
env:
IMAGE_NAME: 'sampleapi'
TAG: ${{ github.sha }}
steps:
- name: Checkout
uses: actions/checkout@v5
# 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.1.1'
# Set up BuildKit Docker container builder to be able to build
# multi-platform images and export cache
# https://github.com/docker/setup-buildx-action
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ vars.DOCKER_LOGIN_SERVER }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ vars.DOCKER_LOGIN_SERVER }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_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:
images: ${{ vars.DOCKER_LOGIN_SERVER }}/${{ env.IMAGE_NAME }}
- name: Build Docker Image
uses: docker/build-push-action@v6
id: build
with:
context: src/SampleApi
load: true
push: false
tags: ${{ env.IMAGE_NAME }}:${{ env.TAG }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
# - name: Run Trivy vulnerability scanner
# if: ${{ github.event_name != 'pull_request' }}
# uses: aquasecurity/trivy-action@0.28.0
# with:
# exit-code: '1'
# image-ref: ${{ fromJSON(steps.build.outputs.metadata)['image.name'] }}
# format: 'github'
# github-pat: ${{ github.token }}
# env:
# TRIVY_USERNAME: Username
# TRIVY_PASSWORD: Password
- name: Generate Trivy Vulnerability Report
uses: aquasecurity/trivy-action@master
with:
image-ref: ${{ fromJSON(steps.build.outputs.metadata)['image.name'] }}
output: trivy-report.json
# format: json
format: 'github'
github-pat: ${{ github.token }}
exit-code: 0
- name: Upload Vulnerability Scan Results
uses: actions/upload-artifact@v4
with:
name: trivy-report
path: trivy-report.json
retention-days: 30
- name: Build Docker Image
uses: docker/build-push-action@v6
id: build-and-push
with:
context: src/SampleApi
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max