diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5c56727..ae5a647 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,25 +2,77 @@ name: Build ACT on: push: - branches: [ master ] - pull_request: - branches: [ naster ] - + branches: [ PROD-2028 ] + jobs: - build: - + buils_atl: runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v2 - - name: configure - run: sudo apt-get install make gcc libc6-dev - - name: build - run: make - - name: Upload Artifact - uses: actions/upload-artifact@v2.2.4 - with: - name: act - path: target/bin/ - if-no-files-found: error + strategy: + matrix: + container: [ 'centos:7', 'centos:8', 'debian:9', 'debian:10', 'debian:11' ] + container: + image: ${{ matrix.container }} + options: "--entrypoint /bin/bash" + steps: + - name: Install Dependencies (centos 7 & 8) + run: | + yum install -y make gcc git rpm-build + if: matrix.container == 'centos:7' || matrix.container == 'centos:8' + - name: Install Dependencies (Debian) + run: | + apt-get -y update + apt-get -y install make gcc libc6-dev git build-essential + if: | + matrix.container == 'debian:9' || matrix.container == 'debian:10' || matrix.container == 'debian:11' + - name: Clone Source + run: git clone --branch PROD-2028 https://github.com/aerospike/act.git + - name: buils act (centos) + working-directory: ./act + if: matrix.container == 'centos:7' || matrix.container == 'centos:8' + run: | + echo "REV=$(make -f pkg/Makefile.deb print-REV)" >> $GITHUB_ENV + echo "OS=$(make -f pkg/Makefile.deb print-OS)" >> $GITHUB_ENV + echo "GITHUB_SHA_SHORT=$(echo $GITHUB_SHA | cut -c 1-6)" >> $GITHUB_ENV + make all rpm + - name: build act (debian) + working-directory: ./act + if: | + matrix.container == 'debian:9' || matrix.container == 'debian:10' || matrix.container == 'debian:11' + run: | + echo "REV=$(make -f pkg/Makefile.deb print-REV)" >> $GITHUB_ENV + echo "OS=$(make -f pkg/Makefile.deb print-OS)" >> $GITHUB_ENV + echo "GITHUB_SHA_SHORT=$(echo $GITHUB_SHA | cut -c 1-6)" >> $GITHUB_ENV + make all deb + - name: Upload Artifacts + uses: actions/upload-artifact@v2.2.4 + with: + name: act-${{ env.REV }}-${{ env.OS }}-${{ env.GITHUB_SHA_SHORT }} + path: /__w/act/act/act/target/packages/act-* + if-no-files-found: error + + build: + strategy: + matrix: + os: [ 'ubuntu-20.04', 'ubuntu-18.04' ] + runs-on: ${{ matrix.os }} + steps: + - name: Install Dependencies + run: sudo apt-get install make gcc libc6-dev + - name: Get Sources + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Set env + run: | + echo "REV=$(make -f pkg/Makefile.deb print-REV)" >> $GITHUB_ENV + echo "OS=$(make -f pkg/Makefile.deb print-OS)" >> $GITHUB_ENV + echo "GITHUB_SHA_SHORT=$(echo $GITHUB_SHA | cut -c 1-6)" >> $GITHUB_ENV + ls -la + - name: build + run: make all deb + - name: Upload Artifact + uses: actions/upload-artifact@v2.2.4 + with: + name: act-${{ env.REV }}-${{ env.OS }}-${{ env.GITHUB_SHA_SHORT }} + path: target/packages + if-no-files-found: error diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..74e51f4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +bin +obj +target +dist +act_v.spec +pkg/packages diff --git a/Makefile b/Makefile index 2b3fb7b..5a25025 100755 --- a/Makefile +++ b/Makefile @@ -3,6 +3,9 @@ DIR_TARGET = target DIR_OBJ = $(DIR_TARGET)/obj DIR_BIN = $(DIR_TARGET)/bin +DIR_PKG = $(DIR_TARGET)/packages +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 +55,21 @@ 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) + /bin/rm -rf dist -include $(ALL_DEPENDENCIES) 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..2efb85a --- /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)}'` + rev=`echo $rev | awk -F'-' '{printf("%s\n",$1)}'` +fi +echo $rev diff --git a/pkg/Makefile.deb b/pkg/Makefile.deb new file mode 100644 index 0000000..562792e --- /dev/null +++ b/pkg/Makefile.deb @@ -0,0 +1,60 @@ +# 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 git describe 2>/dev/null; if [ $${?} != 0 ]; then echo 'unknown'; fi) +DIR_PKG = target/packages +REV = $(shell build/version) +OS = $(shell build/os_version) + +MANIFEST_DIR = manifest/TEMP + +.PHONY: default +default: dist + +.PHONY: dist +dist: + + # Build act package. + @echo $(REV) + @echo $(OS) + rm -rf $(DEB_BUILD_ROOT)/* + mkdir -p $(DEB_BUILD_ROOT)/DEBIAN + mkdir -p $(DEB_BUILD_ROOT)/usr/bin + mkdir -p $(DIR_PKG) + 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) $(DIR_PKG)/act-$(REV).$(OS).x86_64.deb + rm -rf dist + +distclean: + rm -rf $(DEB_SOURCE_ROOT) + rm -rf target/packages + +print-% : ; @echo $($*) diff --git a/pkg/Makefile.rpm b/pkg/Makefile.rpm new file mode 100644 index 0000000..b4ecfb1 --- /dev/null +++ b/pkg/Makefile.rpm @@ -0,0 +1,45 @@ +# Build ACT 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 +DIR_PKG = target/packages +#REV = $(shell git describe 2>/dev/null; if [ $${?} != 0 ]; then echo 'unknown'; fi) +REV = $(shell build/version) +OS = $(shell build/os_version) + +.PHONY: default +default: dist + mkdir -p $(DIR_PKG) + mkdir -p $(RPM_BUILD_ROOT) + mkdir -p $(RPM_SOURCE_ROOT)/RPMS/x86_64 + mkdir -p $(RPM_BUILD_ROOT)/usr/bin + + sed 's/@VERSION@/'$(REV)'/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 {} $(DIR_PKG) \; + rm -rf pkg/act_v.spec dist + +distclean: + rm -rf $(RPM_BUILD_ROOT) + rm -rf target/packages: + +.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)/ + +print-% : ; @echo $($*) 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..3e741a1 --- /dev/null +++ b/pkg/deb/postinst @@ -0,0 +1,25 @@ +#!/bin/sh + +set -e + +case "$1" in + configure) + + echo "Installing Aerospike Certification Tool" + + # 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..bddd382 --- /dev/null +++ b/pkg/deb/prerm @@ -0,0 +1,13 @@ +#!/bin/sh + +set -e + +case "$1" in + remove) + + echo "Removing Aerospike Certification Tool" +# 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