Skip to content

Commit

Permalink
add debian based installer
Browse files Browse the repository at this point in the history
  • Loading branch information
julsemaan committed Jan 21, 2022
1 parent eb3e122 commit a1c3df7
Show file tree
Hide file tree
Showing 7 changed files with 646 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ variables:
RELEASEDIR: ${CILIBDIR}/release
PACKERDIR: $CIDIR/packer
ZENDIR: $CIDIR/packer/zen
ISODIR: $CIDIR/debian-installer
VAGRANT_IMG_DIR: $CIDIR/packer/vagrant_img
TESTDIR: t/venom
UPLOAD_DIR: $CILIBDIR/upload
SF_REPO_URL: https://sourceforge.net/projects/packetfence/files/PacketFence%20ZEN
SF_REPO_URL: https://sourceforge.net/projects/packetfence/files/PacketFence%20ISO
# env variables
ANSIBLE_FORCE_COLOR: 1
ANSIBLE_STDOUT_CALLBACK: yaml
Expand Down Expand Up @@ -151,6 +153,14 @@ variables:
- if: '$CI_COMMIT_REF_NAME == "devel" && ( $BUILD_PF_IMG_ZEN == "yes" || $CI_COMMIT_MESSAGE =~ /build_pf_img_zen=yes/ )'
- if: '$CI_COMMIT_REF_NAME != "devel" && $CI_COMMIT_REF_NAME !~ /^maintenance\/[[:digit:]]+\.[[:digit:]]+$/ && $CI_COMMIT_TAG == null && $CI_PIPELINE_SOURCE == "web" && ( $BUILD_PF_IMG_ZEN == "yes" || $CI_COMMIT_MESSAGE =~ /build_pf_img_zen=yes/ )'

# run this job on:
# - devel branch with BUILD_PF_IMG_ISO variable defined or build_pf_img_iso=yes in commit message
# - all branches, except maintenance/X.Y and devel (web) if variable BUILD_PF_IMG_ISO sets to yes or if CI_COMMIT_MESSAGE contains "build_pf_img_iso=yes".
.build_pf_img_iso_devel_rules:
rules:
- if: '$CI_COMMIT_REF_NAME == "devel" && ( $BUILD_PF_IMG_ISO == "yes" || $CI_COMMIT_MESSAGE =~ /build_pf_img_iso=yes/ )'
- if: '$CI_COMMIT_REF_NAME != "devel" && $CI_COMMIT_REF_NAME !~ /^maintenance\/[[:digit:]]+\.[[:digit:]]+$/ && $CI_COMMIT_TAG == null && $CI_PIPELINE_SOURCE == "web" && ( $BUILD_PF_IMG_ISO == "yes" || $CI_COMMIT_MESSAGE =~ /build_pf_img_ISO=yes/ )'

# run this job on:
# - devel branch with BUILD_ARTIFACTS_WEBSITE variable defined or build_artifacts_website=yes in commit message
# - all branches, except maintenance/X.Y and devel (web) if variable BUILD_ARTIFACTS_WEBSITE sets to yes or if CI_COMMIT_MESSAGE contains "build_artifacts_website=yes".
Expand Down Expand Up @@ -353,6 +363,17 @@ variables:
tags:
- shell

.build_pf_img_iso_job:
stage: build_pf_img
environment:
name: sourceforge
url: ${SF_REPO_URL}/${CI_COMMIT_REF_SLUG}
after_script:
- make -e -C ${ISODIR} clean
dependencies: []
tags:
- shell

.build_pf_img_vagrant_release_job:
stage: build_pf_img
variables:
Expand Down Expand Up @@ -834,6 +855,25 @@ build_pf_img_zen_release:
when: manual
allow_failure: true

### build_pf_img_iso jobs
build_pf_img_iso_devel:
extends:
- .build_pf_img_iso_job
- .build_pf_img_iso_devel_rules
script:
- PF_VERSION=${CI_COMMIT_REF_SLUG} make -e -C ${ISODIR} iso

build_pf_img_iso_release:
extends:
- .build_pf_img_iso_job
script:
- PF_VERSION=${CI_COMMIT_TAG} make -e -C ${ISODIR} iso
# workaround for https://forum.gitlab.com/t/specify-when-at-job-level-with-a-job-that-has-rules/4769
rules:
- if: '$CI_COMMIT_TAG'
when: manual
allow_failure: true

