Repository navigation
149 lines (129 loc) · 4.52 KB
/
Copy pathdocker.yml
File metadata and controls
149 lines (129 loc) · 4.52 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
name: Docker
on:
push:
tags:
- "v*"
branches:
- main
permissions:
contents: read
packages: write
jobs:
build-image:
strategy:
matrix:
include:
- architecture: x86_64
runner: ubuntu-24.04
- architecture: aarch64
runner: ubuntu-24.04-arm
fail-fast: false
runs-on: ${{ matrix.runner }}
steps:
- name: Setup docker arch
id: setup-docker-arch
env:
ARCHITECTURE: ${{ matrix.architecture }}
run: |
case "${ARCHITECTURE}" in
x86_64)
DOCKER_ARCH="amd64"
;;
aarch64)
DOCKER_ARCH="arm64"
;;
*)
echo "Unsupported architecture: $ARCHITECTURE}"
exit 1
;;
esac
echo "DOCKER_ARCH=$DOCKER_ARCH" >> $GITHUB_OUTPUT
echo "Docker architecture: $DOCKER_ARCH"
shell: bash
- uses: actions/checkout@v6
name: Checkout code
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to GitHub Container Registry
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}
- name: Build Docker image
run: |
docker buildx build --platform linux/${{ steps.setup-docker-arch.outputs.DOCKER_ARCH }} --output type=docker -t ghcr.io/riptideslabs/${{ github.event.repository.name }}:${{ github.ref_name }}-${{ steps.setup-docker-arch.outputs.DOCKER_ARCH }} .
shell: bash
- name: Save Docker image as artifact
run: |
docker save ghcr.io/riptideslabs/${{ github.event.repository.name }}:${{ github.ref_name }}-${{ steps.setup-docker-arch.outputs.DOCKER_ARCH }} -o image-${{ steps.setup-docker-arch.outputs.DOCKER_ARCH }}.tar
shell: bash
- name: Upload image artifact
uses: actions/upload-artifact@v7
with:
name: image-${{ steps.setup-docker-arch.outputs.DOCKER_ARCH }}
path: image-${{ steps.setup-docker-arch.outputs.DOCKER_ARCH }}.tar
retention-days: 1
push-manifest:
needs: build-image
runs-on: ubuntu-latest
steps:
- name: Download amd64 image
uses: actions/download-artifact@v8
with:
name: image-amd64
path: ./amd64
- name: Download arm64 image
uses: actions/download-artifact@v8
with:
name: image-arm64
path: ./arm64
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to GitHub Container Registry
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}
- name: Load images
run: |
docker load -i ./amd64/image-amd64.tar
docker load -i ./arm64/image-arm64.tar
shell: bash
- name: Push images (no manifest)
run: |
docker push ghcr.io/riptideslabs/${{ github.event.repository.name }}:${{ github.ref_name }}-amd64
docker push ghcr.io/riptideslabs/${{ github.event.repository.name }}:${{ github.ref_name }}-arm64
shell: bash
- name: Extract metadata
id: meta
uses: docker/metadata-action@v6
with:
images: ghcr.io/riptideslabs/keyledger
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
type=edge,branch=main
- name: Create and push multi-arch manifest
env:
TAGS: ${{ steps.meta.outputs.tags }}
LABELS: ${{ steps.meta.outputs.labels }}
run: |
mapfile -t TAGS_ARRAY <<< "$TAGS"
TAG_ARGS=()
for tag in "${TAGS_ARRAY[@]}"; do
[[ -n "$tag" ]] && TAG_ARGS+=("-t" "$tag")
done
mapfile -t LABELS_ARRAY <<< "$LABELS"
ANNOTATION_ARGS=()
for label in "${LABELS_ARRAY[@]}"; do
[[ -n "$label" ]] && ANNOTATION_ARGS+=("--annotation" "index:$label")
done
docker buildx imagetools create \
"${TAG_ARGS[@]}" \
"${ANNOTATION_ARGS[@]}" \
ghcr.io/riptideslabs/${{ github.event.repository.name }}:${{ github.ref_name }}-amd64 \
ghcr.io/riptideslabs/${{ github.event.repository.name }}:${{ github.ref_name }}-arm64
shell: bash