From 9ad31adedf083bde1aa41af3f4475ff0c5058c28 Mon Sep 17 00:00:00 2001 From: Phuc Vinh Date: Tue, 28 Sep 2021 15:17:19 -0700 Subject: [PATCH] packaging steps --- Makefile | 13 ++++ analysis/act_latency.py | 2 +- build/os_version | 139 ++++++++++++++++++++++++++++++++++++++++ build/version | 10 +++ pkg/Makefile.deb | 53 +++++++++++++++ pkg/Makefile.rpm | 44 +++++++++++++ pkg/deb/control | 8 +++ pkg/deb/postinst | 25 ++++++++ pkg/deb/prerm | 13 ++++ pkg/rpm/act.spec | 55 ++++++++++++++++ 10 files changed, 361 insertions(+), 1 deletion(-) create mode 100755 build/os_version create mode 100755 build/version create mode 100644 pkg/Makefile.deb create mode 100644 pkg/Makefile.rpm create mode 100644 pkg/deb/control create mode 100755 pkg/deb/postinst create mode 100755 pkg/deb/prerm create mode 100644 pkg/rpm/act.spec diff --git a/Makefile b/Makefile index 2b3fb7b..679831f 100755 --- a/Makefile +++ b/Makefile @@ -3,6 +3,8 @@ DIR_TARGET = target DIR_OBJ = $(DIR_TARGET)/obj DIR_BIN = $(DIR_TARGET)/bin +DIR_RPM = pkg/rpm/RPMS +DIR_DEB = pkg/deb/DEBS SRC_DIRS = common index prep storage OBJ_DIRS = $(SRC_DIRS:%=$(DIR_OBJ)/src/%) @@ -52,9 +54,20 @@ act_storage: target_dir $(STORAGE_OBJECTS) echo "Linking $@" $(CC) $(LDFLAGS) -o $(STORAGE_BINARY) $(STORAGE_OBJECTS) $(LIBRARIES) +.PHONY: rpm +rpm: + $(MAKE) -f pkg/Makefile.rpm + +.PHONY: deb +deb: + $(MAKE) -f pkg/Makefile.deb + # For now we only clean everything. +.PHONY: clean clean: /bin/rm -rf $(DIR_TARGET) + /bin/rm -rf $(DIR_RPM) + /bin/rm -rf $(DIR_DEB) -include $(ALL_DEPENDENCIES) diff --git a/analysis/act_latency.py b/analysis/act_latency.py index d337eb0..1ebb9da 100755 --- a/analysis/act_latency.py +++ b/analysis/act_latency.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 # ------------------------------------------------ # act_latency.py diff --git a/build/os_version b/build/os_version new file mode 100755 index 0000000..07a072b --- /dev/null +++ b/build/os_version @@ -0,0 +1,139 @@ +#!/usr/bin/env bash +# ------------------------------------------------------------------------------ +# Copyright 2012-2015 Aerospike, Inc. +# +# Portions may be licensed to Aerospike, Inc. under one or more contributor +# license agreements. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. +# ------------------------------------------------------------------------------ + +OPT_LONG=0 + +if [ "$1" = "-long" ] +then + OPT_LONG=1 +fi + +error() { + echo 'error:' $* >&2 +} + +main() { + + local kernel='' + local distro_id='' + local distro_version='' + local distro_long='' + local distro_short='' + + # Make sure this script is running on Linux + # The script is not designed to work on non-Linux + # operating systems. + kernel=$(uname -s | tr '[:upper:]' '[:lower:]') + if [ "$kernel" != 'linux' ] + then + error "$kernel is not supported." + exit 1 + fi + + if [ -f /etc/os-release ] + then + . /etc/os-release + distro_id=${ID,,} + distro_version=${VERSION_ID} + elif [ -f /etc/issue ] + then + issue=$(cat /etc/issue | tr '[:upper:]' '[:lower:]') + case "$issue" in + *'centos'* ) + distro_id='centos' + ;; + *'redhat'* | *'rhel'* ) + distro_id='rhel' + ;; + *'debian'* ) + distro_id='debian' + ;; + * ) + error "/etc/issue contained an unsupported linux distibution: $issue" + exit 1 + ;; + esac + + case "$distro_id" in + 'centos' | 'rhel' ) + local release='' + if [ -f /etc/centos-release ]; then + release=$(cat /etc/centos-release | tr '[:upper:]' '[:lower:]') + elif [ -f /etc/redhat-release ]; then + release=$(cat /etc/redhat-release | tr '[:upper:]' '[:lower:]') + fi + release_version=${release##*release} + distro_version=${release_version%.*} + ;; + 'debian' ) + debian_version=$(cat /etc/debian_version | tr '[:upper:]' '[:lower:]') + distro_version=${debian_version%%.*} + ;; + * ) + error "/etc/issue contained an unsupported linux distibution: $issue" + exit 1 + ;; + esac + fi + + distro_id=${distro_id//[[:space:]]/} + distro_version=${distro_version//[[:space:]]/} + + case "$distro_id" in + 'centos' ) + distro_long="${distro_id}${distro_version%%.*}" + distro_short="el${distro_version%%.*}" + ;; + 'rhel' | 'redhat' | 'red hat' ) + distro_long="${distro_id}${distro_version%%.*}" + distro_short="el${distro_version%%.*}" + ;; + 'fedora' ) + if [ "$distro_version" -gt "15" ] + then + distro_version=7 + elif [ "$distro_version" -gt "10" ] + then + distro_version=6 + else + error "Unsupported linux distibution: $distro_id $distro_version" + exit 1 + fi + distro_long="centos${distro_version}" + distro_short="el${distro_version}" + ;; + 'amzn' ) + distro_long="ami" + distro_short="ami" + ;; + * ) + distro_long="${distro_id}${distro_version}" + distro_short="${distro_id}${distro_version}" + ;; + esac + + if [ "$OPT_LONG" = "1" ] + then + echo "${distro_long}" + else + echo "${distro_short}" + fi + exit 0 +} + +main diff --git a/build/version b/build/version new file mode 100755 index 0000000..2545f25 --- /dev/null +++ b/build/version @@ -0,0 +1,10 @@ +#!/bin/bash + +rev=`git describe` +subbuild=`echo $rev | awk -F'-' '{print $2}'` + +if [ "$subbuild" != "" ] +then + rev=`echo $rev | awk -F'-' '{printf("%s-%s\n",$1,$2)}'` +fi +echo $rev diff --git a/pkg/Makefile.deb b/pkg/Makefile.deb new file mode 100644 index 0000000..13df2d3 --- /dev/null +++ b/pkg/Makefile.deb @@ -0,0 +1,53 @@ +# Build act distribution. + +export DEB_SOURCE_ROOT = $(shell echo `pwd`/dist) +export DEB_BUILD_ROOT = $(DEB_SOURCE_ROOT)/BUILD +export CL_BASE = $(DEB_BUILD_ROOT)/opt/aerospike +export ETC_BASE = $(DEB_BUILD_ROOT)/etc/aerospike + +REV = $(shell build/version) +#REV = 6.2.0 +OS = $(shell build/os_version) +MANIFEST_DIR = manifest/TEMP + +.PHONY: default +default: dist + +.PHONY: dist +dist: + + # Build tools package. + rm -rf $(DEB_BUILD_ROOT)/* + mkdir -p $(DEB_BUILD_ROOT)/DEBIAN + mkdir -p $(DEB_BUILD_ROOT)/usr/bin + mkdir -p pkg/deb/DEBS + install -m 755 pkg/deb/postinst $(DEB_BUILD_ROOT)/DEBIAN/postinst + install -m 755 pkg/deb/prerm $(DEB_BUILD_ROOT)/DEBIAN/prerm + install -m 644 pkg/deb/control $(DEB_BUILD_ROOT)/DEBIAN/control + + mkdir -p $(CL_BASE) + mkdir -p $(ETC_BASE) + mkdir -p $(CL_BASE)/bin + + # act + install -m 755 target/bin/act_* $(CL_BASE)/bin/ + install -m 755 analysis/act_latency.py $(CL_BASE)/bin/ + install -m 755 config/act_index.conf $(ETC_BASE)/ + install -m 755 config/act_storage.conf $(ETC_BASE)/ + + # Create symlinks to /usr/bin + mkdir -p $(DEB_BUILD_ROOT)/usr/bin + ln -sf /opt/aerospike/bin/act_index $(DEB_BUILD_ROOT)/usr/bin/act_index + ln -sf /opt/aerospike/bin/act_prep $(DEB_BUILD_ROOT)/usr/bin/act_prep + ln -sf /opt/aerospike/bin/act_storage $(DEB_BUILD_ROOT)/usr/bin/act_storage + ln -sf /opt/aerospike/bin/act_latency.py $(DEB_BUILD_ROOT)/usr/bin/act_latency.py + + + sed 's/@VERSION@/'$(REV)'/g' $(DEB_BUILD_ROOT)/DEBIAN/control + + fakeroot dpkg-deb --build $(DEB_BUILD_ROOT) pkg/deb/DEBS + rm -rf dist + +distclean: + rm -rf $(DEB_SOURCE_ROOT) + rm -rf pkg/deb/DEBS diff --git a/pkg/Makefile.rpm b/pkg/Makefile.rpm new file mode 100644 index 0000000..4f20677 --- /dev/null +++ b/pkg/Makefile.rpm @@ -0,0 +1,44 @@ +# Build aerospike rpm distribution. + +export RPM_SOURCE_ROOT = $(shell echo `pwd`/dist) +export RPM_BUILD_ROOT = $(RPM_SOURCE_ROOT)/BUILD +export CL_BASE = $(RPM_BUILD_ROOT)/opt/aerospike +export ETC_BASE = $(RPM_BUILD_ROOT)/etc/aerospike + +MANIFEST_DIR = manifest/TEMP +TOOLS_VERSION = $(shell build/version | sed 's/-/_/g') +OS = $(shell build/os_version) +#TOOLS_VERSION = $(shell git describe 2>/dev/null; if [ $${?} != 0 ]; then echo 'unknown'; fi) +OS = el8 +TOOLS_VERSION = 6.2.0 + +.PHONY: default +default: dist + mkdir -p pkg/rpm/RPMS/x86_64 + mkdir -p $(RPM_BUILD_ROOT) + mkdir -p $(RPM_SOURCE_ROOT)/RPMS/x86_64 + mkdir -p $(RPM_BUILD_ROOT)/usr/bin + + sed 's/@VERSION@/'$(TOOLS_VERSION)'/g' pkg/act_v.spec + sed -i 's/@RELEASE@/'$(OS)'/g' pkg/act_v.spec + + rpmbuild -bb -vv --define "dist .$(OS)" --buildroot $(RPM_BUILD_ROOT) pkg/act_v.spec + find $(RPM_SOURCE_ROOT)/RPMS -type f -exec mv {} pkg/rpm/RPMS/x86_64 \; + rm -rf pkg/act_v.spec dist + +distclean: + rm -rf $(RPM_BUILD_ROOT) + rm -rf pkg/rpm/RPMS/x86_64/* + +.PHONY: dist +dist: + + mkdir -p $(CL_BASE) + mkdir -p $(ETC_BASE) + mkdir -p $(CL_BASE)/bin + + # act + install -m 755 target/bin/act_* $(CL_BASE)/bin/ + install -m 755 analysis/act_latency.py $(CL_BASE)/bin/ + install -m 755 config/act_index.conf $(ETC_BASE)/ + install -m 755 config/act_storage.conf $(ETC_BASE)/ diff --git a/pkg/deb/control b/pkg/deb/control new file mode 100644 index 0000000..44f1584 --- /dev/null +++ b/pkg/deb/control @@ -0,0 +1,8 @@ +Package: act +Version: @VERSION@ +Section: Databases +Priority: optional +Architecture: amd64 +Depends: libc6 (>= 2.7) +Maintainer: Aerospike, Inc. +Description: Aerospike Certification Tool diff --git a/pkg/deb/postinst b/pkg/deb/postinst new file mode 100755 index 0000000..020a549 --- /dev/null +++ b/pkg/deb/postinst @@ -0,0 +1,25 @@ +#!/bin/sh + +set -e + +case "$1" in + configure) + + echo Installing /opt/aerospike/bim/act + + # create aerospike group if it isn't already there + if ! getent group aerospike >/dev/null; then + groupadd -r aerospike + fi + + # create aerospike user if it isn't already there + if ! getent passwd aerospike >/dev/null; then + useradd -r -d /opt/aerospike -c 'Aerospike server' -g aerospike aerospike + fi + + chown -R aerospike:aerospike /opt/aerospike + + ;; +esac + +exit 0 diff --git a/pkg/deb/prerm b/pkg/deb/prerm new file mode 100755 index 0000000..1856125 --- /dev/null +++ b/pkg/deb/prerm @@ -0,0 +1,13 @@ +#!/bin/sh + +set -e + +case "$1" in + remove) + + echo Removing /opt/aerospike/bin/act + rm -f /opt/aerospike/bin/act_* + ;; +esac + +exit 0 diff --git a/pkg/rpm/act.spec b/pkg/rpm/act.spec new file mode 100644 index 0000000..8076600 --- /dev/null +++ b/pkg/rpm/act.spec @@ -0,0 +1,55 @@ +Name: act +Version: @VERSION@ +Release: 1%{?dist} +Summary: The Aerospike Certification Tool +License: Apache 2.0 license +Group: Application +BuildArch: x86_64 +%description +ACT provides a pair of programs for testing and certifying flash/SSD devices' performance for Aerospike Database data and index storage. +%define _topdir dist +%define __spec_install_post /usr/lib/rpm/brp-compress + +%package tools +Summary: The Aerospike Certification Tool +Group: Applications +%description tools +Tools for use with the Aerospike database +%files +%defattr(-,aerospike,aerospike) +/opt/aerospike/bin/act_index +/opt/aerospike/bin/act_prep +/opt/aerospike/bin/act_storage +/opt/aerospike/bin/act_latency.py +%defattr(-,root,root) +/usr/bin/act_index +/usr/bin/act_prep +/usr/bin/act_storage +/usr/bin/act_latency.py + +%config(noreplace) +/etc/aerospike/act_storage.conf +/etc/aerospike/act_index.conf + +%prep +ln -sf /opt/aerospike/bin/act_index %{buildroot}/usr/bin/act_index +ln -sf /opt/aerospike/bin/act_prep %{buildroot}/usr/bin/act_prep +ln -sf /opt/aerospike/bin/act_storage %{buildroot}/usr/bin/act_storage +ln -sf /opt/aerospike/bin/act_latency.py %{buildroot}/usr/bin/act_latency.py + +%pre tools +echo Installing /opt/aerospike/act +if ! id -g aerospike >/dev/null 2>&1; then + echo "Adding group aerospike" + /usr/sbin/groupadd -r aerospike +fi +if ! id -u aerospike >/dev/null 2>&1; then + echo "Adding user aerospike" + /usr/sbin/useradd -r -d /opt/aerospike -c 'Aerospike server' -g aerospike aerospike +fi + +%preun tools +if [ $1 -eq 0 ] +then + echo Removing /opt/aerospike/act +fi