Skip to content

Commit

Permalink
Merge pull request #553 from sctb512/release-different-arch-packages
Browse files Browse the repository at this point in the history
Release nydus-snapshotter packages with different architectures
  • Loading branch information
imeoer authored Dec 7, 2023
2 parents 7b9f4ca + c75cb97 commit 094fb40
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 36 deletions.
70 changes: 43 additions & 27 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,27 @@ env:
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- build-os: linux
build-arch: amd64
build-linker: x86-64
- build-os: linux
build-arch: arm64
build-linker: aarch64
- build-os: linux
build-arch: s390x
build-linker: s390x
- build-os: linux
build-arch: ppc64le
build-linker: powerpc64le
- build-os: linux
build-arch: riscv64
build-linker: riscv64
- build-os: linux
build-arch: static
build-linker: static
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
Expand All @@ -22,9 +43,9 @@ jobs:
uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('go.sum') }}
key: ${{ matrix.build-os }}-go-${{ hashFiles('go.sum') }}
restore-keys: |
${{ runner.os }}-go
${{ matrix.build-os }}-go
- name: cache cargo
uses: actions/cache@v3
with:
Expand All @@ -34,23 +55,29 @@ jobs:
~/.cargo/registry/cache/
~/.cargo/git/db/
tools/optimizer-server/target/
key: ${{ runner.os }}-cargo-${{ hashFiles('tools/optimizer-server/Cargo.lock') }}
key: ${{ matrix.build-os }}-cargo-${{ hashFiles('tools/optimizer-server/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo
${{ matrix.build-os }}-cargo
- name: install gnu gcc linker
run: |
if [ "${{ matrix.build-linker }}" != "static" ]; then
sudo apt-get install -y gcc-${{ matrix.build-linker }}-linux-gnu
fi
- name: build nydus-snapshotter and optimizer
run: |
go install github.com/golangci/golangci-lint/cmd/[email protected]
export PATH=$PATH:$(go env GOPATH)/bin
make static-release
if [ "${{ matrix.build-arch }}" == "static" ]; then
make static-package
else
make package GOOS=${{ matrix.build-os }} GOARCH=${{ matrix.build-arch }}
fi
- name: upload artifacts
uses: actions/upload-artifact@v3
with:
name: nydus-snapshotter_artifacts
name: release-tars-${{ matrix.build-os }}-${{ matrix.build-arch }}
path: |
bin/containerd-nydus-grpc
bin/nydus-overlayfs
bin/optimizer-nri-plugin
bin/optimizer-server
package/*.tar.gz*
upload:
runs-on: ubuntu-latest
needs: [build]
Expand All @@ -59,28 +86,14 @@ jobs:
- name: Download Artifacts
uses: actions/download-artifact@v3
with:
name: nydus-snapshotter_artifacts
path: nydus-snapshotter
- name: Upload Artifacts
run: |
tag=$(echo $GITHUB_REF | cut -d/ -f3-)
tarball="nydus-snapshotter-$tag-x86_64.tgz"
chmod +x nydus-snapshotter/*
tar cf - nydus-snapshotter | gzip > ${tarball}
echo "tag=$tag" >> $GITHUB_ENV
echo "tarball=$tarball" >> $GITHUB_ENV
tarball_shasum="$tarball.sha256sum"
sha256sum $tarball > $tarball_shasum
echo "tarball_shasum=$tarball_shasum" >> $GITHUB_ENV
path: builds
- name: Release
uses: softprops/action-gh-release@v1
with:
name: "Nydus Snapshotter ${{ env.tag }} Release"
generate_release_notes: true
files: |
${{ env.tarball }}
${{ env.tarball_shasum }}
builds/release-tars-**/*
publish-image:
runs-on: ubuntu-latest
Expand All @@ -97,8 +110,11 @@ jobs:
- name: download artifacts
uses: actions/download-artifact@v3
with:
name: nydus-snapshotter_artifacts
name: release-tars-linux-static
path: misc/snapshotter
- name: unpack static release
run: |
cd misc/snapshotter && tar -zxf *.tar.gz && mv bin/* . && rm -rf bin
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
Expand Down
30 changes: 25 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ BUILD_TIMESTAMP=$(shell date '+%Y-%m-%dT%H:%M:%S')
VERSION=$(shell git describe --match 'v[0-9]*' --dirty='.m' --always --tags)
REVISION=$(shell git rev-parse HEAD)$(shell if ! git diff --no-ext-diff --quiet --exit-code; then echo .m; fi)


RELEASE=nydus-snapshotter-$(VERSION:v%=%)-${GOOS}-${GOARCH}
STATIC_RELEASE=nydus-snapshotter-$(VERSION:v%=%)-${GOOS}-static

# Relpace test target images for e2e tests.
ifdef E2E_TEST_TARGET_IMAGES_FILE
ENV_TARGET_IMAGES_FILE = --env-file ${E2E_TEST_TARGET_IMAGES_FILE}
Expand Down Expand Up @@ -48,9 +52,7 @@ DEBUG_LDFLAGS = -X ${PKG}/version.Version=${VERSION} -X ${PKG}/version.Revision=
CARGO ?= $(shell which cargo)
OPTIMIZER_SERVER = tools/optimizer-server
OPTIMIZER_SERVER_TOML = ${OPTIMIZER_SERVER}/Cargo.toml
OPTIMIZER_SERVER_BIN = ${OPTIMIZER_SERVER}/target/release/optimizer-server
STATIC_OPTIMIZER_SERVER_BIN = ${OPTIMIZER_SERVER}/target/x86_64-unknown-linux-gnu/release/optimizer-server

OPTIMIZER_SERVER_BIN = ${OPTIMIZER_SERVER}/bin/optimizer-server
.PHONY: build
build:
GOOS=${GOOS} GOARCH=${GOARCH} ${PROXY} go build -ldflags "$(LDFLAGS)" -v -o bin/containerd-nydus-grpc ./cmd/containerd-nydus-grpc
Expand All @@ -63,13 +65,31 @@ debug:
.PHONY: build-optimizer
build-optimizer:
GOOS=${GOOS} GOARCH=${GOARCH} ${PROXY} go build -ldflags "$(LDFLAGS)" -v -o bin/optimizer-nri-plugin ./cmd/optimizer-nri-plugin
make -C tools/optimizer-server release && cp ${OPTIMIZER_SERVER_BIN} ./bin
make -C tools/optimizer-server release OS=$(GOOS) ARCH=$(GOARCH) && cp ${OPTIMIZER_SERVER_BIN} ./bin

static-release:
CGO_ENABLED=0 ${PROXY} GOOS=${GOOS} GOARCH=${GOARCH} go build -ldflags "$(LDFLAGS) -extldflags -static" -v -o bin/containerd-nydus-grpc ./cmd/containerd-nydus-grpc
CGO_ENABLED=0 ${PROXY} GOOS=${GOOS} GOARCH=${GOARCH} go build -ldflags "$(LDFLAGS) -extldflags -static" -v -o bin/nydus-overlayfs ./cmd/nydus-overlayfs
CGO_ENABLED=0 ${PROXY} GOOS=${GOOS} GOARCH=${GOARCH} go build -ldflags "$(LDFLAGS) -extldflags -static" -v -o bin/optimizer-nri-plugin ./cmd/optimizer-nri-plugin
make -C tools/optimizer-server static-release && cp ${STATIC_OPTIMIZER_SERVER_BIN} ./bin
make -C tools/optimizer-server static-release && cp ${OPTIMIZER_SERVER_BIN} ./bin

package/$(RELEASE).tar.gz: build build-optimizer
mkdir -p package
rm -rf package/$(RELEASE) package/$(RELEASE).tar.gz
tar -czf package/$(RELEASE).tar.gz bin
rm -rf package/$(RELEASE)

package/$(STATIC_RELEASE).tar.gz: static-release
@mkdir -p package
@rm -rf package/$(STATIC_RELEASE) package/$(STATIC_RELEASE).tar.gz
@tar -czf package/$(STATIC_RELEASE).tar.gz bin
@rm -rf package/$(STATIC_RELEASE)

package: package/$(RELEASE).tar.gz
cd package && sha256sum $(RELEASE).tar.gz >$(RELEASE).tar.gz.sha256sum

static-package: package/$(STATIC_RELEASE).tar.gz
@cd package && sha256sum $(STATIC_RELEASE).tar.gz >$(STATIC_RELEASE).tar.gz.sha256sum

# Majorly for cross build for converter package since it is imported by other projects
converter:
Expand Down
2 changes: 1 addition & 1 deletion misc/snapshotter/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ recover_policy = "restart"
# Nydusd worker thread number to handle FUSE or fscache requests, [0-1024].
# Setting to 0 will use the default configuration of nydusd.
threads_number = 4
# Log rotation size for nydusd, in unit MB(megabytes)
# Log rotation size for nydusd, in unit MB(megabytes). (default 100MB)
log_rotation_size = 100

[cgroup]
Expand Down
40 changes: 37 additions & 3 deletions tools/optimizer-server/Makefile
Original file line number Diff line number Diff line change
@@ -1,22 +1,56 @@
OS ?= linux
ARCH ?= amd64

arch_amd64 := x86_64
arch_arm64 := aarch64
arch_ppc64le := powerpc64le
arch_riscv64 := riscv64gc

linker_amd64 := x86_64
linker_arm64 := aarch64
linker_ppc64le := powerpc64le

ifneq ($(arch_$(ARCH)),)
RUST_ARCH := $(arch_$(ARCH))
else
RUST_ARCH := $(ARCH)
endif

ifneq ($(linker_$(ARCH)),)
RUST_LINKER := $(linker_$(ARCH))
else
RUST_LINKER := $(ARCH)
endif

RUST_TARGET := $(RUST_ARCH)-unknown-$(OS)-gnu
RUST_LINKER := $(RUST_LINKER)-$(OS)-gnu-gcc
RUST_TYPE := debug

all: build

.PHONY: .release_version .format build release

.release_version:
$(eval CARGO_BUILD_FLAGS += --release)
$(eval RUST_TYPE := release)
$(eval RUST_FLAGS += -C target-feature=+crt-static -C strip=symbols)

.format:
cargo fmt -- --check

build: .format
cargo build $(CARGO_BUILD_FLAGS)
rustup target add $(RUST_TARGET)
RUSTFLAGS="-C linker=$(RUST_LINKER) $(RUST_FLAGS)" cargo build $(CARGO_BUILD_FLAGS) --target $(RUST_TARGET)
cargo clippy $(CARGO_BUILD_FLAGS) -- -Dwarnings
install -D -m 755 target/$(RUST_TARGET)/$(RUST_TYPE)/optimizer-server bin/optimizer-server

release: .format .release_version build

static-release: .format
cargo clippy $(CARGO_BUILD_FLAGS) -- -Dwarnings
RUSTFLAGS="-C target-feature=+crt-static" cargo build --release --target x86_64-unknown-linux-gnu
RUSTFLAGS="-C linker=$(RUST_LINKER) -C target-feature=+crt-static -C target-feature=+crt-static -C strip=symbols" cargo build --release --target $(RUST_TARGET)
install -D -m 755 target/$(RUST_TARGET)/release/optimizer-server bin/optimizer-server

clean:
cargo clean
cargo clean
rm -rf bin/*

0 comments on commit 094fb40

Please sign in to comment.