Skip to content

Commit

Permalink
Merge pull request #11 from farzadghanei/debian-packaging
Browse files Browse the repository at this point in the history
Debian packaging
  • Loading branch information
farzadghanei authored Jun 16, 2024
2 parents d598098 + 01b6ca9 commit 64b5bcc
Show file tree
Hide file tree
Showing 13 changed files with 159 additions and 39 deletions.
73 changes: 41 additions & 32 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ TIMESTAMP_MINUTE := $(shell date -u +%Y%m%d%H%M)
# build
OS ?= linux
ARCH ?= amd64
DIST ?= bookworm
DIST ?= trixie # go 1.22 is available in trixie
GOLDFLAGS ?= "-s" # by default create a leaner binary
GOARCH ?= amd64

Expand All @@ -36,8 +36,9 @@ DESTDIR ?=
prefix ?= /usr/local
exec_prefix ?= $(prefix)
bindir ?= $(exec_prefix)/bin
sharedir ?= $(exec_prefix)/share
sharedir ?= $(prefix)/share
mandir ?= $(sharedir)/man/man1
docsdir ?= $(sharedir)/doc/chkok

# use Make's builtin variable to call 'install'
INSTALL ?= install
Expand All @@ -54,18 +55,20 @@ PKG_DIST_DIR ?= $(abspath $(makefile_dir)/..)
PKG_TGZ_NAME = chkok-$(CHKOK_VERSION)-$(OS)-$(ARCH).tar.gz
PKG_TGZ_PATH = $(PKG_DIST_DIR)/$(PKG_TGZ_NAME)
PKG_CHECKSUM_NAME = chkok-$(CHKOK_VERSION)-SHA256SUMS
# PBUILDER_COMPONENTS ?= "main universe"
# PBUILDER_RC ?= $(makefile_dir)build/package/pbuilderrc
# PBUILDER_HOOKS_DIR ?= $(makefile_dir)build/package/pbuilder-hooks

PBUILDER_COMPONENTS ?= "main universe"
PBUILDER_RC ?= $(makefile_dir)build/package/pbuilderrc
PBUILDER_HOOKS_DIR ?= $(makefile_dir)build/package/pbuilder-hooks

RPM_DEV_TREE ?= $(HOME)/rpmbuild

# find Debian package version from the changelog file. latest version
# should be at the top, first matching 'chkok (0.1.0-1) ...' and sed clears chars not in version
# CHKOK_DEB_VERSION := $(shell grep --only-matching --max-count 1 --perl-regexp "^\s*chkok\s+\(.+\)\s*" build/package/debian/changelog | sed 's/[^0-9.-]//g')
# CHKOK_DEB_UPSTREAM_VERSION := $(shell echo $(CHKOK_DEB_VERSION) | grep --only-matching --perl-regexp '^[0-9.]+')
# CHKOK_DEB_UPSTREAM_TARBAL_PATH := $(abspath $(makefile_dir)/..)
# CHKOK_DEB_UPSTREAM_TARBAL := $(CHKOK_DEB_UPSTREAM_TARBAL_PATH)/chkok_$(CHKOK_DEB_UPSTREAM_VERSION).orig.tar.gz
# DEB_BUILD_GIT_BRANCH := pkg-deb-$(CHKOK_DEB_VERSION)-$(TIMESTAMP_MINUTE)
CHKOK_DEB_VERSION := $(shell grep --only-matching --max-count 1 --perl-regexp "^\s*chkok\s+\(.+\)\s*" build/package/debian/changelog | sed 's/[^0-9.-]//g')
CHKOK_DEB_UPSTREAM_VERSION := $(shell echo $(CHKOK_DEB_VERSION) | grep --only-matching --perl-regexp '^[0-9.]+')
CHKOK_DEB_UPSTREAM_TARBAL_PATH := $(abspath $(makefile_dir)/..)
CHKOK_DEB_UPSTREAM_TARBAL := $(CHKOK_DEB_UPSTREAM_TARBAL_PATH)/chkok_$(CHKOK_DEB_UPSTREAM_VERSION).orig.tar.gz
DEB_BUILD_GIT_BRANCH := pkg-deb-$(CHKOK_DEB_VERSION)-$(TIMESTAMP_MINUTE)

