-
Notifications
You must be signed in to change notification settings - Fork 0
173 lines (152 loc) · 5.88 KB
/
docker-build.yml
File metadata and controls
173 lines (152 loc) · 5.88 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
163
164
165
166
167
168
169
170
171
172
173
name: Docker Build
on:
push:
branches: [main]
tags: ["v*"]
workflow_dispatch:
inputs:
force_build:
description: "Force build all images"
required: false
default: "false"
type: boolean
concurrency:
group: docker-build-${{ github.ref }}
cancel-in-progress: true
env:
REGISTRY: ghcr.io
IMAGE_PREFIX: allsource
jobs:
changes:
name: Detect Changes
runs-on: ubuntu-latest
outputs:
core: ${{ steps.filter.outputs.core }}
control-plane: ${{ steps.filter.outputs.control-plane }}
query-service: ${{ steps.filter.outputs.query-service }}
mcp-server: ${{ steps.filter.outputs.mcp-server }}
matrix: ${{ steps.matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
core:
- 'apps/core/**'
control-plane:
- 'apps/control-plane/**'
query-service:
- 'apps/query-service/**'
mcp-server:
- 'apps/mcp-server-elixir/**'
- name: Build matrix
id: matrix
run: |
MATRIX='{"include":['
FIRST=true
add_service() {
local name=$1
local context=$2
local changed=$3
if [ "$changed" == "true" ] || [ "${{ startsWith(github.ref, 'refs/tags/v') }}" == "true" ] || [ "${{ github.event.inputs.force_build }}" == "true" ]; then
if [ "$FIRST" != "true" ]; then
MATRIX="$MATRIX,"
fi
MATRIX="$MATRIX{\"name\":\"$name\",\"context\":\"$context\"}"
FIRST=false
fi
}
add_service "core" "apps/core" "${{ steps.filter.outputs.core }}"
add_service "control-plane" "apps/control-plane" "${{ steps.filter.outputs.control-plane }}"
add_service "query-service" "apps/query-service" "${{ steps.filter.outputs.query-service }}"
add_service "mcp-server" "apps/mcp-server-elixir" "${{ steps.filter.outputs.mcp-server }}"
MATRIX="$MATRIX]}"
echo "matrix=$MATRIX" >> $GITHUB_OUTPUT
echo "Build Matrix: $MATRIX"
build:
name: Build ${{ matrix.name }}
needs: changes
if: needs.changes.outputs.matrix != '{"include":[]}'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write
attestations: write
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.changes.outputs.matrix) }}
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.IMAGE_PREFIX }}-${{ matrix.name }}
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha,prefix=sha-
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push
id: build
uses: docker/build-push-action@v6
with:
context: ${{ matrix.context }}
platforms: linux/amd64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.IMAGE_PREFIX }}-${{ matrix.name }}:buildcache
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.IMAGE_PREFIX }}-${{ matrix.name }}:buildcache,mode=max
provenance: true
sbom: true
build-args: |
BUILDTIME=${{ github.event.repository.updated_at }}
VERSION=${{ github.ref_name }}
REVISION=${{ github.sha }}
- name: Generate attestation
uses: actions/attest-build-provenance@v2
with:
subject-name: ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.IMAGE_PREFIX }}-${{ matrix.name }}
subject-digest: ${{ steps.build.outputs.digest }}
push-to-registry: true
summary:
name: Summary
runs-on: ubuntu-latest
needs: [changes, build]
if: always()
steps:
- name: Generate summary
run: |
echo "## Docker Build Summary" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "| Service | Status |" >> "$GITHUB_STEP_SUMMARY"
echo "|---------|--------|" >> "$GITHUB_STEP_SUMMARY"
if [ "${{ needs.build.result }}" == "success" ]; then
echo "| Build | ✅ Published |" >> "$GITHUB_STEP_SUMMARY"
elif [ "${{ needs.build.result }}" == "skipped" ]; then
echo "| Build | ⏭️ Skipped (no changes) |" >> "$GITHUB_STEP_SUMMARY"
else
echo "| Build | ❌ Failed |" >> "$GITHUB_STEP_SUMMARY"
fi
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "**Platform:** linux/amd64" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "**Images:**" >> "$GITHUB_STEP_SUMMARY"
echo '```' >> "$GITHUB_STEP_SUMMARY"
echo "ghcr.io/${{ github.repository_owner }}/allsource-core" >> "$GITHUB_STEP_SUMMARY"
echo "ghcr.io/${{ github.repository_owner }}/allsource-control-plane" >> "$GITHUB_STEP_SUMMARY"
echo "ghcr.io/${{ github.repository_owner }}/allsource-query-service" >> "$GITHUB_STEP_SUMMARY"
echo "ghcr.io/${{ github.repository_owner }}/allsource-mcp-server" >> "$GITHUB_STEP_SUMMARY"
echo '```' >> "$GITHUB_STEP_SUMMARY"