Skip to content

Commit 953146a

Browse files
liuchangyanhao022
authored andcommitted
ci: add nostatic process of bamai release
Signed-off-by: Teresaliu <teresaliu@didiglobal.com>
1 parent a0fb352 commit 953146a

5 files changed

Lines changed: 95 additions & 27 deletions

File tree

.github/workflows/docker-image-latest-push.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,22 @@ jobs:
2121
with:
2222
username: ${{ secrets.DOCKERHUB_USERNAME }}
2323
password: ${{ secrets.DOCKERHUB_TOKEN }}
24-
- name: Build and push
24+
- name: Build and push (static)
2525
uses: docker/build-push-action@v2
2626
with:
2727
context: .
2828
file: ./Dockerfile
2929
platforms: linux/amd64,linux/arm64/v8
3030
push: ${{ github.event_name != 'pull_request' }}
31+
tags: huatuo/huatuo-bamai-static:latest
32+
33+
- name: Build and push (nostatic)
34+
uses: docker/build-push-action@v2
35+
with:
36+
context: .
37+
file: ./Dockerfile
38+
platforms: linux/amd64,linux/arm64/v8
39+
push: ${{ github.event_name != 'pull_request' }}
40+
build-args: |
41+
BUILD_MODE=nostatic
3142
tags: huatuo/huatuo-bamai:latest

.github/workflows/docker-version-release-by-tag.yml

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,35 +21,48 @@ jobs:
2121
with:
2222
username: ${{ secrets.DOCKERHUB_USERNAME }}
2323
password: ${{ secrets.DOCKERHUB_TOKEN }}
24-
- name: Build and push
24+
- name: Build and push (static)
2525
uses: docker/build-push-action@v2
2626
with:
2727
context: .
2828
file: ./Dockerfile
2929
platforms: linux/amd64,linux/arm64
3030
push: true
31+
tags: huatuo/huatuo-bamai-static:${{ github.ref_name }}
32+
- name: Build and push (nostatic)
33+
uses: docker/build-push-action@v2
34+
with:
35+
context: .
36+
file: ./Dockerfile
37+
platforms: linux/amd64,linux/arm64
38+
push: true
39+
build-args: |
40+
BUILD_MODE=nostatic
3141
tags: huatuo/huatuo-bamai:${{ github.ref_name }}
32-
- name: Extract files
42+
43+
- name: Extract files (static)
3344
run: |
3445
# same as docker build platforms
46+
set -euo pipefail
3547
platforms="amd64 arm64"
3648
for arch in $platforms; do
3749
tag=${{ github.ref_name }}
38-
tmpdir="huatuo-${tag}-linux-${arch}"
39-
40-
docker create --platform linux/${arch} --name tmp-container huatuo/huatuo-bamai:${tag}
41-
docker cp tmp-container:/home/huatuo-bamai .
42-
docker rm tmp-container
43-
50+
tmpdir="huatuo-bamai-${tag}-static-linux-${arch}"
51+
tmp_container="tmp_${tag}_static_${arch}"
52+
docker create \
53+
--platform "linux/${arch}" \
54+
--name "${tmp_container}" \
55+
huatuo/huatuo-bamai-static:${tag}
56+
57+
docker cp "${tmp_container}:/home/huatuo-bamai" .
58+
docker rm "${tmp_container}"
4459
mv huatuo-bamai $tmpdir
45-
4660
cp LICENSE $tmpdir
47-
4861
file $tmpdir/bin/huatuo-bamai
49-
5062
tree $tmpdir
5163
tar zcf ${tmpdir}.tar.gz ${tmpdir}
5264
done
65+
5366
- name: Release
5467
uses: softprops/action-gh-release@v2
5568
with:
@@ -59,4 +72,4 @@ jobs:
5972
token: ${{ secrets.HUATUO_RELEASE_TOKEN }}
6073
body_path: docs/CHANGELOG/CHANGELOG-${{ github.ref_name }}.md
6174
files: |
62-
huatuo-${{ github.ref_name }}-linux-*.tar.gz
75+
huatuo-bamai-static-${{ github.ref_name }}-linux-*.tar.gz

Dockerfile

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,54 @@
1+
ARG BUILD_MODE
2+
3+
# Base docker image
4+
FROM golang:1.24-alpine3.22 AS base-static
5+
#
6+
# To accelerate the build process, you may uncomment this section.
7+
# RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
8+
#
9+
RUN apk add --no-cache build-base make clang15 libbpf-dev curl git
10+
ENV PATH=$PATH:/usr/lib/llvm15/bin
11+
112
# Base docker image
2-
FROM golang:1.24-alpine3.22 AS base
13+
FROM golang:1.24 AS base-nostatic
314
#
415
# To accelerate the build process, you may uncomment this section.
516
# RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
617
#
7-
RUN apk add --no-cache make clang15 libbpf-dev curl git
18+
RUN apt-get update && apt-get install -y --no-install-recommends \
19+
make clang libbpf-dev bpftool curl git binutils-gold musl-tools
820
ENV PATH=$PATH:/usr/lib/llvm15/bin
921