### build_pf_img_vagrant jobs
build_pf_img_vagrant_release_el_8:
extends:
Expand Down
2 changes: 2 additions & 0 deletions ci/debian-installer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
preseed.cfg
*.iso
15 changes: 15 additions & 0 deletions ci/debian-installer/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

RESULT_DIR=results

.PHONY: packetfence-debian-installer.iso

iso:
echo "Building Debian installer for $(PF_VERSION)"
PF_RELEASE='$(shell cat ../../conf/pf-release)' \
PF_VERSION='$(PF_VERSION)' \
./build-and-upload.sh

.PHONY: clean
clean:
rm -rf $(RESULT_DIR)

35 changes: 35 additions & 0 deletions ci/debian-installer/build-and-upload.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash
set -o nounset -o pipefail -o errexit

PF_VERSION=${PF_VERSION:-localtest}

PF_RELEASE="`echo $PF_RELEASE | sed -r 's/.*\b([0-9]+\.[0-9]+)\.[0-9]+/\1/g'`"

ISO_NAME=PacketFence-ISO-${PF_VERSION}.iso

# upload
SF_RESULT_DIR=results/sf/${PF_VERSION}
PUBLIC_REPO_DIR="/home/frs/project/p/pa/packetfence/PacketFence\ ISO/${PF_VERSION}"
DEPLOY_SF_USER=${DEPLOY_SF_USER:-inverse-bot,packetfence}
DEPLOY_SF_HOST=${DEPLOY_SF_HOST:-frs.sourceforge.net}

upload_to_sf() {
# warning: slashs at end of dirs are significant for rsync
local src_dir="${SF_RESULT_DIR}/"
local dst_repo="${PUBLIC_REPO_DIR}/"
local dst_dir="${DEPLOY_SF_USER}@${DEPLOY_SF_HOST}:${dst_repo}"
declare -p src_dir dst_dir
echo "rsync: $src_dir -> $dst_dir"

# quotes to handle space in filename
rsync -avz $src_dir "$dst_dir"
}

mkdir -p ${SF_RESULT_DIR}

# Manifest need to be generate by hand because we modify OVF during last step
echo "===> Build ISO for release $PF_RELEASE"
docker run --rm -e PF_RELEASE=$PF_RELEASE -e ISO_OUT="${SF_RESULT_DIR}/${ISO_NAME}" -v `pwd`:/debian-installer debian:11 /debian-installer/create-debian-installer-docker.sh

echo "===> Upload to Sourceforge"
upload_to_sf
10 changes: 10 additions & 0 deletions ci/debian-installer/create-debian-installer-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
set -o nounset -o pipefail -o errexit

cd /debian-installer

apt update
apt install xorriso wget cpio genisoimage -yqq

./create-debian-installer.sh

37 changes: 37 additions & 0 deletions ci/debian-installer/create-debian-installer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

function clean() {
rm -fr isofiles/
rm -f preseed.cfg
chmod a+rw $ISO_IN
chmod a+rw $ISO_OUT
}

ISO_IN=${ISO_IN:-debian-11.2.0-amd64-netinst.iso}
ISO_OUT=${ISO_OUT:-packetfence-debian-installer.iso}

if ! [ -f $ISO_IN ]; then
wget https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/$ISO_IN
fi

rm -fr isofiles/

cat preseed.cfg.tmpl | sed "s/%%PF_VERSION%%/$PF_RELEASE/g" > preseed.cfg

xorriso -osirrox on -indev $ISO_IN -extract / isofiles

chmod +w -R isofiles/install.amd/
gunzip isofiles/install.amd/initrd.gz
echo preseed.cfg | cpio -H newc -o -A -F isofiles/install.amd/initrd
gzip isofiles/install.amd/initrd
chmod -w -R isofiles/install.amd/

cd isofiles
chmod +w md5sum.txt
find -follow -type f ! -name md5sum.txt -print0 | xargs -0 md5sum > md5sum.txt
chmod -w md5sum.txt
cd ..

genisoimage -r -J -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -o $ISO_OUT isofiles

clean
Loading

0 comments on commit a1c3df7

Please sign in to comment.