Skip to content

Commit

Permalink
build-in-docker entry point script and spliting the building script into
Browse files Browse the repository at this point in the history
source and binary package parts.
Using a different container for each ARCH build.
  • Loading branch information
laeti-tia committed Jun 9, 2021
1 parent 3adbb82 commit bad2063
Show file tree
Hide file tree
Showing 7 changed files with 232 additions and 163 deletions.
13 changes: 6 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,20 @@ RUN if [ "$REPO" = "perfsonar-release" ] ; \
RUN curl -o /etc/apt/sources.list.d/$REPO.list http://downloads.perfsonar.net/debian/$REPO.list

# Some APT cleanup
RUN apt-get update && \
apt-get autoremove -y && \
RUN apt-get autoremove -y && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Copy build scripts
COPY ./ps-builder /usr/local/bin/ps-builder
RUN chmod +x /usr/local/bin/ps-builder

# Shared volume for builds and GPG signing
# Shared volume for builds
VOLUME /mnt/build

# Create build user
RUN useradd -d /home/psbuild -G sudo -m -p public -s /bin/bash psbuild

# Copy build scripts
COPY ./ps-source-builder /usr/local/bin/ps-source-builder
COPY ./ps-binary-builder /usr/local/bin/ps-binary-builder

# Start systemd
CMD ["/lib/systemd/systemd"]

34 changes: 22 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
# bundle-deb-install-tests
# Debian/Ubuntu build and testing containers
This directoy needs to be at the same level as the other perfSONAR repositories that you want to build package for. It provides some scripts and a Docker setup to build Debian/Ubuntu packages out of a perfSONAR source repository.

## Build packages
To build a Debian/Ubuntu package, run something like:

./build-in-docker -b 4.4.0 toolkit

* args and environment variables:
** `-b` the branch of the repository you want to build (snapshot package)
** `-t` the tag of the repository you want to build (staging/release package)
** `ARCHES` can be set to a list of architectures to build for

TODO: make it also work for pScheduler

The resulting packages will be located in a new directory at the same level as the other repositories called `build_results`

The build will use the information from the `debian/gbp.conf` file to know on which distro the package should be built and with which perfSONAR repository the dependencies should be solved.

## Test packages
To test the installation of a resulting package, run something like:

This project provides ways of testing installation of perfSONAR DEB package-based bundles on Debian-based systems using Docker containers.

Fully Supported:
* Debian 9 Stretch
* Debian 10 Buster
* Ubuntu 16 Xenial Xerus
* Ubuntu 18 Bionic Beaver

Partial support:
* Debian 10 Buster (only `perfsonar-testpoint` bundle)

The script attempts to perform sanity checks using the `sanity-checking` scripts (so those will need to be built with Docker first). See `../../sanity-checking`.

You can run the tests by executing `test_install_instructions.sh $REPO $OS $BUNDLE` (with all args optional but the previous one always required) where:

