-
Notifications
You must be signed in to change notification settings - Fork 0
170 lines (146 loc) · 5.15 KB
/
Copy pathdocker.yml
File metadata and controls
170 lines (146 loc) · 5.15 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
name: Build and Push Multi-Architecture Docker Images
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
env:
REGISTRY: docker.io
IMAGE_NAME: modelingevolution/autoupdater
jobs:
build:
strategy:
matrix:
include:
- runner: ubuntu-latest
platform: linux/amd64
- runner: ubuntu-24.04-arm
platform: linux/arm64
runs-on: ${{ matrix.runner }}
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=preview,enable=${{ github.ref == 'refs/heads/master' }}
type=ref,event=branch
type=ref,event=pr
- name: Build and push Docker image
id: build
uses: docker/build-push-action@v5
with:
context: .
file: ./src/ModelingEvolution.AutoUpdater.Host/Dockerfile
platforms: ${{ matrix.platform }}
outputs: type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=${{ github.event_name != 'pull_request' }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
BUILD_CONFIGURATION=Release
ASSEMBLY_VERSION=1.0.0.0
SHA=${{ github.sha }}
provenance: false
- name: Export digest
if: github.event_name != 'pull_request'
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
# Extract architecture from matrix.platform (linux/amd64 -> amd64)
arch=$(echo "${{ matrix.platform }}" | cut -d'/' -f2)
echo -n "$digest" > "/tmp/digests/${arch}"
echo "Created digest file for ${arch}: $digest"
- name: Upload digest
if: github.event_name != 'pull_request'
uses: actions/upload-artifact@v4
with:
name: digest-${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
merge:
runs-on: ubuntu-latest
if: github.event_name != 'pull_request'
needs:
- build
permissions:
contents: read
packages: write
steps:
- name: Download digests
uses: actions/download-artifact@v4
with:
pattern: digest-*
merge-multiple: true
path: /tmp/digests
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=preview,enable=${{ github.ref == 'refs/heads/master' }}
type=ref,event=branch
type=ref,event=pr
type=sha,prefix={{branch}}-,format=short
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Create manifest list and push
run: |
set -e
echo "=== Debugging digest files ==="
echo "Available digest files:"
ls -la /tmp/digests/
echo "Contents:"
cat /tmp/digests/* || echo "No digest files found"
# Check if both digest files exist
if [ ! -f /tmp/digests/amd64 ] || [ ! -f /tmp/digests/arm64 ]; then
echo "❌ Missing digest files"
ls -la /tmp/digests/
exit 1
fi
# Read digests
AMD64_DIGEST=$(cat /tmp/digests/amd64)
ARM64_DIGEST=$(cat /tmp/digests/arm64)
echo "AMD64 digest: $AMD64_DIGEST"
echo "ARM64 digest: $ARM64_DIGEST"
# Validate digests
if [[ -z "$AMD64_DIGEST" || -z "$ARM64_DIGEST" ]]; then
echo "❌ Empty digests found"
exit 1
fi
# Create manifest for each tag
echo '${{ steps.meta.outputs.json }}' | jq -r '.tags[]' | while read tag; do
if [[ -n "$tag" && "$tag" != *":-"* ]]; then
echo "Creating manifest for: $tag"
docker buildx imagetools create \
--tag "$tag" \
"${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@$AMD64_DIGEST" \
"${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@$ARM64_DIGEST"
fi
done
echo "✅ Multi-arch manifest creation completed"