# find rpm version from the spec file. latest version
# should be in the top tags, first matching 'Version: 0.1.0' and sed clears chars not in version
Expand All @@ -74,8 +77,10 @@ RPM_DEV_SRC_TGZ = $(RPM_DEV_TREE)/SOURCES/chkok-$(CHKOK_RPM_VERSION).tar.gz
RPM_DEV_SPEC = $(RPM_DEV_TREE)/SPECS/chkok-$(CHKOK_RPM_VERSION).spec

# command aliases
# cowbuilder = env DISTRIBUTION=$(DIST) ARCH=$(ARCH) BASEPATH=/var/cache/pbuilder/base-$(DIST)-$(ARCH).cow cowbuilder
cowbuilder = env DISTRIBUTION=$(DIST) ARCH=$(ARCH) BASEPATH=/var/cache/pbuilder/base-$(DIST)-$(ARCH).cow cowbuilder

# testing
TEST_SKIP_STATICCHECKS ?=

chkok:
GOOS=$(OS) GOARCH=$(GOARCH) go build -ldflags $(GOLDFLAGS) cmd/chkok.go
Expand All @@ -86,18 +91,23 @@ build: chkok

test:
go test -v -race ./...
./scripts/staticchecks
if test -z $(TEST_SKIP_STATICCHECKS); then ./scripts/staticchecks; fi


install: build
$(INSTALL_PROGRAM) -d $(DESTDIR)$(bindir)
$(INSTALL_PROGRAM) chkok $(DESTDIR)$(bindir)
mkdir -p $(DESTDIR)$(mandir)
cp docs/man/chkok.1 $(DESTDIR)$(mandir)
mkdir -p $(DESTDIR)$(docsdir)
cp examples/config.yaml $(DESTDIR)$(docsdir)/example-config.yaml
cp README.rst $(DESTDIR)$(docsdir)/README.rst

