Skip to content

Commit

Permalink
Add tarball make rpm target
Browse files Browse the repository at this point in the history
Build an rpm using `make rpm`

Signed-off-by: Roy Golan <[email protected]>

Add spec and make target

Signed-off-by: Roy Golan <[email protected]>

rpmbuild works
  • Loading branch information
rgolangh committed Oct 31, 2024
1 parent 71d3eaf commit 9d9fe4f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 6 deletions.
22 changes: 16 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@ SHELL := /bin/bash
# it as is. Any project specific info is extracted from the real projct assests,
# like go.mod or git, so when a change is needed, it is changed in one place.
GO_VERSION := $(shell awk '/^go / {print $$2}' go.mod)
# RPM doesn't support dashes '-' in the version string
RPM_VERSION = $(shell git describe --always --tags HEAD | sed 's/-/~/g' || true)
GO_MODULE := $(shell awk '/^module / {print $$2}' go.mod)
GIT_VERSION := $(shell git describe --always --tags HEAD)
GIT_COMMIT := $(shell git rev-parse HEAD)
GIT_COMMIT_DATE := $(shell git log --pretty=%ct -1)
GIT_TREE_STATE := $(shell git diff --exit-code --quiet && echo clean || echo dirty)
GO_MODULE_BASE := $(notdir $(GO_MODULE))
GIT_VERSION = $(shell git describe --always --tags HEAD)
GIT_COMMIT = $(shell git rev-parse HEAD)
GIT_COMMIT_DATE = $(shell git log --pretty=%ct -1)
GIT_TREE_STATE = $(shell git diff --exit-code --quiet && echo clean || echo dirty)
ldflags := -X $(GO_MODULE)/internal/version.Version=$(GIT_VERSION)
ldflags += -X $(GO_MODULE)/internal/version.Commit=$(GIT_COMMIT)
ldflags += -X $(GO_MODULE)/internal/version.CommitDate=$(GIT_COMMIT_DATE)
ldflags += -X $(GO_MODULE)/internal/version.TreeState=$(GIT_TREE_STATE)

INSTALL_PATH = bin/

# Print out only the variables declared in this makefile(not any of the builtins).
# Will be used by other tools like github workflows or any other build tool.
# Note - the ldflags value is long with spaces and isn't a valid bash expression
Expand All @@ -27,6 +32,9 @@ print-vars:
$(if $(filter-out .%,$(v)), \
echo $v=$($v);)))

tarball:
git archive --format=tar.gz --prefix=$(GO_MODULE_BASE)-$(RPM_VERSION)/ -o $(GO_MODULE_BASE)-$(RPM_VERSION).tar.gz HEAD

install:
go install -ldflags="$(ldflags)" .

Expand All @@ -36,7 +44,9 @@ fmt:
vet:
go vet ./...


build: fmt vet
go build -v -o bin/ -ldflags="$(ldflags)" ./...
go build -v -o $(INSTALL_PATH) -ldflags="$(ldflags)" ./...

rpm: tarball
mv -v $(GO_MODULE_BASE)-$(RPM_VERSION).tar.gz ~/rpmbuild/SOURCES
rpmbuild -ba pq.spec --verbose
37 changes: 37 additions & 0 deletions pq.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
%global project_version %(make print-vars | awk -F = '/RPM_VERSION/ {print $2}' | tr -d '\n')
%global debug_package %{nil}

Name: pq
Version: %{project_version}
Release: 1%{?dist}
Summary: A tool to manage podman quadlets

License: Apache-2.0
URL: https://github.com/rgolangh/pq
Source0: %{name}-%{version}.tar.gz

BuildRequires: golang
BuildRequires: make

%description
A tool to manage podman quadlets

%prep
%autosetup

%build
%make_build build INSTALL_PATH=./ GIT_COMMIT=000 GIT_COMMIT_DATE=000 GIT_TREE_STATE=clean GIT_VERSION=%{version} RPM_VERSION=%{version}

%install
#%make_install GIT_COMMIT=000 GIT_COMMIT_DATE=000 GIT_TREE_STATE=clean GIT_VERSION=%{version} INSTALL_PATH=%{name}
install -Dpm 0755 %{name} %{buildroot}%{_bindir}/%{name}


%files
%license LICENSE
%doc README.md
%{_bindir}/%{name}

%changelog
* Sat Oct 26 2024 Roy Golan <[email protected]>
-

0 comments on commit 9d9fe4f

Please sign in to comment.