From bf6ace0d0579c252bb1faaaa168f7ea5f5c641a5 Mon Sep 17 00:00:00 2001 From: Huamin Chen Date: Tue, 14 Mar 2023 14:00:32 -0400 Subject: [PATCH] add containerized build and build rpm (#580) * make: add container build * make: add build rpm * release: release rpm * release: release rpm --- .github/workflows/release.yml | 27 ++++++++++++--------------- Makefile | 16 ++++++++++++++++ packaging/rpm/kepler.spec | 26 +++++++------------------- packaging/systemd/kepler.config | 1 - 4 files changed, 35 insertions(+), 35 deletions(-) delete mode 100644 packaging/systemd/kepler.config diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index dcbc4d1e94..0b59234d50 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -62,24 +62,21 @@ jobs: - name: Build RPM package id: rpm_build - uses: naveenrajm7/rpmbuild@master env: - VERSION : ${{ github.event.inputs.tag }} - RELEASE: ${{ github.event.inputs.release }} - with: - spec_file: "packaging/rpm/kepler_build.spec" + _VERSION_ : ${{ github.event.inputs.tag }} + _RELEASE_: ${{ github.event.inputs.release }} + _COMMITTER_: ${{ github.event.pull_request.head.sha }} + _TIMESTAMP_: ${{ steps.date.outputs.date }} + _CHANGELOG_: ${{ github.event.head_commit.message }} + run: make build_rpm - - name: Upload Release Asset - id: upload-release-asset - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - if: startsWith(github.event.ref, 'refs/tags/') + name: Release + uses: softprops/action-gh-release@master with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ${{ steps.rpm_build.outputs.source_rpm_path }} - asset_name: ${{ steps.rpm_build.outputs.source_rpm_name }} - asset_content_type: ${{ steps.rpm_build.outputs.rpm_content_type }} - + files: | + kepler-*.rpm.tar.gz + /root/rpmbuild/RPMs/ create-release-branch: name: Create release branch diff --git a/Makefile b/Makefile index 889a93d8dc..75722ad6a2 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,12 @@ else IMAGE_REPO := quay.io/sustainable_computing_io endif +ifdef BUILDER_IMAGE + BUILDER_IMAGE := $(BUILD_IMAGE) +else + BUILDER_IMAGE := quay.io/sustainable_computing_io/kepler_builder:ubi-8.6-bcc-0.24-go1.18 +endif + ifdef IMAGE_TAG IMAGE_TAG := $(IMAGE_TAG) else @@ -130,6 +136,16 @@ _build_local: tidy-vendor format +@GOOS=$(GOOS) GOARCH=$(GOARCH) go build -v -tags ${GO_BUILD_TAGS} \ -o $(CROSS_BUILD_BINDIR)/$(GOOS)_$(GOARCH)/kepler -ldflags $(LDFLAGS) ./cmd/exporter.go +container_build: tidy-vendor format + $(CTR_CMD) run --rm \ + -v $(base_dir):/kepler:Z -w /kepler \ + -e GOROOT=/usr/local/go -e PATH=$(PATH):/usr/local/go/bin \ + $(BUILDER_IMAGE) \ + make build + +build_rpm: + rpmbuild packaging/rpm/kepler.spec --build-in-place -bb + clean_build_local: rm -rf $(CROSS_BUILD_BINDIR) diff --git a/packaging/rpm/kepler.spec b/packaging/rpm/kepler.spec index 396b89487b..348923af9b 100644 --- a/packaging/rpm/kepler.spec +++ b/packaging/rpm/kepler.spec @@ -1,17 +1,15 @@ %undefine _disable_source_fetch Name: kepler -Version: %{_VERSION_} -Release: %{_RELEASE_} +Version: %{getenv:_VERSION_} +Release: %{getenv:_RELEASE_} +BuildArch: %{getenv:_ARCH_} Summary: Kepler Binary License: Apache License 2.0 URL: https://github.com/sustainable-computing-io/kepler/ -Source0: https://github.com/sustainable-computing-io/kepler/archive/refs/tags/%{_VERSION_}.tar.gz +Source0: kepler.tar.gz - - -BuildRequires: gcc BuildRequires: systemd BuildRequires: make @@ -27,14 +25,6 @@ Requires: bcc %description Kubernetes-based Efficient Power Level Exporter -# golang specifics -%global golang_version 1.19 - -%global debug_package %{nil} -%prep -%autosetup - - %build GOOS=linux CROSS_BUILD_BINDIR=_output/bin @@ -43,7 +33,7 @@ CROSS_BUILD_BINDIR=_output/bin GOARCH=amd64 %endif -make _build_local GOOS=${GOOS} GOARCH=${GOARCH} +make container_build GOOS=${GOOS} GOARCH=${GOARCH} cp ./${CROSS_BUILD_BINDIR}/${GOOS}_${GOARCH}/kepler ./_output/kepler @@ -55,7 +45,6 @@ install -d %{buildroot}%{_sysconfdir}/kepler/ install -p -m755 ./_output/kepler %{buildroot}%{_bindir}/kepler install -p -m644 ./packaging/systemd/kepler.service %{buildroot}%{_unitdir}/kepler.service -install -p m755 ./packaging/systemd/kepler.conf %{buildroot}%{_sysconfdir}/kepler/kepler.conf %post @@ -66,9 +55,8 @@ install -p m755 ./packaging/systemd/kepler.conf %{buildroot}%{_sysconfdir}/keple %license LICENSE %{_bindir}/kepler %{_unitdir}/kepler.service -%{buildroot}%{_sysconfdir}/kepler/kepler.conf %changelog -* %{_TIMESTAMP_} %{_COMMITTER_} -- %{_CHANGELOG_} \ No newline at end of file +* %{getenv:_TIMESTAMP_} %{getenv:_COMMITTER_} +- %{getenv:_CHANGELOG_} \ No newline at end of file diff --git a/packaging/systemd/kepler.config b/packaging/systemd/kepler.config deleted file mode 100644 index ec1cc425eb..0000000000 --- a/packaging/systemd/kepler.config +++ /dev/null @@ -1 +0,0 @@ -ENABLE_PROCESS_METRICS=true \ No newline at end of file