Skip to content

Commit 5de28e0

Browse files
committed
Add template job and script to generate new build jobs
The commit adds a new template job and detemplate.sh script that will use the template and will help new users generate a new build job for an upstream project. Signed-off-by: Boris Ranto <branto@redhat.com>
1 parent c6ca7dd commit 5de28e0

5 files changed

Lines changed: 346 additions & 0 deletions

File tree

detemplate.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#! /usr/bin/env bash
2+
3+
set -e
4+
5+
echo "Enter project name"
6+
read PROJECT
7+
echo "Enter github name as in github.com/ceph/<github_name>"
8+
read GITHUB
9+
10+
echo "You entered:"
11+
echo "PROJECT=$PROJECT"
12+
echo "GITHUB=$GITHUB"
13+
14+
if test -e ${PROJECT}; then
15+
echo "The current directory already contains ${PROJECT} directory, please remove it first."
16+
exit 1
17+
fi
18+
19+
## Create the initial directory structure
20+
cp -a template ${PROJECT}
21+
22+
## Fix up the filenames
23+
mv ${PROJECT}/config/definitions/template.yml ${PROJECT}/config/definitions/${PROJECT}.yml
24+
25+
find ${PROJECT} -type f -exec sed -i -e "s/PROJECT/$PROJECT/g" {} \;
26+
find ${PROJECT} -type f -exec sed -i -e "s/GITHUB/$GITHUB/g" {} \;
27+
28+
echo "The following job was created:" ${PROJECT}
29+
echo "Please follow all the TODO markers to complete the creation of the build job."
30+
exit 0

