-
Notifications
You must be signed in to change notification settings - Fork 0
146 lines (125 loc) · 4.47 KB
/
Copy pathdocker-build-push.yml
File metadata and controls
146 lines (125 loc) · 4.47 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
name: Build and Push Docker Images
on:
push:
branches:
- main
- develop
tags:
- 'v*'
pull_request:
branches:
- main
workflow_dispatch:
env:
REGISTRY: docker.io
BACKEND_IMAGE_NAME: cyberfly/cyberfly_node
jobs:
build-rust-binaries:
runs-on: ubuntu-latest
# Build inside debian:bookworm container to match runtime GLIBC version
container: debian:bookworm
strategy:
matrix:
include:
- target: x86_64-unknown-linux-gnu
arch: amd64
- target: aarch64-unknown-linux-gnu
arch: arm64
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install build dependencies
run: |
apt-get update
apt-get install -y build-essential perl make curl git cmake gcc-aarch64-linux-gnu g++-aarch64-linux-gnu pkg-config libssl-dev clang
- name: Install Rust toolchain
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
. "$HOME/.cargo/env"
rustup target add ${{ matrix.target }}
# Rust caching - includes Cargo.lock hash automatically
- name: Cache Rust dependencies
uses: Swatinem/rust-cache@v2
with:
shared-key: ${{ matrix.target }}-bookworm
cache-on-failure: true
# Cache the target directory for this specific target
cache-targets: true
- name: Setup cross-compilation for ARM64
if: matrix.arch == 'arm64'
run: |
echo "CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
echo "CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g++" >> $GITHUB_ENV
echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
- name: Build for ${{ matrix.target }}
run: |
. "$HOME/.cargo/env"
# Enable jemalloc on Linux for better runtime performance
cargo build --release --target ${{ matrix.target }} --features jemalloc -j$(nproc)
- name: Strip binary
run: |
if [ "${{ matrix.arch }}" = "amd64" ]; then
strip target/${{ matrix.target }}/release/cyberfly-rust-node
else
aarch64-linux-gnu-strip target/${{ matrix.target }}/release/cyberfly-rust-node || true
fi
- name: Upload binary artifact
uses: actions/upload-artifact@v4
with:
name: cyberfly-rust-node-${{ matrix.arch }}
path: target/${{ matrix.target }}/release/cyberfly-rust-node
retention-days: 1
build-backend:
needs: build-rust-binaries
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download x86_64 binary
uses: actions/download-artifact@v4
with:
name: cyberfly-rust-node-amd64
path: ./bin-amd64
- name: Download arm64 binary
uses: actions/download-artifact@v4
with:
name: cyberfly-rust-node-arm64
path: ./bin-arm64
- name: Rename binaries for Docker
run: |
mv bin-amd64/cyberfly-rust-node cyberfly-rust-node-amd64
mv bin-arm64/cyberfly-rust-node cyberfly-rust-node-arm64
chmod +x cyberfly-rust-node-*
ls -lah cyberfly-rust-node-*
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Extract metadata (tags, labels) for Backend
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.BACKEND_IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push Backend Docker image
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}