uninstall:
rm -f $(DESTDIR)$(bindir)/chkok
rm -f $(DESTDIR)$(mandir)/chkok.1
rm -f $(DESTDIR)$(docsdir)/*
rmdir $(DESTDIR)$(docsdir)

clean:
rm -f chkok
Expand All @@ -107,29 +117,28 @@ clean:
distclean: clean

# override prefix so .deb package installs binaries to /usr/bin instead of /usr/local/bin
# pkg-deb: export prefix = /usr
# run target with 'make pkg-deb prefix=/usr'
# requires a cowbuilder environment. see pkg-deb-setup
# pkg-deb:
# git checkout -b $(DEB_BUILD_GIT_BRANCH)
# rm -f $(CHKOK_DEB_UPSTREAM_TARBAL); tar --exclude-backups --exclude-vcs -zcf $(CHKOK_DEB_UPSTREAM_TARBAL) .
# cp -r build/package/debian debian; git add debian; git commit -m 'add debian dir for packaging v$(CHKOK_DEB_VERSION)'
# gbp buildpackage --git-ignore-new --git-verbose --git-pbuilder \
# --git-no-create-orig --git-tarball-dir=$(CHKOK_DEB_UPSTREAM_TARBAL_PATH) \
# --git-hooks \
# --git-dist=$(DIST) --git-arch=$(ARCH) \
# --git-ignore-new --git-ignore-branch \
# --git-pbuilder-options='--configfile=$(PBUILDER_RC) --hookdir=$(PBUILDER_HOOKS_DIR) --buildresult=$(PKG_DIST_DIR)' \
# -b -us -uc -sa
# git checkout $(GIT_CURRENT_BRANCH)
# git branch -D $(DEB_BUILD_GIT_BRANCH)
pkg-deb:
git checkout -b $(DEB_BUILD_GIT_BRANCH)
rm -f $(CHKOK_DEB_UPSTREAM_TARBAL); tar --exclude-backups --exclude-vcs -zcf $(CHKOK_DEB_UPSTREAM_TARBAL) .
cp -r build/package/debian debian; git add debian; git commit -m 'add debian dir for packaging v$(CHKOK_DEB_VERSION)'
gbp buildpackage --git-ignore-new --git-ignore-branch --git-verbose --git-pbuilder \
--git-no-create-orig --git-tarball-dir=$(CHKOK_DEB_UPSTREAM_TARBAL_PATH) \
--git-hooks \
--git-dist=$(DIST) --git-arch=$(ARCH) \
--git-pbuilder-options='--configfile=$(PBUILDER_RC) --hookdir=$(PBUILDER_HOOKS_DIR) --buildresult=$(PKG_DIST_DIR)' \
-b -us -uc -sa
git checkout $(GIT_CURRENT_BRANCH)
git branch -D $(DEB_BUILD_GIT_BRANCH)

# required:
# sudo apt-get install build-essential debhelper pbuilder fakeroot cowbuilder git-buildpackage devscripts ubuntu-dev-tools
# pkg-deb-setup:
# echo "creating a git-pbuilder environment with apt repositories to install new go versions ..."
# DIST=$(DIST) ARCH=$(ARCH) git-pbuilder create --components=$(PBUILDER_COMPONENTS) \
# --extrapackages="cowdancer curl wget" --configfile=$(PBUILDER_RC) \
# --hookdir=$(PBUILDER_HOOKS_DIR)
pkg-deb-setup:
echo "creating a git-pbuilder environment with apt repositories to install new go versions ..."
DIST=$(DIST) ARCH=$(ARCH) git-pbuilder create --components=$(PBUILDER_COMPONENTS) \
--extrapackages="cowdancer curl wget" --configfile=$(PBUILDER_RC) \
--hookdir=$(PBUILDER_HOOKS_DIR)

pkg-tgz: build
tar --create --gzip --exclude-vcs --exclude=docs/man/*.rst --file $(PKG_TGZ_PATH) chkok \
Expand Down Expand Up @@ -170,7 +179,7 @@ sync-version:
@ sed -i 's/^:Version:.*/:Version: $(CHKOK_VERSION)/;t' docs/man/chkok.rst && $(MAKE) docs
@ # update first occurrence of version in RPM spec
@ sed -i 's/^Version:.*/Version: $(CHKOK_VERSION)/;t' build/package/chkok.spec
@ # (grep --max 1 --only --perl-regexp '^chkok.+\(.+\).+' build/package/debian/changelog | grep -q -F $(CHKOK_VERSION)) || \
@ (grep --max 1 --only --perl-regexp '^chkok.+\(.+\).+' build/package/debian/changelog | grep -q -F $(CHKOK_VERSION)) || \
echo -e "\e[33m*** NOTE:\e[m version $(CHKOK_VERSION) maybe missing from Debian changelog"
@ (grep --line-regexp '%changelog' -A 50 build/package/chkok.spec | grep -q -F $(CHKOK_VERSION)) || \
echo -e "\e[33m*** NOTE:\e[m version $(CHKOK_VERSION) maybe missing from RPM changelog"
Expand Down
10 changes: 7 additions & 3 deletions build/package/chkok.spec
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Name: chkok
Version: 0.3.0
Version: 0.3.1
Release: 1%{?dist}
Summary: checks attributes of files and sockets

Expand Down Expand Up @@ -31,7 +31,6 @@ Provides different running modes, useful for reporting to local and remote monit
%install
rm -rf $RPM_BUILD_ROOT
%make_install
cp -a examples/config.yaml example-config.yaml


%clean
Expand All @@ -40,12 +39,17 @@ rm -rf $RPM_BUILD_ROOT

%files
%license LICENSE
%doc README.rst example-config.yaml
%doc README.rst
%{_bindir}/%{name}
%{_mandir}/man1/%{name}*
%{_docdir}/chkok/example-config.yaml


%changelog
* Sun Jun 16 2024 Farzad Ghanei 0.3.1-1
- Add support for Debian packaging
- Improve packaging

* Sat May 11 2024 Farzad Ghanei 0.3.0-1
- Add support for required headers for http runner
- Add maxHeaderBytes configuration for http runner
10 changes: 10 additions & 0 deletions build/package/debian/changelog
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
chkok (0.3.1-1) UNRELEASED; urgency=low

