forked from helium/oracles
-
Notifications
You must be signed in to change notification settings - Fork 0
257 lines (246 loc) · 8.86 KB
/
DockerCI.yml
File metadata and controls
257 lines (246 loc) · 8.86 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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
name: Docker CI
on:
pull_request:
branches: ["main"]
push:
branches: ["main"]
tags: ["*"]
workflow_dispatch:
permissions:
contents: read
packages: write
jobs:
compute-base-build-tag:
runs-on: ubuntu-latest
outputs:
image_tag: ${{ steps.out.outputs.tag }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Create Tag
id: out
run: echo "tag=${{ hashFiles('Dockerfile','rust-toolchain.toml') }}" >> "$GITHUB_OUTPUT"
build-base:
needs: compute-base-build-tag
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Pull Cached Base Image
run: |
if docker pull ghcr.io/${{ github.repository }}/base:${{ needs.compute-base-build-tag.outputs.image_tag }}; then
echo "CACHE_HIT=true" >> $GITHUB_ENV
else
echo "CACHE_HIT=false" >> $GITHUB_ENV
fi
- name: Set up Docker Buildx
if: env.CACHE_HIT == 'false'
uses: docker/setup-buildx-action@v3
- name: Build and Push Base Image (if not cached)
if: env.CACHE_HIT == 'false'
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile
target: base
push: true
tags: ghcr.io/${{ github.repository }}/base:${{ needs.compute-base-build-tag.outputs.image_tag }}
fmt:
needs: [compute-base-build-tag, build-base]
runs-on: ubuntu-latest
container:
image: ghcr.io/${{ github.repository }}/base:${{ needs.compute-base-build-tag.outputs.image_tag }}
options: --user 1001:1001
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-fmt
cancel-in-progress: true
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Check formatting
run: cargo fmt -- --check
clippy:
needs: [compute-base-build-tag, build-base]
runs-on: ubuntu-latest
container:
image: ghcr.io/${{ github.repository }}/base:${{ needs.compute-base-build-tag.outputs.image_tag }}
options: --user 1001:1001
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-clippy
cancel-in-progress: true
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Cache Cargo Target Directory
uses: actions/cache@v4
with:
path: target
key: clippy-base-${{ needs.compute-base-build-tag.outputs.image_tag }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
clippy-base-${{ needs.compute-base-build-tag.outputs.image_tag }}-
- name: Clippy
run: cargo clippy --all-targets -- -Dclippy::all -D warnings
generate-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.get-matrix.outputs.matrix }}
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Restore Cached Matrix
id: cache-matrix
uses: actions/cache@v4
with:
path: matrix.json
key: matrix-${{ hashFiles('Cargo.toml', 'Cargo.lock') }}
- name: Extract Cargo Workspace Members (if not cached)
if: steps.cache-matrix.outputs.cache-hit != 'true'
run: |
set -e
cargo metadata --format-version=1 | jq -c '[.workspace_members[] | split("#")[0] | split("/") | last | gsub("_"; "-") | select(. != "metrics")]' > matrix.json
- name: Save Matrix to Output
id: get-matrix
run: echo "matrix=$(cat matrix.json)" >> $GITHUB_OUTPUT
tests:
needs: [compute-base-build-tag, build-base, generate-matrix]
runs-on: ubuntu-latest
container:
image: ghcr.io/${{ github.repository }}/base:${{ needs.compute-base-build-tag.outputs.image_tag }}
options: --user 1001:1001
strategy:
fail-fast: false
matrix:
package: ${{ fromJson(needs.generate-matrix.outputs.matrix) }}
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-tests-${{ matrix.package }}
cancel-in-progress: true
services:
postgres:
image: postgres:14.9-alpine
env:
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
localstack:
image: localstack/localstack:latest
env:
SERVICES: s3
EAGER_SERVICE_LOADING: 1
ports:
- 4566:4566
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Cache Cargo Target Directory
# Anything above 4min run
if: contains('["ingest", "iot-config", "iot-packet-verifier", "iot-verifier", "mobile-packet-verifier", "mobile-verifier", "price", "solana"]', matrix.package)
uses: actions/cache@v4
with:
path: target
key: tests-${{ matrix.package }}-base-${{ needs.compute-base-build-tag.outputs.image_tag }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
tests-${{ matrix.package }}-base-${{ needs.compute-base-build-tag.outputs.image_tag }}-
- name: Run tests
env:
DATABASE_URL: postgres://postgres:postgres@postgres:5432/postgres
AWSLOCAL_ENDPOINT: "http://localstack:4566"
run: cargo test -p ${{ matrix.package }}
build-mobile-images:
if: startsWith(github.ref, 'refs/tags/')
needs: [fmt, clippy, tests]
runs-on: ubuntu-latest
strategy:
matrix:
package: ["ingest","mobile-config","mobile-packet-verifier","mobile-verifier","price","reward-index"]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-build-image-${{ matrix.package }}
cancel-in-progress: true
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and Push Base Image
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile
target: runner
push: true
tags: ghcr.io/${{ github.repository }}/${{ matrix.package }}:${{ github.ref_name }}
build-args: |
PACKAGE=${{ matrix.package }}
upload-iot-releases:
needs: [fmt, clippy, tests]
runs-on: ubuntu-latest
container:
image: ubuntu:20.04
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-upload-release
cancel-in-progress: true
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Show Inputs
run: |
echo "Release Version: ${{ github.event.inputs.release_version }}"
- name: Install Dependencies
run: |
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get install -y tzdata curl build-essential pkg-config libssl-dev clang lld cmake unzip
ln -fs /usr/share/zoneinfo/UTC /etc/localtime
dpkg-reconfigure -f noninteractive tzdata
- name: Checkout
uses: actions/checkout@v4
- name: Rust install
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
cache-shared-key: release
- name: Install Protoc
uses: arduino/setup-protoc@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Build Release
run: AWS_LC_SYS_CMAKE_BUILDER=1 cargo build --release -p reward-index -p price -p ingest -p iot-config -p iot-packet-verifier -p iot-verifier -p poc-entropy
- name: Extract binaries and cleanup
run: |
mkdir -p /tmp/binaries
mv target/release/reward-index /tmp/binaries/
mv target/release/price /tmp/binaries/
mv target/release/ingest /tmp/binaries/
mv target/release/iot-config /tmp/binaries/
mv target/release/iot-packet-verifier /tmp/binaries/
mv target/release/iot-verifier /tmp/binaries/
mv target/release/poc-entropy /tmp/binaries/
echo "Before cleanup:"
df -h
rm -rf target/
echo "After cleanup:"
df -h
mkdir -p target/release
mv /tmp/binaries/* target/release/
echo "Binaries restored to target/release/"
- name: Debian packaging
env:
PACKAGECLOUD_API_KEY: ${{ secrets.PACKAGECLOUD_API_KEY }}
RELEASE_VERSION: ${{ github.event.inputs.release_version }}
run: |
chmod +x ./.github/scripts/make_debian.sh
./.github/scripts/make_debian.sh