forked from wso2/reference-implementations-afm
-
Notifications
You must be signed in to change notification settings - Fork 0
119 lines (109 loc) · 4.33 KB
/
release-docker.yml
File metadata and controls
119 lines (109 loc) · 4.33 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
name: Release Docker
on:
workflow_call:
inputs:
context:
description: "Docker build context directory (e.g., ballerina-interpreter)"
required: true
type: string
image_name:
description: "Docker image name without registry prefix (e.g., afm-ballerina-interpreter)"
required: true
type: string
version:
description: "Release version (e.g., 0.1.0)"
required: true
type: string
branch:
description: "Branch being released from"
required: true
type: string
image_title:
description: "Human-readable image title for OCI labels (e.g., AFM Ballerina Interpreter)"
required: true
type: string
jobs:
docker:
runs-on: ubuntu-latest
permissions:
packages: write
security-events: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ inputs.branch }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Determine Docker tags
id: docker-tags
env:
OWNER: ${{ github.repository_owner }}
IMAGE_NAME: ${{ inputs.image_name }}
VERSION: ${{ inputs.version }}
UPDATE_LATEST: ${{ inputs.branch == 'main' || inputs.branch == 'dev' }}
run: |
# GHCR requires lowercase repository names
OWNER_LOWER=$(echo "$OWNER" | tr '[:upper:]' '[:lower:]')
FULL_IMAGE="ghcr.io/$OWNER_LOWER/$IMAGE_NAME"
TAGS_FULL="$FULL_IMAGE:v$VERSION"
[ "$UPDATE_LATEST" = "true" ] && TAGS_FULL="$TAGS_FULL,$FULL_IMAGE:latest"
echo "TAGS_FULL=$TAGS_FULL" >> $GITHUB_OUTPUT
TAGS_SLIM="$FULL_IMAGE:v$VERSION-slim"
[ "$UPDATE_LATEST" = "true" ] && TAGS_SLIM="$TAGS_SLIM,$FULL_IMAGE:slim"
echo "TAGS_SLIM=$TAGS_SLIM" >> $GITHUB_OUTPUT
echo "FULL_IMAGE=$FULL_IMAGE" >> $GITHUB_OUTPUT
- name: Build and push full image
uses: docker/build-push-action@v5
with:
context: ${{ inputs.context }}
push: true
platforms: linux/amd64,linux/arm64
build-args: VARIANT=full
tags: ${{ steps.docker-tags.outputs.TAGS_FULL }}
labels: |
org.opencontainers.image.source=https://github.com/${{ github.repository }}
org.opencontainers.image.version=${{ inputs.version }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.title=${{ inputs.image_title }}
org.opencontainers.image.licenses=Apache-2.0
annotations: |
index:org.opencontainers.image.source=https://github.com/${{ github.repository }}
index:org.opencontainers.image.licenses=Apache-2.0
- name: Build and push slim image
uses: docker/build-push-action@v5
with:
context: ${{ inputs.context }}
push: true
platforms: linux/amd64,linux/arm64
build-args: VARIANT=slim
tags: ${{ steps.docker-tags.outputs.TAGS_SLIM }}
labels: |
org.opencontainers.image.source=https://github.com/${{ github.repository }}
org.opencontainers.image.version=${{ inputs.version }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.title=${{ inputs.image_title }} (Slim)
org.opencontainers.image.licenses=Apache-2.0
annotations: |
index:org.opencontainers.image.source=https://github.com/${{ github.repository }}
index:org.opencontainers.image.licenses=Apache-2.0
- name: Scan Docker image for vulnerabilities
uses: aquasecurity/trivy-action@0.34.0
with:
image-ref: ${{ steps.docker-tags.outputs.FULL_IMAGE }}:v${{ inputs.version }}
format: "sarif"
output: "trivy-results.sarif"
severity: "CRITICAL,HIGH"
limit-severities-for-sarif: true
exit-code: "1"
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v4
if: always()
with:
sarif_file: "trivy-results.sarif"