Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ci): collect and release binaries and image #24

Merged
merged 1 commit into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 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,86 @@ 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 checksum
- name: Create sha256 checksum
run: mkdir -p checksum && cd bin && for i in *; do sha256sum -b $i > "../checksum/$i.sha256"; done && cd -

# Upload binaries to release
- name: Upload binaries to release
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
bin/longhornctl*
checksum/longhornctl*
env:
GITHUB_TOKEN: ${{ secrets.CUSTOM_GITHUB_TOKEN }}

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