Browse Source

Merged in pbx-2488-automate-rpm-package-building (pull request #1)

PBX-2488 Automate RPM package building

* PBX-2488 Automate RPM package building
master
Harenson Henao 5 months ago
parent
commit
465766152e
3 changed files with 239 additions and 12 deletions
  1. +15
    -12
      README.md
  2. +151
    -0
      bitbucket-pipelines.yml
  3. +73
    -0
      kfa.spec

README.org → README.md View File


+ 151
- 0
bitbucket-pipelines.yml View File

@ -0,0 +1,151 @@
####################################################################################################
## NOTE: Environment variables not declared within the actual "script"s sections, are being read ##
## from bitbucket's repository/workspace variables' configuration page or the Docker container. ##
####################################################################################################
image:
name: docker-registry.mysmartpbx.org:5000/kazoo_firewall_agent:1.0-rockylinux-9
username: $DOCKER_REGISTRY_USERNAME
password: $DOCKER_REGISTRY_PASSWORD
# Keeping this parameter just for historic and documentation reasons:
# If "run-as-user" parameter is set to a given user ID (UID) and the given UID does not exist on
# the configured Docker Image, some steps may work as expected but there won't be any output from
# the pipelines steps available on the Pipelines UI. Not matter if the pipeline succeeds or not,
# not output will be available. Once you remove (or comment) the parameter, steps continue working
# as expected and they will also contain all the expected output from the steps' scripts.
#run-as-user: 1000 # circleci UID from main docker image.
definitions:
caches:
go-deps-cache:
key:
files:
- go.mod
path: $HOME/go
steps:
- step: &default
name: "default"
runs-on:
- "self.hosted"
- "linux"
- step: &info-step
name: "Informational step"
clone:
enabled: false
image: "alpine" # Image size is only 5MB! Remember to override it in future steps if needed.
- step: &build-rpm-packages
<<: *default
name: "Build RockyLinux9 RPM packages"
caches:
- go-deps-cache
script:
- |
echo "Preparing source for packaging"
mkdir -vp /tmp/packaging/rpmbuild/{SOURCES,BUILD,BUILDROOT,i386,x86_64,SPECS}
mkdir -vp /tmp/packaging/${BITBUCKET_REPO_SLUG}
cp -R ./* /tmp/packaging/${BITBUCKET_REPO_SLUG}
cp ./kfa.spec /tmp/packaging/rpmbuild/SPECS/.
cd /tmp/packaging
echo " - removing files that should not be packaged in the source tar"
rm -rf ${BITBUCKET_REPO_SLUG}/*.org
rm -rf ${BITBUCKET_REPO_SLUG}/*.md
rm -rf ${BITBUCKET_REPO_SLUG}/.git*
echo " - creating the source tar"
tar -zcvf ${BITBUCKET_REPO_SLUG}.tar.gz ${BITBUCKET_REPO_SLUG}
cp ${BITBUCKET_REPO_SLUG}.tar.gz rpmbuild/SOURCES/.
- |
echo "Packaging"
rpmbuild \
--define "_topdir %(pwd)/rpmbuild" \
--define "_rpmdir %{_topdir}" \
--define "_srcrpmdir %{_topdir}" \
--define "custom_version 1.0" \
-vv -bb rpmbuild/SPECS/kfa.spec
mv /tmp/packaging/rpmbuild/x86_64 $BITBUCKET_CLONE_DIR/RPMS
- |
cd $BITBUCKET_CLONE_DIR
echo "Pushing STEP artifacts to artifacts repository"
ROS_VERSION=$(rpm -E %{rhel})
export ARTIFACTS_FILENAME=artifacts-${BITBUCKET_REPO_SLUG}-build${BITBUCKET_BUILD_NUMBER}-rocky${ROS_VERSION}-step${BITBUCKET_STEP_UUID}-${BITBUCKET_STEP_RUN_NUMBER}.tar.gz
echo " - compressing artifacts into ${ARTIFACTS_FILENAME}"
tar zcvf /tmp/${ARTIFACTS_FILENAME} RPMS/**
export SKIP_METADATA=1 # Instruct upload_pkgs.sh script to skip triggering repositories metadata update.
echo " - pushing compressed artifacts to artifacts server"
/tmp/packager/upload_pkgs.sh "$YUM_REPOSITORY_CREDS" "/artifacts" /tmp/$ARTIFACTS_FILENAME
artifacts:
- RPMS/**
pipelines:
custom: # Manual builds.
pull_artifact_push_packages:
- variables:
- name: ARTIFACT_NAME
description: "Name of the artifact. HINT: can be seen in the output of the step that uploads it."
- name: ROCKY_OS_VERSION
description: "RockyLinux OS version these packages were created for. e.g.: 8. NOTE: Used for filtering files to upload and to know to which folder to upload the packages to."
default: "9"
allowed-values:
- "8"
- "9"
- name: STABILITY
description: "Package stability level."
default: "staging"
allowed-values:
- "stable"
- "staging"
- "experimental"
- step:
name: "Pull artifacts & push packages to YUM repository"
clone:
enabled: false # Not need for the repository content for this step.
script:
- export ARTIFACTS_URL="http://${YUM_REPOSITORY_CREDS}@docker-registry.mysmartpbx.org/artifacts"
- export RPMS_LISTING_PATTERN="RPMS/*\.el${ROCKY_OS_VERSION}\.*\.rpm"
- env # Helpful for debugging purposes.
- curl -v $ARTIFACTS_URL/$ARTIFACT_NAME -o $ARTIFACT_NAME
- tar xvf $ARTIFACT_NAME
- ls -lah $RPMS_LISTING_PATTERN
- export UPLOAD_URI="/packages/upload/rockylinux/${ROCKY_OS_VERSION}/${STABILITY}/"
- /tmp/packager/upload_pkgs.sh "$YUM_REPOSITORY_CREDS" "${UPLOAD_URI}" "${RPMS_LISTING_PATTERN}"
branches:
'master':
- parallel:
name: "Build Rocky 9 packages"
steps:
- step: # Informational step only. I find pipelines lack to appropiately tell what triggered the build.
<<: *info-step
script:
- echo "Pipeline triggered by a change on ${BITBUCKET_BRANCH} branch"
- step:
<<: *build-rpm-packages
pull-requests:
'**':
- parallel:
name: "Build Rocky 9 packages"
steps:
- step: # Informational step only. I find pipelines lack to appropiately tell what triggered the build.
<<: *info-step
script:
- echo "Pipeline triggered by a PR change"
- step:
<<: *build-rpm-packages
tags:
'**':
- parallel:
name: "Build Rocky 9 packages"
steps:
- step: # Informational step only. I find pipelines lack to appropiately tell what triggered the build.
<<: *info-step
script:
- echo "Pipeline triggered by a brand new TAG"
- step:
<<: *build-rpm-packages

+ 73
- 0
kfa.spec View File

@ -0,0 +1,73 @@
# Disable LTO objects.
%global _lto_cflags %{nil}
%global build_timestamp %(date +"%Y%m%d")
%global kfa_install_dir /opt/kazoo_firewall_agent
# This project looks not to provide debugging symbols. Disable building debug symbols for this package.
%define debug_package %{nil}
# Define custom_version=1.0 if not defined when rpmbuild was called.
%{!?custom_version: %global custom_version 1.0}
# Define custom_release={build_timestamp} if not defined when rpmbuild was called.
%{!?custom_release: %global custom_release %{build_timestamp}}
Summary: Kazoo Firewall Agent
Name: kazoo_firewall_agent
Version: %{custom_version}
%dnl Release: %{build_timestamp}%{?dist}
Release: %{custom_release}%{?dist}
License: Unknown
URL: https://bitbucket.org/gofiber-india/kazoo_firewall_agent
Source0: kazoo_firewall_agent.tar.gz
# Runtime required packages.
Requires: glibc
Requires: systemd
Requires: firewalld
BuildRequires: make
BuildRequires: go
# Needed for {_unitdir} macro to exist, which is used for installing service unit files in proper locations.
BuildRequires: systemd
%description
Use in conjunction with call_shield Kazoo application.
%prep
%setup -n kazoo_firewall_agent
%build
go build
%install
mkdir -p %{buildroot}%{kfa_install_dir}
mkdir -p %{buildroot}%{_unitdir}
cp ./%{name} %{buildroot}%{kfa_install_dir}/.
cp ./%{name}.service %{buildroot}%{_unitdir}/.
cp ./%{name}_config.json.sample %{buildroot}%{kfa_install_dir}/%{name}_config.json
%clean
rm -rf %{buildroot}
%files
%defattr(-,root,root,-)
%dir %{kfa_install_dir}
%{kfa_install_dir}/%{name}
# Don't replace existing configuration file.
%config(noreplace) %{kfa_install_dir}/%{name}_config.json
%{_unitdir}/%{name}.service
%post
/usr/bin/systemctl -q enable %{name}.service
%preun
%{?systemd_preun %{name}.service}
%postun
%{?systemd_postun %{name}.service}
%changelog
* Thu Jun 19 2025 PBX.com LLC <packages@pbx.com> 1.0
- Initial release for RPM based distros

Loading…
Cancel
Save