Skip to content

Commit

Permalink
ci: change to use GitHub actions
Browse files Browse the repository at this point in the history
Signed-off-by: PoAn Yang <poan.yang@suse.com>
  • Loading branch information
FrankYang0529 committed Apr 25, 2024
1 parent 7f003f1 commit 4253429
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 10 deletions.
94 changes: 94 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: build
on:
push:
branches:
- master
- v*
tags:
- v*
pull_request:
jobs:
build:
name: Build binaries
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}

# Build binaries
- name: Run ci
run: make ci

- uses: codecov/codecov-action@v4
with:
files: ./coverage.out
flags: unittests
token: ${{ secrets.CODECOV_TOKEN }}

- name: Upload binaries
uses: actions/upload-artifact@v4
with:
name: binaries_artifact
path: ./bin/*

build_push_image:
name: Build and push image
runs-on: ubuntu-latest
needs: build
if: ${{ startsWith(github.ref, 'refs/heads/') || startsWith(github.ref, 'refs/tags/') }}
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Download binaries
uses: actions/download-artifact@v4
with:
name: binaries_artifact
path: ./bin/

- name: Add executable permission
run: |
chmod +x ./bin/*
- name: Copy bin folder to package
run: |
cp -r ./bin ./package/
# For multi-platform support
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Declare branch
run: |
echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> "$GITHUB_ENV"
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

# longhorn/longhorn-manager image
- name: docker-publish
if: ${{ startsWith(github.ref, 'refs/heads/') }}
uses: docker/build-push-action@v5
with:
context: ./
push: true
platforms: linux/amd64,linux/arm64
tags: longhorn/longhorn-manager:${{ env.branch }}-head
file: package/Dockerfile

- name: docker-publish-with-tag
if: ${{ startsWith(github.ref, 'refs/tags/') }}
uses: docker/build-push-action@v5
with:
context: ./
push: true
platforms: linux/amd64,linux/arm64
tags: longhorn/longhorn-manager:${{ github.ref_name }}
file: package/Dockerfile
7 changes: 6 additions & 1 deletion Dockerfile.dapper
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM registry.suse.com/bci/bci-base:15.6

ARG DAPPER_HOST_ARCH=amd64
ARG DAPPER_HOST_ARCH
ARG http_proxy
ARG https_proxy
ENV HOST_ARCH=${DAPPER_HOST_ARCH} ARCH=${DAPPER_HOST_ARCH}
Expand All @@ -20,6 +20,11 @@ RUN wget -O - https://storage.googleapis.com/golang/go1.21.3.linux-${!GOLANG_ARC

RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.55.2

# The docker version in dapper is too old to have buildx. Install it manually.
RUN wget https://github.com/docker/buildx/releases/download/v0.13.1/buildx-v0.13.1.linux-${ARCH} && \
chmod +x buildx-v0.13.1.linux-${ARCH} && \
mv buildx-v0.13.1.linux-${ARCH} /usr/local/bin/buildx

ENV DAPPER_SOURCE /go/src/github.com/longhorn/longhorn-manager
ENV DAPPER_OUTPUT ./bin coverage.out
ENV DAPPER_DOCKER_SOCKET true
Expand Down
16 changes: 14 additions & 2 deletions package/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
# syntax=docker/dockerfile:1.7.0

FROM registry.suse.com/bci/bci-base:15.6

ARG TARGETPLATFORM
RUN if [ "$TARGETPLATFORM" != "linux/amd64" ] && [ "$TARGETPLATFORM" != "linux/arm64" ]; then \
echo "Error: Unsupported TARGETPLATFORM: $TARGETPLATFORM" && \
exit 1; \
fi

ENV ARCH ${TARGETPLATFORM#linux/}

COPY package/bin/longhorn-manager-${ARCH} /usr/local/sbin/longhorn-manager

COPY package/launch-manager package/nsmounter /usr/local/sbin/

RUN zypper -n install iputils iproute2 nfs-client cifs-utils bind-utils e2fsprogs xfsprogs zip unzip && \
rm -rf /var/cache/zypp/*

COPY bin package/launch-manager package/nsmounter /usr/local/sbin/

VOLUME /usr/local/sbin
EXPOSE 9500
CMD ["launch-manager"]
3 changes: 2 additions & 1 deletion scripts/build
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ cd $(dirname $0)/..

mkdir -p bin

CGO_ENABLED=0 go build -o bin/longhorn-manager -ldflags "$LINKFLAGS $OTHER_LINKFLAGS" $COVER $COVERPKG
CGO_ENABLED=0 GOARCH=amd64 go build -o bin/longhorn-manager-amd64 -ldflags "$LINKFLAGS $OTHER_LINKFLAGS" $COVER $COVERPKG
CGO_ENABLED=0 GOARCH=arm64 go build -o bin/longhorn-manager-arm64 -ldflags "$LINKFLAGS $OTHER_LINKFLAGS" $COVER $COVERPKG
10 changes: 4 additions & 6 deletions scripts/package
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,23 @@ source $(dirname $0)/version

cd $(dirname $0)/..

ARCH=${ARCH:-amd64}
SUFFIX=""
[ "${ARCH}" != "amd64" ] && SUFFIX="_${ARCH}"

TAG=${TAG:-${IMAGE_TAG_PREFIX}${SUFFIX}}
TAG=${TAG:-${IMAGE_TAG_PREFIX}}
REPO=${REPO:-longhornio}
IMAGE=${IMAGE:-${REPO}/longhorn-manager:${TAG}}

if [ ! -e ./bin/longhorn-manager ]; then
./scripts/build
fi

cp -r bin package/

trap 'rm -rf ./package/bin' exit

# update base image to get latest changes
BASE_IMAGE=`grep FROM package/Dockerfile | awk '{print $2}'`
docker pull ${BASE_IMAGE}

docker build -t ${IMAGE} -f package/Dockerfile .
buildx build --load -t ${IMAGE} -f package/Dockerfile .

echo Built ${IMAGE}

Expand Down

0 comments on commit 4253429

Please sign in to comment.