Repository navigation
188 lines (167 loc) · 6.77 KB
/
Copy pathbuild.yml
File metadata and controls
188 lines (167 loc) · 6.77 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
name: build
on:
workflow_dispatch:
pull_request:
push:
branches: [ 'main' ]
tags: [ 'v*' ]
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
prepare:
runs-on: ubuntu-latest
outputs:
targets: ${{ steps.set.outputs.targets }}
steps:
- id: set
run: echo 'targets=["dipper-service","dipper-cli"]' >> "$GITHUB_OUTPUT"
build:
name: ${{ matrix.target }} (${{ matrix.platform }})
needs: prepare
strategy:
fail-fast: false
matrix:
target: ${{ fromJSON(needs.prepare.outputs.targets) }}
platform: [linux/amd64, linux/arm64]
include:
- platform: linux/amd64
runner: ubuntu-24.04
- platform: linux/arm64
runner: ubuntu-24.04-arm
runs-on: ${{ matrix.runner }}
permissions:
contents: read
packages: write
env:
IMAGE: ghcr.io/graphprotocol/${{ matrix.target }}
steps:
- name: Prepare platform pair
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> "$GITHUB_ENV"
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0
- uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0
if: github.event_name != 'pull_request'
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker labels
id: meta
uses: docker/metadata-action@030e881283bb7a6894de51c315a6bfe6a94e05cf # v6.0.0
with:
images: ${{ env.IMAGE }}
# dipper-service uses the default Dockerfile; dipper-cli has its own.
- name: Build and push by digest
id: build
uses: docker/build-push-action@bcafcacb16a39f128d818304e6c9c0c18556b85f # v7.1.0
with:
file: ${{ matrix.target == 'dipper-cli' && 'Dockerfile.dipper-cli' || 'Dockerfile' }}
context: .
platforms: ${{ matrix.platform }}
labels: ${{ steps.meta.outputs.labels }}
pull: true
cache-from: type=registry,ref=${{ env.IMAGE }}:buildcache-${{ env.PLATFORM_PAIR }}
cache-to: ${{ github.event_name != 'pull_request' && format('type=registry,ref={0}:buildcache-{1},mode=max', env.IMAGE, env.PLATFORM_PAIR) || '' }}
outputs: type=image,name=${{ env.IMAGE }},push-by-digest=true,name-canonical=true,push=${{ github.event_name != 'pull_request' }}
- name: Export digest
if: github.event_name != 'pull_request'
run: |
mkdir -p ${{ runner.temp }}/digests
digest="${{ steps.build.outputs.digest }}"
touch "${{ runner.temp }}/digests/${digest#sha256:}"
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
if: github.event_name != 'pull_request'
with:
name: digests-${{ matrix.target }}-${{ env.PLATFORM_PAIR }}
path: ${{ runner.temp }}/digests/*
if-no-files-found: error
retention-days: 1
merge:
name: Merge ${{ matrix.target }} into multi-arch manifest
needs: [prepare, build]
if: |
!cancelled()
&& needs.build.result == 'success'
&& github.event_name != 'pull_request'
strategy:
fail-fast: false
matrix:
target: ${{ fromJSON(needs.prepare.outputs.targets) }}
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
env:
IMAGE: ghcr.io/graphprotocol/${{ matrix.target }}
steps:
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
path: ${{ runner.temp }}/digests
pattern: digests-${{ matrix.target }}-*
merge-multiple: true
- uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0
- uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker tags
id: meta
uses: docker/metadata-action@030e881283bb7a6894de51c315a6bfe6a94e05cf # v6.0.0
with:
images: ${{ env.IMAGE }}
# `latest` follows main only. A release's tag is built after main's push of the
# same commit, and main may have moved on by then.
flavor: |
latest=false
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=ref,event=tag
# On for every run but a tag's, so workflow_dispatch from a non-default branch
# (no `latest`, no tag ref) still yields a populated meta.outputs.version for
# Inspect. Off for a tag: main's push already published this commit's `sha-`
# tag, and a rebuild would point it at a new digest.
type=sha,enable=${{ !startsWith(github.ref, 'refs/tags/') }}
# Glob `*` expands to digest-named files written by the build job's Export digest step.
- name: Create manifest list and push
working-directory: ${{ runner.temp }}/digests
run: |
# Both lists are meant to split, into 1 argument per tag and per digest.
# shellcheck disable=SC2046
docker buildx imagetools create \
$(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.IMAGE }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.IMAGE }}:${{ steps.meta.outputs.version }}
dipper-cli:
strategy:
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
- os: macos-latest
target: aarch64-apple-darwin
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Set up Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@1780873c7b576612439a134613cc4cc74ce5538c # v1
with:
target: ${{ matrix.target }}
rustflags: ''
cache: false
- name: Cache Rust build files
uses: leafwing-studios/cargo-cache@ba6ee760ccdefa26b630cff8094e3243ae86a2c9 # v2
with:
sweep-cache: true
- name: Build executable (release)
run: cargo build --package dipper-cli --bin dipper-cli --target=${{ matrix.target }} --release
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: dipper-cli-${{ matrix.target }}
path: target/${{ matrix.target }}/release/dipper-cli
if-no-files-found: error