1022
# Build release version
11-
FROM base AS build
23+
FROM base-${BUILD_MODE:-static} AS build
24+
ARG BUILD_MODE=static
1225
ARG BUILD_PATH="/go/huatuo-bamai"
1326
ARG RUN_PATH="/home/huatuo-bamai"
1427
WORKDIR ${BUILD_PATH}
1528
COPY . .
16-
RUN make && mkdir -p ${RUN_PATH} && cp -rf ${BUILD_PATH}/_output/* ${RUN_PATH}/
29+
RUN make BUILD_MODE=${BUILD_MODE} \
30+
&& mkdir -p ${RUN_PATH} \
31+
&& cp -rf ${BUILD_PATH}/_output/* ${RUN_PATH}/
1732
# Disable the elasticsearch and kubelet fetching pods.
1833
RUN sed -i -e 's/# Address.*/Address=""/g' \
1934
-e '$a\ KubeletReadOnlyPort=0' \
2035
-e '$a\ KubeletAuthorizedPort=0' ${RUN_PATH}/conf/huatuo-bamai.conf
2136

2237
# Release docker image
23-
FROM alpine:3.22.0 AS run
38+
FROM alpine:3.22.0 AS run-static
2439
ARG RUN_PATH="/home/huatuo-bamai"
2540
RUN apk add --no-cache curl
2641
COPY --from=build ${RUN_PATH} ${RUN_PATH}
2742
WORKDIR ${RUN_PATH}
43+
44+
# Release docker image
45+
FROM debian:bookworm-slim AS run-nostatic
46+
ARG RUN_PATH="/home/huatuo-bamai"
47+
RUN apt-get update && apt-get install -y --no-install-recommends \
48+
curl libelf1 libnuma1 \
49+
&& rm -rf /var/lib/apt/lists/*
50+
COPY --from=build ${RUN_PATH} ${RUN_PATH}
51+
WORKDIR ${RUN_PATH}
52+
53+
FROM run-${BUILD_MODE:-static}
2854
CMD ["./bin/huatuo-bamai", "--region", "example", "--config", "huatuo-bamai.conf"]

Makefile

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,34 @@ APP_CMD_OUTPUT := _output
1212
APP_CMD_SUBDIRS := $(shell find $(APP_CMD_DIR) -mindepth 1 -maxdepth 1 -type d)
1313
APP_CMD_BIN_TARGETS := $(patsubst %,$(APP_CMD_OUTPUT)/bin/%,$(notdir $(APP_CMD_SUBDIRS)))
1414

15-
GO_BUILD_STATIC := CGO_ENABLED=1 go build -tags "netgo osusergo" -gcflags=all="-N -l"
16-
GO_BUILD_STATIC_WITH_VERSION := $(GO_BUILD_STATIC) -ldflags "-extldflags -static \
15+
GO_BUILD_FLAGS := CGO_ENABLED=1 go build -tags "netgo osusergo" -gcflags=all="-N -l"
16+
GO_VERSION_LDFLAGS := \
1717
-X main.AppVersion=$(APP_VERSION) \
1818
-X main.AppGitCommit=$(APP_COMMIT) \
19-
-X main.AppBuildTime=$(APP_BUILD_TIME)"
19+
-X main.AppBuildTime=$(APP_BUILD_TIME)
2020

21-
IMAGE_LATEST := huatuo/huatuo-bamai:latest
21+
GO_BUILD_STATIC := $(GO_BUILD_FLAGS) -ldflags "-extldflags -static $(GO_VERSION_LDFLAGS)"
22+
GO_BUILD_NOSTATIC := $(GO_BUILD_FLAGS) -ldflags "$(GO_VERSION_LDFLAGS)"
23+
24+
BUILD_MODE ?= static
25+
26+
IMAGE_TAG := latest
27+
28+
ifeq ($(BUILD_MODE),nostatic)
29+
GO_BUILD_IMPL := $(GO_BUILD_NOSTATIC)
30+
IMAGE_REPO := huatuo/huatuo-bamai
31+
else
32+
GO_BUILD_IMPL := $(GO_BUILD_STATIC)
33+
IMAGE_REPO := huatuo/huatuo-bamai-static
34+
endif
35+
36+
IMAGE := $(IMAGE_REPO):$(IMAGE_TAG)
2237

2338
all: bpf-build sync build
2439

40+
build-nostatic:
41+
@$(MAKE) BUILD_MODE=nostatic all
42+
2543
bpf-build:
2644
@BPF_DIR=$(BPF_DIR) BPF_COMPILE=$(BPF_COMPILE) BPF_INCLUDE=$(BPF_INCLUDE) go generate -run "BPF_COMPILE" -x ./...
2745

@@ -32,13 +50,13 @@ sync:
3250

3351
build: $(APP_CMD_BIN_TARGETS)
3452
$(APP_CMD_OUTPUT)/bin/%: $(APP_CMD_DIR)/% force
35-
$(GO_BUILD_STATIC_WITH_VERSION) -o $@ ./$<
53+
$(GO_BUILD_IMPL) -o $@ ./$<
3654

3755
docker-build:
38-
@docker build --network=host --no-cache -t $(IMAGE_LATEST) -f Dockerfile .
56+
@docker build --network=host --no-cache -t $(IMAGE) -f Dockerfile .
3957

4058
docker-clean:
41-
@docker rmi $(IMAGE_LATEST) || true
59+
@docker rmi $(IMAGE) || true
4260

4361
check: import-fmt golangci-lint
4462
@git diff --exit-code
@@ -69,4 +87,4 @@ integration: all mock-build
6987

7088
force:;
7189

72-
.PHONY: all bpf-build mock-build sync build check import-fmt golangci-lint vendor clean integration force docker-build docker-clean
90+
.PHONY: all build-nostatic bpf-build mock-build sync build check import-fmt golangci-lint vendor clean integration force docker-build docker-clean

huatuo-bamai.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
# The global blacklist for tracing and metrics
3-
BlackList = ["netdev_hw"]
3+
BlackList = ["netdev_hw", "metax_gpu"]
44

55
# Log Configuration
66
#

0 commit comments

Comments
 (0)