forked from AAS-TwinEngine/AAS.TwinEngine.Plugin.DPP
-
Notifications
You must be signed in to change notification settings - Fork 0
124 lines (109 loc) · 4.74 KB
/
Copy pathdocker-publish.yml
File metadata and controls
124 lines (109 loc) · 4.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
name: Docker
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
on:
workflow_dispatch:
push:
branches:
- 'develop'
- 'release/**'
- 'hotfix/**'
# Publish semver tags as releases.
tags: [ 'v**' ]
pull_request:
branches:
- 'main'
- 'develop'
- 'release/**'
- 'hotfix/**'
permissions:
contents: read
env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository_owner }}/plugindpp
DOCKERFILE_PATH: source/AAS.TwinEngine.Plugin.RelationalDatabase/Dockerfile
BUILD_CONTEXT: source
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.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@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
# 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@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
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@c299e40c65443455700f0fdfc63efafe5b349051 # v5.10.0
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
flavor: |
latest=false
tags: |
type=semver,pattern={{raw}}
type=raw,value=develop-{{sha}},enable=${{startsWith(github.ref, 'refs/heads/develop')}}
type=raw,value=rc-{{branch}}-{{sha}},enable=${{startsWith(github.ref, 'refs/heads/release/')}}
type=raw,value={{branch}}-{{sha}},enable=${{startsWith(github.ref, 'refs/heads/hotfix/')}}
type=ref,event=pr
type=raw,value=manual-{{branch}}-{{sha}},enable=${{github.event_name == 'workflow_dispatch'}}
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
with:
sbom: true
provenance: mode=max
context: ${{ env.BUILD_CONTEXT }}
file: ${{ env.DOCKERFILE_PATH }}
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
# Extract the pure application SBOM from the artifact stage, we want to handle it separately from the container SBOM
# This automaticaly re-uses the previously generated stage from cache, so we get the exact sbom from previous build step
- name: Export Application SBOM from artifact stage
if: ${{ github.event_name != 'pull_request' }}
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
with:
context: ${{ env.BUILD_CONTEXT }}
file: ${{ env.DOCKERFILE_PATH }}
target: app-sbom-artifact
push: false
outputs: type=local,dest=sbom-output
# Generate container SBOM.
- name: Run Trivy in GitHub SBOM mode to generate CycloneDX SBOM for container
if: ${{ github.event_name != 'pull_request' }}
uses: aquasecurity/trivy-action@b6643a29fecd7f34b3597bc6acb0a98b03d33ff8 # 0.33.1
with:
scan-type: 'image'
format: 'cyclonedx'
output: 'sbom-output/sbom_container.cyclonedx.json'
image-ref: ${{ steps.meta.outputs.tags }}
skip-dirs: '/App' # Skip the /app directory as we handle the content of the application in a seperate SBOM for easier vulnerability management and because trivy misses important fields
- name: Upload trivy/container AND application SBOMs as a Github artifact
if: ${{ github.event_name != 'pull_request' }}
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: sbom
path: '${{ github.workspace }}/sbom-output/'