Simplifying Jenkinsfile and making it more granular for reporting
This commit is contained in:
parent
c241215149
commit
120ad601c1
1 changed files with 130 additions and 119 deletions
249
.build/Jenkinsfile
vendored
249
.build/Jenkinsfile
vendored
|
|
@ -1,10 +1,16 @@
|
||||||
pipeline {
|
pipeline {
|
||||||
agent none
|
agent none
|
||||||
parameters {
|
|
||||||
string(name: 'BUILD_VERSION', defaultValue: '', description: 'Build version for the distribution packages')
|
environment {
|
||||||
|
// Define common variables used throughout the pipeline
|
||||||
|
REPO_URL = 'https://github.com/junkurihara/rust-rpxy.git'
|
||||||
|
BINARY_NAME = 'rpxy'
|
||||||
|
// BUILD_VERSION is not set because it will be extracted from Cargo.toml in the first step
|
||||||
|
BUILD_VERSION = ''
|
||||||
}
|
}
|
||||||
|
|
||||||
stages {
|
stages {
|
||||||
stage('Build Binary and Prepare Files') {
|
stage('Prepare Build Environment') {
|
||||||
agent {
|
agent {
|
||||||
kubernetes {
|
kubernetes {
|
||||||
inheritFrom 'default'
|
inheritFrom 'default'
|
||||||
|
|
@ -23,65 +29,73 @@ pipeline {
|
||||||
}
|
}
|
||||||
steps {
|
steps {
|
||||||
container('rust-cargo') {
|
container('rust-cargo') {
|
||||||
script {
|
// Step to install necessary tools
|
||||||
// Install git
|
step('Install Git') {
|
||||||
sh 'apt-get update && apt-get -y install git --no-install-recommends'
|
sh 'apt-get update && apt-get -y install git --no-install-recommends'
|
||||||
// Clone git repo
|
}
|
||||||
sh 'git clone https://github.com/junkurihara/rust-rpxy.git'
|
|
||||||
|
// Step to clone and prepare the repository
|
||||||
|
step('Clone and Prepare Repository') {
|
||||||
|
// Clone the repository
|
||||||
|
sh "git clone ${REPO_URL}"
|
||||||
|
|
||||||
dir('rust-rpxy') {
|
dir('rust-rpxy') {
|
||||||
sh """
|
sh """
|
||||||
sed -i 's|git@github.com:junkurihara/rusty-http-cache-semantics.git|https://github.com/junkurihara/rusty-http-cache-semantics.git|g' .gitmodules
|
# Update submodule URLs to HTTPS (allows cloning without SSH keys)
|
||||||
sed -i 's|git@github.com:junkurihara/rustls-acme.git|https://github.com/junkurihara/rustls-acme.git|g' .gitmodules
|
sed -i 's|git@github.com:|https://github.com/|g' .gitmodules
|
||||||
"""
|
|
||||||
// Load required submodules
|
|
||||||
sh 'git submodule update --init'
|
|
||||||
// Compile rustc binary
|
|
||||||
sh 'cargo build --release'
|
|
||||||
|
|
||||||
// Extract the version from Cargo.toml if not passed as parameter
|
# Initialize and update submodules
|
||||||
if (params.BUILD_VERSION == "") {
|
git submodule update --init
|
||||||
def versionMatch = sh(script: 'grep "^version" Cargo.toml | sed \'s/version = "\\([0-9.]*\\)"/\\1/\'', returnStdout: true).trim()
|
"""
|
||||||
if (versionMatch) {
|
}
|
||||||
env.BUILD_VERSION = versionMatch
|
}
|
||||||
echo "Using extracted version: ${env.BUILD_VERSION}"
|
|
||||||
} else {
|
// Step to extract BUILD_VERSION from Cargo.toml
|
||||||
error "Version not found in Cargo.toml"
|
step('Extract BUILD_VERSION') {
|
||||||
}
|
script {
|
||||||
} else {
|
dir('rust-rpxy') {
|
||||||
env.BUILD_VERSION = params.BUILD_VERSION
|
// Extract version from Cargo.toml and set it as an environment variable
|
||||||
echo "Using provided build version: ${env.BUILD_VERSION}"
|
env.BUILD_VERSION = sh(script: "grep '^version' Cargo.toml | sed -E 's/version = \"(.+)\"/\\1/'", returnStdout: true).trim()
|
||||||
|
echo "Using extracted version: ${env.BUILD_VERSION}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Stash the binary for later use in package building stages
|
}
|
||||||
sh 'mv rust-rpxy/target/release/rpxy .'
|
|
||||||
stash includes: "rpxy", name: "rpxy"
|
|
||||||
|
|
||||||
// Stash the service, control, and spec files for later use
|
// Step to build the binary
|
||||||
sh '''
|
step('Compile Binary') {
|
||||||
mv rust-rpxy/.build/DEB/control .
|
dir('rust-rpxy') {
|
||||||
mv rust-rpxy/.build/DEB/postinst .
|
// Build the release version of the binary
|
||||||
mv rust-rpxy/.build/DEB/prerm .
|
sh 'cargo build --release'
|
||||||
mv rust-rpxy/.build/DEB/postrm .
|
}
|
||||||
mv rust-rpxy/.build/RPM/rpxy.spec .
|
}
|
||||||
mv rust-rpxy/.build/rpxy-start.sh .
|
|
||||||
mv rust-rpxy/.build/config.toml .
|
// Step to prepare and stash files
|
||||||
mv rust-rpxy/.build/rpxy.service .
|
step('Prepare and Stash Files') {
|
||||||
'''
|
sh """
|
||||||
|
# Move binary to workspace root for easier access
|
||||||
|
mv rust-rpxy/target/release/${BINARY_NAME} .
|
||||||
|
|
||||||
|
# Move necessary files for packaging
|
||||||
|
mv rust-rpxy/.build/DEB/{control,postinst,prerm,postrm} .
|
||||||
|
mv rust-rpxy/.build/RPM/${BINARY_NAME}.spec .
|
||||||
|
mv rust-rpxy/.build/{rpxy-start.sh,config.toml,rpxy.service} .
|
||||||
|
mv rust-rpxy/{LICENSE,README.md} .
|
||||||
|
"""
|
||||||
|
|
||||||
|
// Stash files for use in later stages
|
||||||
|
stash includes: "${BINARY_NAME}", name: "binary"
|
||||||
stash includes: "control, postinst, prerm, postrm, rpxy-start.sh", name: "deb-files"
|
stash includes: "control, postinst, prerm, postrm, rpxy-start.sh", name: "deb-files"
|
||||||
stash includes: "rpxy.spec", name: "rpm-files"
|
stash includes: "${BINARY_NAME}.spec", name: "rpm-files"
|
||||||
stash includes: "rpxy.service, config.toml", name: "service-file"
|
stash includes: "rpxy.service, config.toml", name: "service-file"
|
||||||
|
|
||||||
// Stash LICENSE and README.md
|
|
||||||
sh 'mv rust-rpxy/LICENSE .'
|
|
||||||
sh 'mv rust-rpxy/README.md .'
|
|
||||||
stash includes: "LICENSE, README.md", name: "docs"
|
stash includes: "LICENSE, README.md", name: "docs"
|
||||||
|
|
||||||
// Archive the binary and create fingerprint
|
// Archive the binary as an artifact
|
||||||
archiveArtifacts artifacts: "rpxy", allowEmptyArchive: false, fingerprint: true
|
archiveArtifacts artifacts: "${BINARY_NAME}", allowEmptyArchive: false, fingerprint: true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Build RPM Package') {
|
stage('Build RPM Package') {
|
||||||
agent {
|
agent {
|
||||||
kubernetes {
|
kubernetes {
|
||||||
|
|
@ -101,43 +115,46 @@ pipeline {
|
||||||
}
|
}
|
||||||
steps {
|
steps {
|
||||||
container('rpm-build') {
|
container('rpm-build') {
|
||||||
script {
|
// Step to prepare the RPM build environment
|
||||||
// Unstash the necessary files for this stage
|
step('Prepare RPM Build Environment') {
|
||||||
unstash 'rpxy'
|
// Unstash necessary files
|
||||||
|
unstash 'binary'
|
||||||
unstash 'rpm-files'
|
unstash 'rpm-files'
|
||||||
unstash 'service-file'
|
unstash 'service-file'
|
||||||
unstash 'docs'
|
unstash 'docs'
|
||||||
|
|
||||||
// Install required tools
|
// Install necessary tools for RPM building
|
||||||
sh 'dnf update -y && dnf install -y rpmdevtools tar'
|
sh 'dnf update -y && dnf install -y rpmdevtools tar'
|
||||||
|
}
|
||||||
// Create a tar.gz archive containing all necessary files
|
|
||||||
|
// Step to create the RPM package
|
||||||
|
step('Create RPM Package') {
|
||||||
sh """
|
sh """
|
||||||
mkdir -p rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}
|
# Create RPM build directory structure
|
||||||
mkdir -p rpxy-${env.BUILD_VERSION}
|
mkdir -p rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}
|
||||||
mv rpxy rpxy.service LICENSE README.md config.toml rpxy-${env.BUILD_VERSION}/
|
mkdir -p ${BINARY_NAME}-${BUILD_VERSION}
|
||||||
tar -czf rpmbuild/SOURCES/rpxy-${env.BUILD_VERSION}.tar.gz rpxy-${env.BUILD_VERSION}/
|
|
||||||
rm -rf rpxy-${env.BUILD_VERSION}
|
# Move files to the appropriate locations
|
||||||
|
mv ${BINARY_NAME} ${BINARY_NAME}.service LICENSE README.md config.toml ${BINARY_NAME}-${BUILD_VERSION}/
|
||||||
|
tar -czf rpmbuild/SOURCES/${BINARY_NAME}-${BUILD_VERSION}.tar.gz ${BINARY_NAME}-${BUILD_VERSION}/
|
||||||
|
mv ${BINARY_NAME}.spec rpmbuild/SPECS/
|
||||||
|
|
||||||
|
# Update spec file with correct version and source
|
||||||
|
sed -i 's/@BUILD_VERSION@/${BUILD_VERSION}/g; s/@Source0@/${BINARY_NAME}-${BUILD_VERSION}.tar.gz/g' rpmbuild/SPECS/${BINARY_NAME}.spec
|
||||||
|
|
||||||
|
# Build the RPM package
|
||||||
|
rpmbuild --define "_topdir ${WORKSPACE}/rpmbuild" --define "_version ${BUILD_VERSION}" -bb rpmbuild/SPECS/${BINARY_NAME}.spec
|
||||||
"""
|
"""
|
||||||
|
}
|
||||||
// Move the RPM spec file
|
|
||||||
sh 'mv rpxy.spec rpmbuild/SPECS/'
|
// Step to archive the RPM package
|
||||||
|
step('Archive RPM Package') {
|
||||||
// Replace @BUILD_VERSION@ in control file with actual version
|
archiveArtifacts artifacts: "rpmbuild/RPMS/x86_64/${BINARY_NAME}-${BUILD_VERSION}-1.el9.x86_64.rpm", allowEmptyArchive: false, fingerprint: true
|
||||||
sh "sed -i 's/@BUILD_VERSION@/${env.BUILD_VERSION}/' rpmbuild/SPECS/rpxy.spec"
|
|
||||||
|
|
||||||
// Replace @Source0@ in control file with actual version
|
|
||||||
sh "sed -i 's/@Source0@/rpxy-${env.BUILD_VERSION}.tar.gz/' rpmbuild/SPECS/rpxy.spec"
|
|
||||||
|
|
||||||
// Build the RPM package
|
|
||||||
sh "rpmbuild --define '_topdir ${WORKSPACE}/rpmbuild' --define '_version ${env.BUILD_VERSION}' -bb rpmbuild/SPECS/rpxy.spec"
|
|
||||||
|
|
||||||
// Archive the RPM package and create fingerprint
|
|
||||||
archiveArtifacts artifacts: "rpmbuild/RPMS/x86_64/rpxy-${env.BUILD_VERSION}-1.el9.x86_64.rpm", allowEmptyArchive: false, fingerprint: true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Build DEB Package') {
|
stage('Build DEB Package') {
|
||||||
agent {
|
agent {
|
||||||
kubernetes {
|
kubernetes {
|
||||||
|
|
@ -157,55 +174,49 @@ pipeline {
|
||||||
}
|
}
|
||||||
steps {
|
steps {
|
||||||
container('debian-build') {
|
container('debian-build') {
|
||||||
script {
|
// Step to prepare the DEB build environment
|
||||||
// Unstash the necessary files for this stage
|
step('Prepare DEB Build Environment') {
|
||||||
unstash 'rpxy'
|
// Unstash necessary files
|
||||||
|
unstash 'binary'
|
||||||
unstash 'deb-files'
|
unstash 'deb-files'
|
||||||
unstash 'service-file'
|
unstash 'service-file'
|
||||||
unstash 'docs'
|
unstash 'docs'
|
||||||
|
|
||||||
// Install required tools
|
// Install necessary tools for DEB building
|
||||||
sh 'apt-get update && apt-get install --no-install-recommends -y dpkg-dev'
|
sh 'apt-get update && apt-get install -y dpkg-dev --no-install-recommends'
|
||||||
|
}
|
||||||
// Create folder structure
|
|
||||||
|
// Step to create the DEB package
|
||||||
|
step('Create DEB Package') {
|
||||||
sh """
|
sh """
|
||||||
mkdir -p rpxy_${env.BUILD_VERSION}-1_amd64/usr/bin
|
# Define DEB package directory
|
||||||
mkdir -p rpxy_${env.BUILD_VERSION}-1_amd64/usr/local/bin
|
DEB_DIR=${BINARY_NAME}_${BUILD_VERSION}-1_amd64
|
||||||
mkdir -p rpxy_${env.BUILD_VERSION}-1_amd64/etc/systemd/system
|
|
||||||
mkdir -p rpxy_${env.BUILD_VERSION}-1_amd64/usr/share/doc/rpxy
|
# Create directory structure for DEB package
|
||||||
mkdir -p rpxy_${env.BUILD_VERSION}-1_amd64/etc/rpxy/acme_registry
|
mkdir -p $DEB_DIR/{DEBIAN,usr/{bin,local/bin,share/doc/${BINARY_NAME}},etc/{systemd/system,${BINARY_NAME}/acme_registry}}
|
||||||
mkdir -p rpxy_${env.BUILD_VERSION}-1_amd64/DEBIAN
|
|
||||||
|
# Move files to appropriate locations
|
||||||
|
mv {postinst,prerm,postrm} $DEB_DIR/DEBIAN/
|
||||||
|
chmod 755 $DEB_DIR/DEBIAN/{postinst,prerm,postrm}
|
||||||
|
mv rpxy-start.sh $DEB_DIR/usr/local/bin/
|
||||||
|
chmod 0755 $DEB_DIR/usr/local/bin/rpxy-start.sh
|
||||||
|
mv ${BINARY_NAME} $DEB_DIR/usr/bin/
|
||||||
|
mv rpxy.service $DEB_DIR/etc/systemd/system/
|
||||||
|
mv {LICENSE,README.md} $DEB_DIR/usr/share/doc/${BINARY_NAME}/
|
||||||
|
mv config.toml $DEB_DIR/etc/${BINARY_NAME}/
|
||||||
|
mv control $DEB_DIR/DEBIAN/
|
||||||
|
|
||||||
|
# Update control file with correct version
|
||||||
|
sed -i 's/@BUILD_VERSION@/${BUILD_VERSION}/' $DEB_DIR/DEBIAN/control
|
||||||
|
|
||||||
|
# Build the DEB package
|
||||||
|
dpkg-deb --build --root-owner-group $DEB_DIR
|
||||||
"""
|
"""
|
||||||
|
}
|
||||||
// Move postinstall, pre-removal and start-wrapper scripts
|
|
||||||
sh """
|
// Step to archive the DEB package
|
||||||
mv postinst rpxy_${env.BUILD_VERSION}-1_amd64/DEBIAN/
|
step('Archive DEB Package') {
|
||||||
chmod 755 rpxy_${env.BUILD_VERSION}-1_amd64/DEBIAN/postinst
|
archiveArtifacts artifacts: "${DEB_DIR}.deb", allowEmptyArchive: false, fingerprint: true
|
||||||
mv prerm rpxy_${env.BUILD_VERSION}-1_amd64/DEBIAN/
|
|
||||||
chmod 755 rpxy_${env.BUILD_VERSION}-1_amd64/DEBIAN/prerm
|
|
||||||
mv postrm rpxy_${env.BUILD_VERSION}-1_amd64/DEBIAN/
|
|
||||||
chmod 755 rpxy_${env.BUILD_VERSION}-1_amd64/DEBIAN/postrm
|
|
||||||
mv rpxy-start.sh rpxy_${env.BUILD_VERSION}-1_amd64/usr/local/bin/
|
|
||||||
chmod 0755 rpxy_${env.BUILD_VERSION}-1_amd64/usr/local/bin/rpxy-start.sh
|
|
||||||
"""
|
|
||||||
|
|
||||||
// Move binary, service, control and config file, LICENSE, and README.md
|
|
||||||
sh """
|
|
||||||
mv rpxy rpxy_${env.BUILD_VERSION}-1_amd64/usr/bin/
|
|
||||||
mv rpxy.service rpxy_${env.BUILD_VERSION}-1_amd64/etc/systemd/system/
|
|
||||||
mv LICENSE README.md rpxy_${env.BUILD_VERSION}-1_amd64/usr/share/doc/rpxy/
|
|
||||||
mv config.toml rpxy_${env.BUILD_VERSION}-1_amd64/etc/rpxy/
|
|
||||||
mv control rpxy_${env.BUILD_VERSION}-1_amd64/DEBIAN/
|
|
||||||
"""
|
|
||||||
|
|
||||||
// Replace @BUILD_VERSION@ in control file with actual version
|
|
||||||
sh "sed -i 's/@BUILD_VERSION@/${env.BUILD_VERSION}/' rpxy_${env.BUILD_VERSION}-1_amd64/DEBIAN/control"
|
|
||||||
|
|
||||||
// Build the DEB package
|
|
||||||
sh "dpkg-deb --build --root-owner-group rpxy_${env.BUILD_VERSION}-1_amd64"
|
|
||||||
|
|
||||||
// Archive the DEB package and create fingerprint
|
|
||||||
archiveArtifacts artifacts: "rpxy_${env.BUILD_VERSION}-1_amd64.deb", allowEmptyArchive: false, fingerprint: true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue