forked from sigp/anchor
-
Notifications
You must be signed in to change notification settings - Fork 1
180 lines (152 loc) · 6.11 KB
/
docker.yml
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
name: Docker build and push
on:
workflow_run:
workflows: ["test-suite"]
push:
branches:
- stable
tags:
- v*
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
# Enable self-hosted runners for the sigp repo only.
SELF_HOSTED_RUNNERS: ${{ github.repository == 'sigp/anchor' }}
RUST_VERSION: 'abc'
SHORT_ARCH: 'amd64'
# Deny warnings in CI
RUSTFLAGS: "-D warnings -C debuginfo=0"
# Prevent Github API rate limiting
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
extract-version:
uses: ./.github/workflows/extract-version.yml
# Critical test jobs from test-suite.yml
# TODO - depend on test-suite.yml
release-tests:
name: release-tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Get latest version of stable Rust
uses: moonrepo/setup-rust@v1
with:
channel: stable
cache-target: release
bins: cargo-nextest
- name: Run tests in release
run: make nextest-release
debug-tests:
name: debug-tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Get latest version of stable Rust
uses: moonrepo/setup-rust@v1
with:
channel: stable
bins: cargo-nextest
- name: Run tests in debug
run: make nextest-debug
code-quality:
name: code-quality
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Get latest version of stable Rust
uses: moonrepo/setup-rust@v1
with:
channel: stable
cache-target: release
components: rustfmt,clippy
- name: Check formatting with cargo fmt
run: make cargo-fmt
- name: Lint code for quality and style with Clippy
run: make lint
build-docker-multi-arch:
name: build-docker-anchor-${{ matrix.cpu_arch }}
runs-on: ${{ github.repository == 'sigp/anchor' && fromJson('["self-hosted", "linux", "release"]') || 'ubuntu-22.04' }}
strategy:
matrix:
cpu_arch: [aarch64, x86_64]
include:
- profile: maxperf
needs: [extract-version, release-tests, debug-tests, code-quality]
env:
VERSION: ${{ needs.extract-version.outputs.VERSION }}
VERSION_SUFFIX: ${{ needs.extract-version.outputs.VERSION_SUFFIX }}
steps:
- name: Map aarch64 to arm64 short arch
if: startsWith(matrix.cpu_arch, 'aarch64')
run: echo "SHORT_ARCH=arm64" >> $GITHUB_ENV
- name: Map x86_64 to amd64 short arch
if: startsWith(matrix.cpu_arch, 'x86_64')
run: echo "SHORT_ARCH=amd64" >> $GITHUB_ENV
- name: Install Rust and Cargo
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source $HOME/.cargo/env
echo "PATH=$HOME/.cargo/bin:$PATH" >> $GITHUB_ENV
- name: cargo install cross
run: |
cargo install cross
# - uses: actions/checkout@v4
# - name: Update Rust
# if: env.SELF_HOSTED_RUNNERS == 'false'
# run: rustup update stable
- name: Checkout sources
uses: actions/checkout@v4
- name: Get rust-version
id: get-rust-version
run: |
echo "RUST_VERSION=$(./.github/scripts/toml_reader.sh ./anchor/Cargo.toml package rust-version)" >> $GITHUB_ENV
- name: Get latest version of stable Rust
run: echo "rust version is ${{ env.RUST_VERSION }}"
- name: Retrieve Docker credentials from Vault
uses: hashicorp/vault-action@v2
with:
url: https://vault.sigp.io
method: github
githubToken: ${{ secrets.GH_TOKEN }}
secrets: |
spesi_kv/data/dev/docker/anchor DOCKER_USERNAME
spesi_kv/data/dev/docker/anchor DOCKER_PASSWORD
- name: Dockerhub login
run: |
echo "${DOCKER_PASSWORD}" | docker login --username ${DOCKER_USERNAME} --password-stdin
- name: Build binary
run: |
cargo install cross
env CROSS_PROFILE=${{ matrix.profile }} make build-${{ matrix.cpu_arch }}
- name: Set `make` command for anchor
run: |
echo "MAKE_CMD=build-${{ matrix.cpu_arch }}" >> $GITHUB_ENV
- name: Make bin dir
run: mkdir ./bin
- name: Move built binary into Docker scope
run: mv ./target/${{ matrix.cpu_arch }}-unknown-linux-gnu/${{ matrix.profile }}/anchor ./bin
- name: Install QEMU
if: env.SELF_HOSTED_RUNNERS == 'false'
run: sudo apt-get update && sudo apt-get install -y qemu-user-static
- name: Set up Docker Buildx
if: env.SELF_HOSTED_RUNNERS == 'false'
uses: docker/setup-buildx-action@v3
- name: Build and push
uses: docker/build-push-action@v5
with:
file: ./anchor/Dockerfile.cross
context: .
platforms: linux/${{ env.SHORT_ARCH }}
labels: |
git.revision=${{ github.sha }}
git.branch=${{ github.ref }}
git.tag=${{ github.ref }}
git.repository=${{ github.repository }}
push: true
tags: |
${{ github.repository_owner}}/anchor:${{ env.VERSION }}-${{ env.SHORT_ARCH }}${{ env.VERSION_SUFFIX }}
build-args: |
RUST_VERSION=${{ env.RUST_VERSION }}
TARGETPLATFORM=linux/${{ env.SHORT_ARCH }}
GIT_COMMIT_HASH=${{ github.sha }}