[ Farzad Ghanei ]
* Closes #10 adds deb packaging
* Add support for required headers for http runner
* Add maxHeaderBytes configuration for http runner

[ Farzad Ghanei ]

-- Farzad Ghanei <644113+farzadghanei@users.noreply.github.com> Sun, 16 Jun 2024 16:08:03 +0100
1 change: 1 addition & 0 deletions build/package/debian/chkok.manpages
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docs/man/chkok.1
14 changes: 14 additions & 0 deletions build/package/debian/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Source: chkok
Section: misc
Priority: optional
Maintainer: Farzad Ghanei <644113+farzadghanei@users.noreply.github.com>
Homepage: https://github.com/farzadghanei/chkok
Standards-Version: 4.6.2
Build-Depends: debhelper-compat (= 13), golang-go (>=1.22), git, ca-certificates

Package: chkok
Architecture: amd64
Depends: ${shlibs:Depends}, ${misc:Depends}
Description: checks attributes of files and sockets
"chkok" checks if attributes of files and sockets match the provided
conditions.
44 changes: 44 additions & 0 deletions build/package/debian/copyright
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: chkok
Upstream-Contact: Farzad Ghanei
Source: https://github.com/farzadghanei/chkok

Files: *
Copyright: 2024 Farzad Ghanei <644113+farzadghanei@users.noreply.github.com>
License: MIT

Files: go-yaml/yaml*
Copyright: Copyright (c) 2006-2011 Kirill Simonov
License: MIT
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.



License: MIT
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
and associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1 change: 1 addition & 0 deletions build/package/debian/docs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
README.rst
16 changes: 16 additions & 0 deletions build/package/debian/rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/make -f

%:
dh $@


override_dh_install:
dh_install


override_dh_auto_test:
# skip staticchecks on package build
$(MAKE) test TEST_SKIP_STATICCHECKS=1

override_dh_usrlocal:
@echo "skip dh_usrlocal"
1 change: 1 addition & 0 deletions build/package/debian/source/format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.0 (quilt)
20 changes: 20 additions & 0 deletions build/package/pbuilderrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# configurations for pbuilder/cowbuilder
# can be set via ~/.pbuilderrc

# by defualt don't sign the deb package
AUTO_DEBSIGN=${AUTO_DEBSIGN:-no}

# configure where to place the built packages
BUILDRESULT=${PKG_DIST_DIR:-../}

# apt repository components
COMPONENTS=${COMPONENTS:-"main universe"}

# enable networking in pbuilder env so go can download package dependencies
USENETWORK=yes

# set $HOME var to $BUILDDIR so commands that need $HOME env var would work
BUILD_HOME=$BUILDDIR

# set debbuild opts so dpkg-buildpackage skips signing packages
DEBBUILDOPTS=${DEBBUILDOPTS:-"-us -uc -I -i"}
2 changes: 1 addition & 1 deletion cmd/chkok.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

// Version of the app
const Version string = "0.3.0"
const Version string = "0.3.1"

// ModeHTTP run checks in http server mode
const ModeHTTP string = "http"
Expand Down
2 changes: 1 addition & 1 deletion docs/man/chkok.1
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
..
.TH "CHKOK" 1 "2024-05-11" "0.3.0" "General Command Manuals"
.TH "CHKOK" 1 "2024-05-16" "0.3.1" "General Command Manuals"
.SH NAME
chkok \- Check if file attributes are OK
.SH SYNOPSIS
Expand Down
4 changes: 2 additions & 2 deletions docs/man/chkok.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ Check if file attributes are OK
-------------------------------

:Author: Farzad Ghanei
:Date: 2024-05-11
:Date: 2024-05-16
:Copyright: Copyright (c) 2024 Farzad Ghanei. chkok is an open source project released under the terms of the MIT license.
:Version: 0.3.0
:Version: 0.3.1
:Manual section: 1
:Manual group: General Command Manuals

Expand Down

0 comments on commit 64b5bcc

Please sign in to comment.