Skip to content

Commit

Permalink
feat(ci): collect and release binaries and image
Browse files Browse the repository at this point in the history
Longhorn 8980

Signed-off-by: Derek Su <[email protected]>
  • Loading branch information
derekbit committed Jul 11, 2024
1 parent 980da35 commit 90343da
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 4 deletions.
88 changes: 88 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ on:
push:
branches:
- master
- v*
tags:
- v*
pull_request:
jobs:
build:
Expand All @@ -21,3 +24,88 @@ jobs:
files: ./coverage.out
flags: unittests
token: ${{ secrets.CODECOV_TOKEN }}

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

# Calculate sha256 and sha12 checksum
- name: Create sha256 checksum
run: mkdir -p checksum && cd bin && for i in *; do sha256sum -b $i > "../checksum/$i.sha256"; done && cd -

- name: Create sha512 checksum
run: mkdir -p checksum && cd bin && for i in *; do sha512sum -b $i > "../checksum/$i.sha512"; done && cd -

# Upload binaries to release
- name: Upload binaries to release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: '{bin/longhornctl*,checksum/longhornctl*}'
tag: ${{ github.ref }}
overwrite: true
file_glob: true

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 }}

# longhornio/longhorn-cli 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: longhornio/longhorn-cli:${{ env.branch }}-head
file: package/Dockerfile
sbom: true

- 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: longhornio/longhorn-cli:${{ github.ref_name }}
file: package/Dockerfile
sbom: true
14 changes: 10 additions & 4 deletions dapper/build
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,27 @@ LINKFLAGS="-extldflags -static -s"
build_app() {
local _dir=$1
local _app=$2
local _os=$3
local _arch=$4

cd "${ROOT_DIR}/cmd/${_dir}"

[ "$(uname)" != "Darwin" ] && LINKFLAGS="-extldflags -static -s"
CGO_ENABLED=0 go build -ldflags \
CGO_ENABLED=0 GOARCH=${_arch} GOOS=${_os} go build -ldflags \
"-X github.com/longhorn/cli/meta.Version=$VERSION \
-X github.com/longhorn/cli/meta.GitCommit=$GITCOMMIT \
-X github.com/longhorn/cli/meta.BuildDate=$BUILDDATE \
$LINKFLAGS" -o ${ROOT_DIR}/bin/${_app}
$LINKFLAGS" -o ${ROOT_DIR}/bin/${_app}-${_os}-${_arch}
}

source "${ROOT_DIR}/dapper/version"

mkdir -p "${ROOT_DIR}/bin"
echo "Making binary at ${ROOT_DIR}/bin"

build_app local longhornctl-local
build_app remote longhornctl
for os in linux; do
for arch in amd64 arm64; do
build_app local longhornctl-local ${os} ${arch}
build_app remote longhornctl ${os} ${arch}
done
done

0 comments on commit 90343da

Please sign in to comment.