Skip to content

Commit 57d7eaf

Browse files
committed
feat: add continuous deployment workflow and refactor Docker setup
1 parent 18f7972 commit 57d7eaf

File tree

4 files changed

+125
-21
lines changed

4 files changed

+125
-21
lines changed

.github/workflows/cd.yml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
name: CD
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
tags:
7+
- 'v*'
8+
9+
jobs:
10+
build:
11+
name: Build for ${{ matrix.platform }}
12+
runs-on: ${{ matrix.runs-on }}
13+
strategy:
14+
matrix:
15+
include:
16+
- platform: linux/amd64
17+
runs-on: ubuntu-latest
18+
arch: amd64
19+
- platform: linux/arm64
20+
runs-on: ubuntu-24.04-arm
21+
arch: arm64
22+
23+
steps:
24+
- name: Checkout code
25+
uses: actions/checkout@v3
26+
27+
- name: Build dist directory
28+
run: make build
29+
30+
- name: Set up Docker Buildx
31+
uses: docker/setup-buildx-action@v2
32+
33+
- name: Docker metadata
34+
id: meta
35+
uses: docker/metadata-action@v4
36+
with:
37+
images: ghcr.io/${{ github.repository }}
38+
flavor: |
39+
suffix=-${{ matrix.arch }}
40+
tags: |
41+
type=raw,value=latest
42+
type=sha
43+
type=ref,event=tag
44+
45+
- name: Log in to GitHub Container Registry
46+
uses: docker/login-action@v2
47+
with:
48+
registry: ghcr.io
49+
username: ${{ github.actor }}
50+
password: ${{ secrets.GITHUB_TOKEN }}
51+
52+
- name: Build and push single-platform Docker image
53+
uses: docker/build-push-action@v4
54+
with:
55+
context: .
56+
push: true
57+
platforms: ${{ matrix.platform }}
58+
tags: ${{ steps.meta.outputs.tags }}
59+
labels: ${{ steps.meta.outputs.labels }}
60+
cache-from: type=gha,scope=${{ matrix.platform }}
61+
cache-to: type=gha,mode=max,scope=${{ matrix.platform }}
62+
63+
merge-manifests:
64+
name: Merge Multi-Arch Manifests
65+
needs: build
66+
runs-on: ubuntu-latest
67+
permissions:
68+
contents: read
69+
packages: write
70+
71+
steps:
72+
- name: Set up Docker Buildx
73+
uses: docker/setup-buildx-action@v2
74+
75+
- name: Docker metadata for final image
76+
id: meta
77+
uses: docker/metadata-action@v4
78+
with:
79+
images: ghcr.io/${{ github.repository }}
80+
tags: |
81+
type=raw,value=latest
82+
type=sha
83+
type=ref,event=tag
84+
85+
- name: Log in to GitHub Container Registry
86+
uses: docker/login-action@v2
87+
with:
88+
registry: ghcr.io
89+
username: ${{ github.actor }}
90+
password: ${{ secrets.GITHUB_TOKEN }}
91+
92+
- name: Create and push manifest list
93+
uses: docker/build-push-action@v4
94+
with:
95+
push: true
96+
tags: ${{ steps.meta.outputs.tags }}
97+
labels: ${{ steps.meta.outputs.labels }}
98+
platforms: linux/amd64,linux/arm64
99+
cache-from: type=gha
100+
cache-to: type=gha,mode=max

Dockerfile

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,4 @@
1-
FROM ubuntu:22.04 AS libbpf_builder
1+
FROM busybox
22

3-
RUN apt-get update && \
4-
apt-get install -y --no-install-recommends git ca-certificates gcc make pkg-config libelf-dev
5-
6-
COPY ./ /build/ebpf_exporter
7-
8-
RUN make -j $(nproc) -C /build/ebpf_exporter libbpf.a && \
9-
tar -C /build/ebpf_exporter/libbpf/dest -czf /build/libbpf.tar.gz .
10-
11-
FROM ubuntu:22.04 AS bpf_builder
12-
13-
# Install dependencies for building eBPF programs
14-
RUN apt-get update && \
15-
apt-get install -y clang make
16-
17-
COPY --from=libbpf_builder /build/ebpf_exporter/libbpf /build/ebpf_exporter/libbpf
18-
19-
COPY ./ /build/ebpf_exporter
20-
21-
RUN make -j $(nproc) -C /build/ebpf_exporter/src CC=clang
3+
# Copy only the dist directory
4+
COPY dist/ /ebpf

Dockerfile.builder

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
FROM ubuntu:22.04 AS libbpf_builder
2+
3+
RUN apt-get update && \
4+
apt-get install -y --no-install-recommends git ca-certificates gcc make pkg-config libelf-dev
5+
6+
COPY ./ /build/ebpf_exporter
7+
8+
RUN make -j $(nproc) -C /build/ebpf_exporter libbpf.a && \
9+
tar -C /build/ebpf_exporter/libbpf/dest -czf /build/libbpf.tar.gz .
10+
11+
FROM ubuntu:22.04 AS bpf_builder
12+
13+
# Install dependencies for building eBPF programs
14+
RUN apt-get update && \
15+
apt-get install -y clang make
16+
17+
COPY --from=libbpf_builder /build/ebpf_exporter/libbpf /build/ebpf_exporter/libbpf
18+
19+
COPY ./ /build/ebpf_exporter
20+
21+
RUN make -j $(nproc) -C /build/ebpf_exporter/src CC=clang

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ clean:
4141
.PHONY: build
4242
build: clean
4343
@echo "Building eBPF programs in Docker..."
44-
@docker build -t ebpf-builder .
44+
@docker build -t ebpf-builder -f Dockerfile.builder .
4545
@docker run --rm -v $(PWD)/dist:/output ebpf-builder sh -c "cp -r /build/ebpf_exporter/dist/* /output && chown -R $(shell id -u):$(shell id -g) /output"
4646
@echo "Copied eBPF programs to dist directory"
4747
@cp -r config/* dist/

0 commit comments

Comments
 (0)