template/build/build_deb

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#! /usr/bin/bash
2+
set -ex
3+
4+
# Only do actual work when we are a DEB distro
5+
if test "$DISTRO" != "debian" -a "$DISTRO" != "ubuntu"; then
6+
exit 0
7+
fi
8+
9+
10+
## Install any setup-time deps
11+
# TODO -- upload install-deps.sh script that installs the setup time deps
12+
# to upstream repo or update this section to install these packages
13+
14+
# We need this for mk-build-deps
15+
sudo apt-get install -y equivs
16+
17+
# Run the install-deps.sh upstream script if it exists
18+
if [ -x install-deps.sh ]; then
19+
echo "Ensuring dependencies are installed"
20+
sudo ./install-deps.sh
21+
fi
22+
23+
24+
## Setup the pbuilder
25+
# TODO remove if you do not want to use pbuilders
26+
setup_pbuilder
27+
28+
29+
## Get some basic information about the system and the repository
30+
# TODO -- update this to get the proper VERSION/REVISION
31+
DEB_ARCH=$(dpkg-architecture -qDEB_BUILD_ARCH)
32+
VERSION="$(./get-version.sh)"
33+
REVISION="$(./get-revision.sh)"
34+
35+
36+
## Build the source tarball
37+
# TODO -- upload make-dist script that stores the tarball in dist/ to upstream repo or update this section
38+
echo "Building source distribution"
39+
if [ -x make-dist ]; then
40+
echo "Ensuring dependencies are installed"
41+
./make-dist
42+
fi
43+
44+
45+
## Prepare the debian files
46+
# TODO -- Make sure the debian folder is tracked upstream
47+
# Bump the changelog
48+
dch -v "$VERSION" "New release ($VERSION)"
49+
50+
# Install debian build-time dependencies
51+
yes | sudo mk-build-deps --install debian/control
52+
53+
# Create .dsc and source tarball
54+
sudo dpkg-buildpackage -S -us -uc
55+
56+
57+
## Build with pbuilder
58+
echo "Building debs"
59+
60+
PBUILDDIR="/srv/debian-base"
61+
62+
sudo pbuilder --clean
63+
64+
mkdir -p dist/deb
65+
66+
echo "Building debs for $DIST"
67+
sudo pbuilder build \
68+
--distribution $DIST \
69+
--basetgz $PBUILDDIR/$DIST.tgz \
70+
--buildresult dist/deb/ \
71+
--debbuildopts "-j`grep -c processor /proc/cpuinfo`" \
72+
dist/PROJECT_$VERSION.dsc
73+
74+
75+
## Upload the created RPMs to chacra
76+
chacra_endpoint="PROJECT/${BRANCH}/${GIT_COMMIT}/${DISTRO}/${DIST}"
77+
78+
[ "$FORCE" = true ] && chacra_flags="--force" || chacra_flags=""
79+
80+
# push binaries to chacra
81+
find ../*.deb | $VENV/chacractl binary ${chacra_flags} create ${chacra_endpoint}/${DEB_ARCH}/
82+
83+
# start repo creation
84+
$VENV/chacractl repo update ${chacra_endpoint}
85+
86+
echo Check the status of the repo at: https://shaman.ceph.com/api/repos/${chacra_endpoint}

template/build/build_rpm

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#! /usr/bin/bash
2+
set -ex
3+
4+
# Only do actual work when we are an RPM distro
5+
if test "$DISTRO" != "fedora" -a "$DISTRO" != "centos" -a "$DISTRO" != "rhel"; then
6+
exit 0
7+
fi
8+
9+
10+
## Install any setup-time deps (to make dist package)
11+
# TODO -- upload install-deps.sh script that installs the setup time deps
12+
# to upstream repo or update this section to install these packages
13+
14+
# We need this to get the major version from lsb_release
15+
yum install -y redhat-lsb-core mock
16+
17+
# Run the install-deps.sh upstream script if it exists
18+
if [ -x install-deps.sh ]; then
19+
echo "Ensuring dependencies are installed"
20+
sudo ./install-deps.sh
21+
fi
22+
23+
24+
## Get some basic information about the system and the repository
25+
# TODO -- update this to get the proper VERSION/REVISION
26+
RELEASE="$(lsb_release --short -r | cut -d '.' -f 1)" # sytem release
27+
VERSION="$(./get-version.sh)"
28+
REVISION="$(./get-revision.sh)"
29+
RPM_RELEASE=$(echo $REVISION | tr '-' '_') # the '-' has a special meaning
30+
31+
32+
## Build the source tarball
33+
# TODO -- upload make-dist script that stores the tarball in dist/ to upstream repo or update this section
34+
echo "Building source distribution"
35+
if [ -x make-dist ]; then
36+
echo "Ensuring dependencies are installed"
37+
./make-dist
38+
fi
39+
40+
41+
## Prepare the spec file for build
42+
# TODO -- Make sure the spec(.in) file is tracked upstream
43+
sed -e "s/@VERSION@/${VERSION}/g" -e "s/@RELEASE@/${RPM_RELEASE}/g" < PROJECT.spec.in > dist/PROJECT.spec
44+
45+
46+
## Create the source rpm
47+
# TODO -- update the paths to match the location of source package (dist/ by
48+
# default) and the spec file (PWD by default)
49+
echo "Building SRPM"
50+
rpmbuild \
51+
--define "_sourcedir ./dist" \
52+
--define "_specdir ." \
53+
--define "_builddir ." \
54+
--define "_srcrpmdir ." \
55+
--define "_rpmdir ." \
56+
--define "dist .any" \
57+
--define "fedora 21" \
58+
--define "rhel 7" \
59+
--nodeps -bs dist/PROJECT.spec
60+
SRPM=$(readlink -f *.src.rpm)
61+
62+
63+
## Build the binaries with mock
64+
echo "Building RPMs"
65+
sudo mock -r ${MOCK_TARGET}-${RELEASE}-${ARCH} --resultdir=./dist/rpm/ ${SRPM}
66+
67+
68+
## Upload the created RPMs to chacra
69+
chacra_endpoint="PROJECT/${BRANCH}/${GIT_COMMIT}/${DISTRO}/${RELEASE}"
70+
71+
[ "$FORCE" = true ] && chacra_flags="--force" || chacra_flags=""
72+
73+
# push binaries to chacra
74+
find ./dist/rpm/ | egrep '\.rpm$' | $VENV/chacractl binary ${chacra_flags} create ${chacra_endpoint}/$ARCH/
75+
76+
# start repo creation
77+
$VENV/chacractl repo update ${chacra_endpoint}
78+
79+
echo Check the status of the repo at: https://shaman.ceph.com/api/repos/${chacra_endpoint}

template/build/setup

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#! /usr/bin/bash
2+
#
3+
# Ceph distributed storage system
4+
#
5+
# Copyright (C) 2016 Red Hat <contact@redhat.com>
6+
#
7+
# Author: Boris Ranto <branto@redhat.com>
8+
#
9+
# This library is free software; you can redistribute it and/or
10+
# modify it under the terms of the GNU Lesser General Public
11+
# License as published by the Free Software Foundation; either
12+
# version 2.1 of the License, or (at your option) any later version.
13+
#
14+
set -ex
15+
16+
# Make sure we execute at the top level directory before we do anything
17+
cd $WORKSPACE
18+
19+
# This will set the DISTRO and MOCK_TARGET variables
20+
get_distro_and_target
21+
22+
# Perform a clean-up
23+
git clean -fxd
24+
25+
# Make sure the dist directory is clean
26+
rm -rf dist
27+
mkdir -p dist
28+
29+
# Print some basic system info
30+
HOST=$(hostname --short)
31+
echo "Building on $(hostname) with the following env"
32+
echo "*****"
33+
env
34+
echo "*****"
35+
36+
export LC_ALL=C # the following is vulnerable to i18n
37+
38+
pkgs=( "chacractl>=0.0.4" )
39+
install_python_packages "pkgs[@]"
40+
41+
# ask shaman which chacra instance to use
42+
chacra_url=`curl -f -u $SHAMAN_API_USER:$SHAMAN_API_KEY https://shaman.ceph.com/api/nodes/next/`
43+
# create the .chacractl config file using global variables
44+
make_chacractl_config $chacra_url
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
- job:
2+
name: PROJECT
3+
project-type: matrix
4+
defaults: global
5+
display-name: 'PROJECT'
6+
block-downstream: false
7+
block-upstream: false
8+
concurrent: true
9+
parameters:
10+
- string:
11+
name: BRANCH
12+
description: "The git branch (or tag) to build"
13+
14+
- string:
15+
name: DISTROS
16+
description: "A list of distros to build for. Available options are: xenial, centos7, centos6, trusty, precise, wheezy, and jessie"
17+
default: "centos7 precise xenial"
18+
19+
- string:
20+
name: ARCHS
21+
description: "A list of architectures to build for. Available options are: x86_64, and arm64"
22+
default: "x86_64"
23+
24+
- bool:
25+
name: FORCE
26+
description: "
27+
If this is unchecked, then nothing is built or pushed if they already exist in chacra. This is the default.
28+
29+
If this is checked, then the binaries will be built and pushed to chacra even if they already exist in chacra."
30+
31+
- string:
32+
name: BUILD_VIRTUALENV
33+
description: "Base parent path for virtualenv locations, set to avoid issues with extremely long paths that are incompatible with tools like pip. Defaults to '/tmp/' (note the trailing slash, which is required)."
34+
default: "/tmp/"
35+
36+
execution-strategy:
37+
combination-filter: DIST==AVAILABLE_DIST && ARCH==AVAILABLE_ARCH && (ARCH=="x86_64" || (ARCH == "arm64" && (DIST == "xenial" || DIST == "centos7")))
38+
axes:
39+
- axis:
40+
type: label-expression
41+
name: MACHINE_SIZE
42+
values:
43+
- huge
44+
- axis:
45+
type: label-expression
46+
name: AVAILABLE_ARCH
47+
values:
48+
- x86_64
49+
- arm64
50+
- axis:
51+
type: label-expression
52+
name: AVAILABLE_DIST
53+
values:
54+
- centos6
55+
- centos7
56+
- trusty
57+
- xenial
58+
- jessie
59+
- precise
60+
- wheezy
61+
- axis:
62+
type: dynamic
63+
name: DIST
64+
- axis:
65+
type: dynamic
66+
name: DIST
67+
values:
68+
- DISTROS
69+
- axis:
70+
type: dynamic
71+
name: ARCH
72+
values:
73+
- ARCHS
74+
75+
scm:
76+
- git:
77+
url: git@github.com:ceph/GITHUB.git
78+
# Use the SSH key attached to the ceph-jenkins GitHub account.
79+
credentials-id: '39fa150b-b2a1-416e-b334-29a9a2c0b32d'
80+
branches:
81+
- $BRANCH
82+
skip-tag: true
83+
wipe-workspace: true
84+
85+
builders:
86+
- shell: |
87+
echo "Cleaning up top-level workarea (shared among workspaces)"
88+
rm -rf dist
89+
rm -rf venv
90+
rm -rf release
91+
# debian build scripts
92+
- shell:
93+
!include-raw:
94+
- ../../../scripts/build_utils.sh
95+
- ../../build/setup
96+
- ../../build/build_deb
97+
# rpm build scripts
98+
- shell:
99+
!include-raw:
100+
- ../../../scripts/build_utils.sh
101+
- ../../build/setup
102+
- ../../build/build_rpm
103+
104+
wrappers:
105+
- inject-passwords:
106+
global: true
107+
mask-password-params: true

0 commit comments

Comments
 (0)