* `$REPO` is one of these (default is to use production):
Expand All @@ -24,10 +40,4 @@ You can run the tests by executing `test_install_instructions.sh $REPO $OS $BUND
** `debian:buster`
** `ubuntu:xenial`
** `ubuntu:bionic`
* `$BUNDLE` is one of these (default is to test all)
** `perfsonar-tools`
** `perfsonar-testpoint`
** `perfsonar-core`
** `perfsonar-centralmanagement`
** `perfsonar-toolkit`

103 changes: 0 additions & 103 deletions build-host-d9-setup.sh

This file was deleted.

94 changes: 94 additions & 0 deletions build-in-docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/usr/bin/env bash

#######
# build-in-docker [args_as_for_ps-bulder] [gitrepo]
# This script will build docker images and launch a git repo build in a container
# Requirements:
# - Needs to be in a directory at the same level as the gitrepo to be built
# - Functionnal docker buildx setup
#
# Args:
# - all args are directly passed to the ps-builder script
# - gitrepo: name of an already checked out git repository to build
#
# The OSimage and the pS repo used to build the package are coming from what
# is defined in the debian/gbp.conf file, respectively in the builder and
# debian-branch values.
#######

# Defaults
declare -a ARCHES=("linux/amd64" "linux/arm/v7")
declare -a ARCHES=("linux/amd64" "linux/ppc64le")
# Valid values for ARCH:
# linux/amd64
# linux/arm64
# linux/arm/v7
# linux/arm/v5
# linux/i386
# linux/ppc64le
# We will launch only the upper declared containers ARCH
CONTAINERS=""
for ARCH in ${ARCHES[@]}; do
LARCH=${ARCH#*\/}
CONTAINERS+=${LARCH/\/}"_build "
done

# Get the gitrepo to build
GITREPO=`echo $@ | awk '{print $NF}'`

# Which pS repo are we building for?
# TODO: when a tag is given, we should build from staging
REPO=`awk '/debian-branch / {gsub("\.[0-9]+$","",$3); print "perfsonar-"$3"-snapshot"}' ../$GITREPO/debian/gbp.conf`

# Which OS are we building on?
OSimage=`awk '/ DIST=/ {gsub("DIST=","",$3); print $3}' ../$GITREPO/debian/gbp.conf`
case $OSimage in
bionic) OSimage=ubuntu:$OSimage ;;
buster) OSimage=debian:$OSimage ;;
focal) OSimage=ubuntu:$OSimage ;;
stretch) OSimage=debian:$OSimage ;;
esac

# Initialise
LOGS_PREFIX="logs/binary_build"
mkdir -p ${LOGS_PREFIX%%/*}
rm -f ${LOGS_PREFIX}_*.log
docker compose down
export OSimage REPO useproxy

# Loop on all ARCHES we want to build for to prepare images
for ARCH in ${ARCHES[@]}; do
echo -e "\n\033[1;35m============\033[0;35m\nBuilding OS: $OSimage.$ARCH - pS repo: $REPO\n\033[1m============\033[0m\n"
# Build the image
ARCH=$ARCH docker buildx bake --load
done

# Launch all containers, with deb_build running on amd64
# TODO: deb_build should be running on the main Docker host ARCH
ARCH=linux/amd64 docker compose up -d deb_build $CONTAINERS
# Build source package and feed all the parameters to ps-builder
echo -e "\n\033[1m===== Building source package in source-build container =====\033[0m"
docker compose exec --user psbuild deb_build /usr/local/bin/ps-source-builder $*
# TODO: how to actually stop?
[ $? -eq 0 ] || exit 1

# Build binary package for all architectures
for ARCH in ${ARCHES[@]}; do
LARCH=${ARCH#*\/}
LARCH=${LARCH/\/}
echo -e "\n===== Building \033[1mbinary package\033[0m on \033[1m$ARCH.$OSimage\033[0m in \033[1m$LARCH-build\033[0m container ====="
# TODO: can we run all builds in parallel?
docker compose exec --user psbuild ${LARCH}_build /usr/local/bin/ps-binary-builder $GITREPO
done

# Loop on all ARCHES to test install the new package
# TODO

echo -e "\nNow stopping containers."
docker compose down

### Debugging
# docker compose up -d
### Running again a binary build with same source package
# ARCH=amd64 docker compose exec --user psbuild ${ARCH}_build /usr/local/bin/ps-binary-builder $GITREPO

69 changes: 57 additions & 12 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,70 @@
### Required setup for the build images.
version: '3.8'

###
# Some repeated defaults:
# tmpfs and /sys/fs/cgroup volumes are needed for systemd to work properly
# /mnt/build is where the git repositories will be shared with the host
version: '3.8'
###
x-tmpfs:
&default-tmpfs
- /run
- /tmp

x-volumes:
&default-volumes
- /sys/fs/cgroup:/sys/fs/cgroup:ro
- ../:/mnt/build

###
# The first service is only to build the required images
# and to build the source package
###
services:
deb_build:
container_name: deb-build
privileged: true
container_name: source-build
build:
context: .
dockerfile: Dockerfile
args:
OSimage: "$OSimage"
ARCH: "$ARCH"
REPO: "$REPO"
useproxy: "${useproxy:-no}"
proxy: "$proxy"
image: build.$REPO/$OSimage.$ARCH
tmpfs:
- /run
- /tmp
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
- ../:/mnt/build
image: build.$REPO.$ARCH.$OSimage
# Might be useful to publish multiarch image on dockerHub
#image: docker.io/library/ntw0n/build.$REPO/$OSimage.$ARCH
privileged: true
tmpfs: *default-tmpfs
volumes: *default-volumes

###
# The binary build containers
###
amd64_build:
container_name: amd64-build
image: build.$REPO.linux/amd64.$OSimage
privileged: true
tmpfs: *default-tmpfs
volumes: *default-volumes

arm64_build:
container_name: arm64-build
image: build.$REPO.linux/arm64.$OSimage
privileged: true
tmpfs: *default-tmpfs
volumes: *default-volumes

armv7_build:
container_name: armv7-build
image: build.$REPO.linux/arm/v7.$OSimage
privileged: true
tmpfs: *default-tmpfs
volumes: *default-volumes

386_build:
container_name: 386-build
image: build.$REPO.linux/386.$OSimage
privileged: true
tmpfs: *default-tmpfs
volumes: *default-volumes

Loading

0 comments on commit bad2063

Please sign in to comment.