-
Notifications
You must be signed in to change notification settings - Fork 0
162 lines (146 loc) · 6.07 KB
/
docker-build.yml
File metadata and controls
162 lines (146 loc) · 6.07 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
name: Docker Build & Publish
on:
push:
branches:
- main
tags:
- 'v*'
workflow_dispatch:
inputs:
rocm_version:
description: 'ROCm version for build (e.g., 6.0, 6.1, 6.2)'
required: false
default: '6.0'
type: string
push_image:
description: 'Push image to registry'
required: false
default: true
type: boolean
env:
REGISTRY: ghcr.io
IMAGE_NAME: onnwee/transcript-create
jobs:
build-and-push:
name: Build and Push Docker Image
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write
attestations: write
security-events: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
# Tag as 'latest' for main branch
type=raw,value=latest,enable={{is_default_branch}}
# Tag with version for release tags (v1.2.3 -> 1.2.3)
type=semver,pattern={{version}}
# Tag with major.minor for release tags (v1.2.3 -> 1.2)
type=semver,pattern={{major}}.{{minor}}
# Tag with major for release tags (v1.2.3 -> 1)
type=semver,pattern={{major}}
# Tag with sha for all commits (sha-abc123)
type=sha,prefix=sha-,format=short
labels: |
org.opencontainers.image.title=Transcript Create
org.opencontainers.image.description=Create searchable, exportable transcripts from YouTube videos or channels
org.opencontainers.image.vendor=Subculture Collective
org.opencontainers.image.licenses=Apache-2.0
- name: Determine ROCm version and build args
id: rocm
run: |
# Use workflow input if provided, otherwise default to 6.0
ROCM_VERSION="${{ inputs.rocm_version || '6.0' }}"
echo "version=${ROCM_VERSION}" >> $GITHUB_OUTPUT
echo "wheel_index=https://download.pytorch.org/whl/rocm${ROCM_VERSION}" >> $GITHUB_OUTPUT
# Add ROCm variant tag if not on main branch or if manually specified
if [[ "${{ github.ref }}" != "refs/heads/main" ]] || [[ -n "${{ inputs.rocm_version }}" ]]; then
echo "rocm_tag=rocm${ROCM_VERSION}" >> $GITHUB_OUTPUT
fi
- name: Build and push Docker image
id: build-push
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: linux/amd64
push: ${{ (github.event_name != 'workflow_dispatch') || inputs.push_image }}
tags: |
${{ steps.meta.outputs.tags }}
${{ steps.rocm.outputs.rocm_tag != '' && format('{0}/{1}:{2}', env.REGISTRY, env.IMAGE_NAME, steps.rocm.outputs.rocm_tag) || '' }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
ROCM_WHEEL_INDEX=${{ steps.rocm.outputs.wheel_index }}
cache-from: type=gha
cache-to: type=gha,mode=max
provenance: true
sbom: true
- name: Generate artifact attestation
if: ${{ (github.event_name != 'workflow_dispatch') || inputs.push_image }}
uses: actions/attest-build-provenance@v1
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
subject-digest: ${{ steps.build-push.outputs.digest }}
push-to-registry: true
- name: Run Trivy vulnerability scanner
if: ${{ (github.event_name != 'workflow_dispatch') || inputs.push_image }}
uses: aquasecurity/trivy-action@master
with:
image-ref: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
format: 'sarif'
output: 'trivy-results.sarif'
severity: 'CRITICAL,HIGH'
- name: Upload Trivy results to GitHub Security
if: always()
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: 'trivy-results.sarif'
category: 'trivy-container'
- name: Output image details
run: |
echo "### Docker Image Published :rocket:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Image:** \`${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}\`" >> $GITHUB_STEP_SUMMARY
echo "**Digest:** \`${{ steps.build-push.outputs.digest }}\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Tags:**" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "${{ steps.meta.outputs.tags }}" | sed 's/^/ /' >> $GITHUB_STEP_SUMMARY
if [[ -n "${{ steps.rocm.outputs.rocm_tag }}" ]]; then
echo " ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.rocm.outputs.rocm_tag }}" >> $GITHUB_STEP_SUMMARY
fi
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Pull command:**" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY
echo "docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
build-time-check:
name: Verify Build Time
runs-on: ubuntu-latest
needs: build-and-push
if: always()
steps:
- name: Check build duration
run: |
echo "### Build Time Analysis :clock3:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Build job completed. Review the build-and-push job duration above." >> $GITHUB_STEP_SUMMARY
echo "**Target:** < 5 minutes with caching" >> $GITHUB_STEP_SUMMARY
echo "**Target:** < 15 minutes for first build" >> $GITHUB_STEP_SUMMARY