Skip to content

Commit eeca155

Browse files
FrankYang0529innobead
authored andcommitted
ci: change to use GitHub actions
Signed-off-by: PoAn Yang <[email protected]> (cherry picked from commit 8df21c2)
1 parent 9724096 commit eeca155

File tree

5 files changed

+124
-28
lines changed

5 files changed

+124
-28
lines changed

.github/workflows/build.yml

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: build
2+
on:
3+
push:
4+
branches:
5+
- master
6+
- v*
7+
tags:
8+
- v*
9+
pull_request:
10+
jobs:
11+
build:
12+
name: Build binaries
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
18+
# Build binaries
19+
- name: Run ci
20+
run: make ci
21+
22+
- uses: codecov/codecov-action@v4
23+
with:
24+
files: ./coverage.out
25+
flags: unittests
26+
token: ${{ secrets.CODECOV_TOKEN }}
27+
28+
- name: Upload binaries
29+
uses: actions/upload-artifact@v4
30+
with:
31+
name: binaries_artifact
32+
path: ./bin/*
33+
34+
build_push_image:
35+
name: Build and push image
36+
runs-on: ubuntu-latest
37+
needs: build
38+
if: ${{ startsWith(github.ref, 'refs/heads/') || startsWith(github.ref, 'refs/tags/') }}
39+
steps:
40+
- name: Checkout code
41+
uses: actions/checkout@v4
42+
43+
- name: Download binaries
44+
uses: actions/download-artifact@v4
45+
with:
46+
name: binaries_artifact
47+
path: ./bin/
48+
49+
- name: Add executable permission
50+
run: |
51+
chmod +x ./bin/*
52+
53+
- name: Copy bin folder to package
54+
run: |
55+
cp -r ./bin ./package/
56+
57+
# For multi-platform support
58+
- name: Set up QEMU
59+
uses: docker/setup-qemu-action@v3
60+
- name: Set up Docker Buildx
61+
uses: docker/setup-buildx-action@v3
62+
63+
- name: Declare branch
64+
run: |
65+
echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> "$GITHUB_ENV"
66+
67+
- name: Login to Docker Hub
68+
uses: docker/login-action@v3
69+
with:
70+
username: ${{ secrets.DOCKER_USERNAME }}
71+
password: ${{ secrets.DOCKER_PASSWORD }}
72+
73+
# longhornio/backing-image-manager image
74+
- name: docker-publish
75+
if: ${{ startsWith(github.ref, 'refs/heads/') }}
76+
uses: docker/build-push-action@v5
77+
with:
78+
context: ./
79+
push: true
80+
platforms: linux/amd64,linux/arm64
81+
tags: longhornio/backing-image-manager:${{ env.branch }}-head
82+
file: package/Dockerfile
83+
84+
- name: docker-publish-with-tag
85+
if: ${{ startsWith(github.ref, 'refs/tags/') }}
86+
uses: docker/build-push-action@v5
87+
with:
88+
context: ./
89+
push: true
90+
platforms: linux/amd64,linux/arm64
91+
tags: longhornio/backing-image-manager:${{ github.ref_name }}
92+
file: package/Dockerfile

Dockerfile.dapper

+5
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ ENV GOLANG_ARCH_amd64=amd64 GOLANG_ARCH_arm64=arm64 GOLANG_ARCH_s390x=s390x GOLA
3636
RUN wget -O - https://storage.googleapis.com/golang/go1.21.3.linux-${!GOLANG_ARCH}.tar.gz | tar -xzf - -C /usr/local
3737
RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.55.2
3838

39+
# The docker version in dapper is too old to have buildx. Install it manually.
40+
RUN wget https://github.com/docker/buildx/releases/download/v0.13.1/buildx-v0.13.1.linux-${ARCH} && \
41+
chmod +x buildx-v0.13.1.linux-${ARCH} && \
42+
mv buildx-v0.13.1.linux-${ARCH} /usr/local/bin/buildx
43+
3944
VOLUME /tmp
4045
ENV TMPDIR /tmp
4146
ENTRYPOINT ["./scripts/entry"]

package/Dockerfile

+13-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
1-
FROM registry.suse.com/bci/bci-base:15.5
1+
# syntax=docker/dockerfile:1.7.1
22

3-
ARG ARCH=amd64
3+
FROM registry.suse.com/bci/bci-base:15.6
4+
5+
ARG TARGETPLATFORM
6+
RUN if [ "$TARGETPLATFORM" != "linux/amd64" ] && [ "$TARGETPLATFORM" != "linux/arm64" ]; then \
7+
echo "Error: Unsupported TARGETPLATFORM: $TARGETPLATFORM" && \
8+
exit 1; \
9+
fi
10+
11+
ENV ARCH ${TARGETPLATFORM#linux/}
412

513
RUN zypper -n addrepo --refresh https://download.opensuse.org/repositories/system:/snappy/SLE_15/system:snappy.repo && \
614
zypper -n addrepo --refresh https://download.opensuse.org/repositories/network:/utilities/SLE_15_SP5/network:utilities.repo && \
715
zypper --gpg-auto-import-keys ref
816

917
RUN zypper -n install kmod curl wget nfs-client nfs4-acl-tools fuse \
10-
librdmacm1 librdmacm-utils libibverbs perl-Config-General libaio-devel sg3_utils \
11-
iputils telnet iperf qemu-tools iproute2 e2fsprogs e2fsprogs-devel xfsprogs xfsprogs-devel
18+
librdmacm1 librdmacm-utils libibverbs perl-Config-General libaio-devel sg3_utils \
19+
iputils telnet iperf qemu-tools iproute2 e2fsprogs e2fsprogs-devel xfsprogs xfsprogs-devel
1220

13-
COPY bin/backing-image-manager /usr/local/bin/
21+
COPY package/bin/backing-image-manager-${ARCH} /usr/local/bin/backing-image-manager
1422

1523
VOLUME /usr/local/bin
1624

scripts/build

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
#!/bin/bash
2-
set -e
2+
set -ex
33

44
source $(dirname $0)/version
55

6+
LINKFLAGS="-X main.Version=$VERSION
7+
-X main.GitCommit=$GITCOMMIT
8+
-X main.BuildDate=$BUILDDATE"
9+
[ "$(uname)" != "Darwin" ] && OTHER_LINKFLAGS="-extldflags -static"
10+
611
cd $(dirname $0)/..
712

813
mkdir -p bin
9-
go build -ldflags \
10-
"-X main.Version=$VERSION \
11-
-X main.GitCommit=$GITCOMMIT \
12-
-X main.BuildDate=$BUILDDATE \
13-
-linkmode external -extldflags -static" \
14-
-o bin/backing-image-manager
14+
15+
archs=("amd64" "arm64")
16+
for arch in "${archs[@]}"; do
17+
CGO_ENABLED=0 GOARCH="$arch" go build -o "bin/backing-image-manager-$arch" -ldflags "$LINKFLAGS $OTHER_LINKFLAGS"
18+
done

scripts/package

+3-16
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,18 @@ cd $(dirname $0)/..
77

88
PROJECT=`basename "$PWD"`
99

10-
case $(uname -m) in
11-
aarch64 | arm64)
12-
ARCH=arm64
13-
;;
14-
x86_64)
15-
ARCH=amd64
16-
;;
17-
s390x)
18-
ARCH=s390x
19-
;;
20-
*)
21-
echo "$(uname -a): unsupported architecture"
22-
exit 1
23-
esac
24-
2510
if [ ! -x ./bin/longhorn ]; then
2611
./scripts/build
2712
fi
2813

14+
cp -r bin package/
15+
2916
APIVERSION=`./bin/backing-image-manager version --client-only|jq ".clientVersion.backingImageManagerAPIVersion"`
3017
TAG="v${APIVERSION}_`date -u +%Y%m%d`"
3118
REPO=${REPO:-longhornio}
3219
IMAGE=${REPO}/${PROJECT}:${TAG}
3320

34-
docker build --build-arg ARCH=${ARCH} --no-cache -t ${IMAGE} -f package/Dockerfile .
21+
buildx build --load --no-cache -t ${IMAGE} -f package/Dockerfile .
3522

3623
echo Built ${IMAGE}
3724

0 commit comments

Comments
 (0)