Skip to content

Commit 00103b4

Browse files
authored
Merge pull request #172 from demml/171/image-refactor
171/image refactor
2 parents c1c1fc2 + e667716 commit 00103b4

File tree

8 files changed

+621
-214
lines changed

8 files changed

+621
-214
lines changed
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
name: Build Dev Assets
2+
3+
permissions:
4+
pull-requests: write
5+
contents: write
6+
7+
on:
8+
pull_request:
9+
branches:
10+
- docker-dev
11+
12+
env:
13+
INTERPRETER: "3.12"
14+
RUSTFLAGS: "-C debuginfo=0"
15+
BINARY_NAME: "scouter-server"
16+
17+
jobs:
18+
build:
19+
name: build - ${{ matrix.target }} - ${{ matrix.feature }} - ${{ matrix.tag }}
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
include:
24+
- os: ubuntu-22.04-arm
25+
target: aarch64-unknown-linux-gnu
26+
archive_ext: tar.gz
27+
container_image: rockylinux:9
28+
tag: rocky
29+
archive_name_suffix: -rocky
30+
feature: kafka
31+
32+
- os: ubuntu-22.04-arm
33+
target: aarch64-unknown-linux-gnu
34+
archive_ext: tar.gz
35+
container_image: null
36+
tag: ubuntu
37+
archive_name_suffix: ""
38+
feature: kafka
39+
40+
runs-on: ${{ matrix.os}}
41+
container: ${{ matrix.container_image != null && matrix.container_image || null }}
42+
43+
steps:
44+
- name: Checkout repository
45+
uses: actions/checkout@v4
46+
with:
47+
fetch-depth: 0
48+
49+
- name: Install Rocky Deps
50+
if: matrix.container_image == 'rockylinux:9'
51+
run: |
52+
dnf install -y --allowerasing gcc make curl pkgconf openssl-devel wget perl pkg-config
53+
54+
# Install Rust via rustup
55+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
56+
57+
# Add Rust to PATH for subsequent steps
58+
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
59+
60+
# Source for this step
61+
source $HOME/.cargo/env
62+
63+
echo "Installing CMake 3.26.4..."
64+
curl -L https://github.com/Kitware/CMake/releases/download/v3.26.4/cmake-3.26.4-linux-aarch64.sh -o cmake.sh
65+
chmod +x cmake.sh
66+
./cmake.sh --skip-license --prefix=/usr/local
67+
cmake --version
68+
69+
- name: Update apt repositories (Linux)
70+
if: contains(matrix.os, 'ubuntu') && matrix.container_image == null
71+
run: |
72+
sudo apt-get update -y
73+
sudo apt-get install -y build-essential
74+
75+
- name: Set up Rust
76+
run: |
77+
rustup override set stable
78+
rustup update
79+
rustup target add ${{ matrix.target }}
80+
rustup component add rust-src
81+
82+
- name: Build binaries
83+
run: |
84+
# Ensure -p is used for the correct package
85+
cargo build -p scouter-server \
86+
--target ${{ matrix.target }} \
87+
--features ${{ matrix.feature }}
88+
89+
- name: Prepare and Archive binary
90+
id: prepare
91+
shell: bash
92+
run: |
93+
# Create the unique base name including target, feature, and suffix
94+
ARTIFACT_BASE_NAME="${{ env.BINARY_NAME }}-${{ matrix.target }}-${{ matrix.feature }}${{ matrix.archive_name_suffix }}"
95+
ARTIFACT_ARCHIVE_NAME="${ARTIFACT_BASE_NAME}.${{ matrix.archive_ext }}"
96+
97+
mkdir -p release-bin
98+
# Copy the binary from the target directory
99+
cp target/${{ matrix.target }}/debug/${{ env.BINARY_NAME }} release-bin/
100+
chmod +x release-bin/${{ env.BINARY_NAME }}
101+
102+
# Create archive
103+
cd release-bin
104+
# This command must be on its own line
105+
tar -czf ../${ARTIFACT_ARCHIVE_NAME} ./*
106+
107+
# Now, echo the outputs to $GITHUB_OUTPUT on new lines
108+
echo "ARTIFACT_BASE_NAME=${ARTIFACT_BASE_NAME}" >> $GITHUB_OUTPUT
109+
echo "ARTIFACT_ARCHIVE_NAME=${ARTIFACT_ARCHIVE_NAME}" >> $GITHUB_OUTPUT
110+
111+
- name: Upload artifact
112+
uses: actions/upload-artifact@v4
113+
with:
114+
name: ${{ steps.prepare.outputs.ARTIFACT_BASE_NAME }}
115+
path: ${{ steps.prepare.outputs.ARTIFACT_ARCHIVE_NAME }}
116+
retention-days: 1
117+
118+
publish-docker-images-arm64:
119+
needs: build
120+
name: Publish ARM64 Docker images - ${{ matrix.image }} - ${{ matrix.feature }}
121+
runs-on: ubuntu-22.04
122+
strategy:
123+
fail-fast: false
124+
matrix:
125+
include:
126+
- image: ubuntu
127+
tag_suffix: ubuntu
128+
artifact: scouter-server-aarch64-unknown-linux-gnu-kafka
129+
feature: kafka
130+
131+
- image: rocky
132+
tag_suffix: rocky-minimal
133+
artifact: scouter-server-aarch64-unknown-linux-gnu-kafka-rocky
134+
feature: kafka
135+
steps:
136+
- name: Checkout Code
137+
uses: actions/checkout@v4
138+
139+
- name: Set up QEMU
140+
uses: docker/setup-qemu-action@v3
141+
142+
- name: Set up Docker Buildx
143+
uses: docker/setup-buildx-action@v3
144+
145+
- name: Download ARM64 Linux binary artifact
146+
uses: actions/download-artifact@v4
147+
with:
148+
name: ${{ matrix.artifact }}
149+
path: ./artifacts
150+
151+
- name: List downloaded files
152+
run: ls -la ./artifacts
153+
154+
- name: Extract binary
155+
run: |
156+
archive="./artifacts/${{ matrix.artifact }}.tar.gz"
157+
if [ -f "$archive" ]; then
158+
mkdir -p binary
159+
tar -xzf "$archive" -C ./binary
160+
chmod +x ./binary/scouter-server
161+
else
162+
echo "ARM64 binary $archive not found, skipping this build"
163+
exit 1
164+
fi
165+
166+
- name: Set version tag
167+
id: set-version
168+
run: |
169+
# Use a default version tag of 'dev' for PRs
170+
echo "VERSION=dev" >> $GITHUB_OUTPUT
171+
172+
- name: Login to DockerHub
173+
uses: docker/login-action@v3
174+
with:
175+
username: ${{ secrets.DOCKER_USERNAME }}
176+
password: ${{ secrets.DOCKER_PASSWORD }}
177+
178+
- name: Build and push ARM64 image
179+
uses: docker/build-push-action@v5
180+
with:
181+
context: .
182+
file: docker/official/${{ matrix.image }}/Dockerfile
183+
push: true
184+
platforms: linux/arm64
185+
build-args: |
186+
SCOUTER_SERVER_BINARY=./binary/${{ env.BINARY_NAME }}
187+
TINI_BIN=tini-arm64
188+
tags: |
189+
demml/scouter:${{ matrix.tag_suffix }}-arm64-${{ steps.set-version.outputs.VERSION }}-${{ matrix.feature }}
190+
cache-from: type=gha
191+
cache-to: type=gha,mode=max

0 commit comments

Comments
 (0)