From 95ed59561b003ffe60f9c38b240978d9db4546bc Mon Sep 17 00:00:00 2001 From: Bram Prieshof Date: Tue, 7 Jan 2025 00:00:15 +0100 Subject: [PATCH] Added Fedora, fixed cache script and did some cleanup * Added Alpine 3.21 to the jenkinsfile * Added Debian Trixe(13) to the jenkinsfile * Fixed broken cache script Alpine edge builds * Added Fedora (41) distro * Cleaned-up Debian.yaml --- .vscode/tasks.json | 3 +- CT-Build/Alpine.Jenkinsfile | 2 +- CT-Build/Alpine.yaml | 10 +- CT-Build/Debian.Jenkinsfile | 2 +- CT-Build/Debian.yaml | 11 -- CT-Build/Fedora.Jenkinsfile | 81 +++++++++++ CT-Build/Fedora.yaml | 157 +++++++++++++++++++++ Scripts/UpdateIMGBuildFile-CacheAndRepo.sh | 9 +- 8 files changed, 255 insertions(+), 20 deletions(-) create mode 100644 CT-Build/Fedora.Jenkinsfile create mode 100644 CT-Build/Fedora.yaml diff --git a/.vscode/tasks.json b/.vscode/tasks.json index d04c5bf..167df6f 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -37,7 +37,8 @@ "description": "Wich Distro shoud be used", "options": [ "Debian", - "Alpine" + "Alpine", + "Fedora" ], "default": "Debian" }, diff --git a/CT-Build/Alpine.Jenkinsfile b/CT-Build/Alpine.Jenkinsfile index 8124d6a..f75e2e3 100644 --- a/CT-Build/Alpine.Jenkinsfile +++ b/CT-Build/Alpine.Jenkinsfile @@ -7,7 +7,7 @@ pipeline { string defaultValue: '192.168.200.11', description: 'Proxy server for packages, when enabled', name: 'ProxyServer' booleanParam description: 'will disable use of proxy server', name: 'DisProxy' checkboxParameter(name: 'ImgVersionList', format: 'JSON', displayNodePath: "//Versions/Version", valueNodePath: "//Versions/Version", description: 'Select the vesions(s) that should be build', - pipelineSubmitContent: '{"Versions": [{"Version": "3.17"},{"Version": "3.18"},{"Version": "3.19"},{"Version": "3.20"},{"Version": "edge"}]}') + pipelineSubmitContent: '{"Versions": [{"Version": "3.17"},{"Version": "3.18"},{"Version": "3.19"},{"Version": "3.20"},{"Version": "3.21"},{"Version": "edge"}]}') } options { skipDefaultCheckout() diff --git a/CT-Build/Alpine.yaml b/CT-Build/Alpine.yaml index cacf56a..7f4a2e2 100644 --- a/CT-Build/Alpine.yaml +++ b/CT-Build/Alpine.yaml @@ -270,13 +270,13 @@ packages: url: |- #StartREPOS {% if image.release != "edge" %} - http://dl-4.alpinelinux.org/alpine/v{{ image.release }}/main - http://dl-4.alpinelinux.org/alpine/v{{ image.release }}/community + https://dl-4.alpinelinux.org/alpine/v{{ image.release }}/main + https://dl-4.alpinelinux.org/alpine/v{{ image.release }}/community {% endif %} {% if image.release == "edge" %} - http://dl-4.alpinelinux.org/alpine/{{ image.release }}/main - http://dl-4.alpinelinux.org/alpine/{{ image.release }}/community - #http://dl-4.alpinelinux.org/alpine/{{ image.release }}/testing + https://dl-4.alpinelinux.org/alpine/edge/main + https://dl-4.alpinelinux.org/alpine/edge/community + #https://dl-4.alpinelinux.org/alpine/edge/testing {% endif %} #EndREPOS diff --git a/CT-Build/Debian.Jenkinsfile b/CT-Build/Debian.Jenkinsfile index bdde27a..4aaef81 100644 --- a/CT-Build/Debian.Jenkinsfile +++ b/CT-Build/Debian.Jenkinsfile @@ -7,7 +7,7 @@ pipeline { string defaultValue: '192.168.200.11', description: 'Proxy server for packages, when enabled', name: 'ProxyServer' booleanParam description: 'will disable use of proxy server', name: 'DisProxy' checkboxParameter(name: 'ImgVersionList', format: 'JSON', displayNodePath: "//Versions/Version", valueNodePath: "//Versions/Version", description: 'Select the vesions(s) that should be build', - pipelineSubmitContent: '{"Versions": [{"Version": "bookworm"},{"Version": "bullseye"}]}') + pipelineSubmitContent: '{"Versions": [{"Version": "bullseye"},{"Version": "bookworm"},{"Version": "trixie"}]}') } options { skipDefaultCheckout() diff --git a/CT-Build/Debian.yaml b/CT-Build/Debian.yaml index 9d97d1f..a16d7b6 100644 --- a/CT-Build/Debian.yaml +++ b/CT-Build/Debian.yaml @@ -74,14 +74,6 @@ files: types: - container -- path: /etc/sudoers.d/imgbuilder - generator: dump - content: |- - Defaults env_keep += "XZ_DEFAULTS" - jenkins ALL=(root:root)NOPASSWD:/bin/chown,/home/jenkins/workspace/*/*/*/*/*/*/*/*/distrobuilder,/home/jenkins/workspace/*/*/distrobuilder,/home/jenkins/workspace/*/distrobuilder - variants: - - imgbuilder - #Unattended-Upgrade configuration - path: /etc/apt/apt.conf.d/50unattended-upgrades generator: dump @@ -105,9 +97,6 @@ files: Unattended-Upgrade::InstallOnShutdown "false"; Unattended-Upgrade::Remove-Unused-Kernel-Packages "true"; Unattended-Upgrade::Remove-Unused-Dependencies "true"; - //Unattended-Upgrade::Automatic-Reboot "true"; - //Unattended-Upgrade::Automatic-Reboot-WithUsers "true"; - //Unattended-Upgrade::Automatic-Reboot-Time "02:00"; Unattended-Upgrade::SyslogEnable "true"; - path: /etc/apt/apt.conf.d/20auto-upgrades diff --git a/CT-Build/Fedora.Jenkinsfile b/CT-Build/Fedora.Jenkinsfile new file mode 100644 index 0000000..1d720cd --- /dev/null +++ b/CT-Build/Fedora.Jenkinsfile @@ -0,0 +1,81 @@ +pipeline { + agent { label 'LXCBuilder' } + parameters { + booleanParam description: 'Will only update Jenkins piplinefile (jenkinsfile)', name: 'OnlyUpdatePipeline' + booleanParam defaultValue: true, description: 'Enable muticore support for ZX compression', name: 'ZX_Multicore' + string defaultValue: '0', description: 'Set amount of core\'s ZX is allowed when compressing (use 0 for all cores)', name: 'ZX_Cores' + string defaultValue: '192.168.200.11', description: 'Proxy server for packages, when enabled', name: 'ProxyServer' + booleanParam description: 'will disable use of proxy server', name: 'DisProxy' + checkboxParameter(name: 'ImgVersionList', format: 'JSON', displayNodePath: "//Versions/Version", valueNodePath: "//Versions/Version", description: 'Select the vesions(s) that should be build', + pipelineSubmitContent: '{"Versions": [{"Version": "41"},{"Version": "Rawhide"}]}') + } + options { + skipDefaultCheckout() + buildDiscarder(logRotator(numToKeepStr: '2', artifactNumToKeepStr: '1')) + } + stages { + stage('Prepare') { + steps { + // Cleanup before starting + cleanWs() + // Checkout the repository + checkout scm + // Get distrobuilder + copyArtifacts filter: 'distrobuilder-BrampCustom', fingerprintArtifacts: true, flatten: true, projectName: 'LXC-ImgBuilder/DistroBuilder', selector: lastSuccessful() + // Setup Env + sh '''mkdir $WORKSPACE/REL + mv distrobuilder-* distrobuilder + ''' + //Check if Proxy is disabled + script{ + if (env.DisProxy == 'true') { + sh '''bash Scripts/UpdateIMGBuildFile-CacheAndRepo.sh -d''' + } else { + env.ProxyServer = ProxyServer + sh '''bash Scripts/UpdateIMGBuildFile-CacheAndRepo.sh -e $ProxyServer''' + } + if (env.OnlyUpdatePipeline == 'true') { + error 'Build ended early, only updated jenkins file' + } + } + } + } + stage('Image Configs'){ + steps{ + script{ + //Run build for requested Versions + for(ImgVersion in ImgVersionList.split(',')){ + env.ZX_Multicore = ZX_Multicore + env.ZX_Cores = ZX_Cores + env.ImgVersion = ImgVersion + stage("Build ${ImgVersion}") { + catchError(buildResult: 'UNSTABLE', stageResult: 'FAILURE') { + sh ''' + if $ZX_Multicore; then + export XZ_DEFAULTS="-T $ZX_Cores" + fi + sudo $WORKSPACE/distrobuilder build-lxc CT-Build/Fedora.yaml $WORKSPACE/REL/$ImgVersion/ -o image.release=$ImgVersion + sudo chown jenkins:jenkins -R $WORKSPACE/REL + mv $WORKSPACE/REL/$ImgVersion/rootfs.tar.xz Fedora-$ImgVersion.tar.xz + ''' + } + } + } + } + } + } + stage('Finish') { + steps { + // Save generated files + archiveArtifacts artifacts: '*.tar.xz', followSymlinks: false + // Copy artifacts to /LXCBuild folder + sh ''' + mkdir -p /LXCBuild/template/cache + cp -f *.tar.xz /LXCBuild/template/cache + ''' + // Cleaning WorkSpace when build successfully + cleanWs cleanWhenAborted: false, cleanWhenFailure: false, cleanWhenNotBuilt: false, cleanWhenUnstable: false + } + } + } +} \ No newline at end of file diff --git a/CT-Build/Fedora.yaml b/CT-Build/Fedora.yaml new file mode 100644 index 0000000..acd76d3 --- /dev/null +++ b/CT-Build/Fedora.yaml @@ -0,0 +1,157 @@ +image: + distribution: fedora + +source: + downloader: fedora-http + url: https://kojipkgs.fedoraproject.org + +targets: + lxc: + #create_message: | + # You just created a {{ image.description }} container. + config: + - type: all + before: 5 + content: |- + lxc.include = LXC_TEMPLATE_CONFIG/fedora.common.conf + + - type: user + before: 5 + content: |- + lxc.include = LXC_TEMPLATE_CONFIG/fedora.userns.conf + + - type: all + after: 4 + content: |- + lxc.include = LXC_TEMPLATE_CONFIG/common.conf + + - type: user + after: 4 + content: |- + lxc.include = LXC_TEMPLATE_CONFIG/userns.conf + + - type: all + content: |- + lxc.arch = {{ image.architecture_kernel }} + +files: +- path: /etc/machine-id + generator: dump + +- path: /etc/fstab + generator: dump + types: + - container + +- path: /var/lib/dbus/machine-id + generator: remove + +- path: /etc/hostname + generator: hostname + +- path: /etc/hosts + generator: hosts + +#dnf-automatic configuration +- path: /etc/dnf/automatic.conf + generator: dump + content: |- + apply_updates = yes + download_updates = yes + upgrade_type = security + + +packages: + manager: dnf + update: true + cleanup: true + sets: + - packages: + - cpio + - file + - findutils + - fipscheck + - gettext + - glibc-all-langpacks + - hardlink + - hostname + - ipcalc + - iproute + - iproute-tc + - iputils + - kbd + - kmod + - openssh-clients + - passwd + - policycoreutils + - procps-ng + - systemd-udev + - which + - dnf-automatic + action: install + + - packages: + - libsss_idmap + - libsss_nss_idmap + - sssd-client + action: remove + +actions: +- trigger: post-unpack + action: |- + #!/bin/sh + + set -eux + + # Increase connection timeout + echo timeout=60 >> /etc/dnf/dnf.conf + + # Let dnf find the fastest mirror + echo fastestmirror=True >> /etc/dnf/dnf.conf + + #ProxyCacheSetting + echo '#CacheServer not set' >> /etc/dnf/dnf.conf + + # Backup all repo files + for repo in $(ls /etc/yum.repos.d/*.repo); do + cp "${repo}" "${repo}.bak" + done + +- trigger: post-unpack + action: |- + #!/bin/sh + + set -eux + + # Use Fedora 38 GPG key to avoid package installation errors + for repo in $(ls /etc/yum.repos.d/*.repo); do + grep -q 'RPM-GPG-KEY-fedora-38' "${repo}" && continue + + sed -ri 's#^gpgkey=.*#\0 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-38-$basearch#g' "${repo}" + done + architectures: + - aarch64 + - x86_64 + releases: + - Rawhide + +- trigger: post-packages + action: |- + #!/bin/sh + umount -l /etc/resolv.conf || true + rm /etc/resolv.conf + ln -sf /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf + systemctl enable systemd-resolved + cp -R /etc/skel/.bash* /root/ + + systemctl enable dnf-automatic.timer + +- trigger: post-files + action: |- + #!/bin/sh + set -eux + + # Restore repos + for repo in $(ls /etc/yum.repos.d/*.bak); do + mv "${repo}" ${repo%.*} + done \ No newline at end of file diff --git a/Scripts/UpdateIMGBuildFile-CacheAndRepo.sh b/Scripts/UpdateIMGBuildFile-CacheAndRepo.sh index e6f7a41..4a8f14f 100644 --- a/Scripts/UpdateIMGBuildFile-CacheAndRepo.sh +++ b/Scripts/UpdateIMGBuildFile-CacheAndRepo.sh @@ -23,6 +23,7 @@ fi CacheAlpineRepo="http://$UseServer/alpine/" CacheDebianCache="http://$UseServer:80" CacheDebianCore="http://$UseServer/deb.debian.org/debian" +CacheFedoraCache="http://$UseServer:80" #Check if using StatusFlag if not chek if scipt is configured if [ -n "$StatusFlag" ]; then @@ -43,11 +44,13 @@ if [ $UseCache = yes ]; then AlpineRepo=$CacheAlpineRepo DebianCache='Acquire::http::Proxy "'$CacheDebianCache'";' DebianCore=$CacheDebianCore + FedoraCache='proxy = "'$CacheFedoraCache'"' elif [ $UseCache = no ]; then echo "Not using cache server" AlpineRepo=$DefaultAlpineRepo DebianCache='#CacheServer not set' DebianCore=$DefaultDebianCore + FedoraCache='#CacheServer not set' fi #Goto ProjectRoot @@ -61,7 +64,7 @@ sed -i -e '/#InitDownloadREPO/a \ url: '$DefaultAlpineRepo'' CT-Build/Alpine.ya #AlpineRepo sed -i -n '/#StartREPOS/{:a;N;/#EndREPOS/!ba;N;s/.*\n/#HereREPO\n/};p' CT-Build/Alpine.yaml -sed -i -e 's#\#HereREPO#\ \#StartREPOS\n\ '$AlpineRepo'v{{ image.release }}/main\n\ '$AlpineRepo'v{{ image.release }}/community\n\ \#EndREPOS#g' CT-Build/Alpine.yaml +sed -i -e 's#\#HereREPO#\ \#StartREPOS\n\ {% if image.release != "edge" %}\n\ '$AlpineRepo'v{{ image.release }}/main\n\ '$AlpineRepo'v{{ image.release }}/community\n\ {% endif %}\n\ {% if image.release == "edge" %}\n\ '$AlpineRepo'edge/main\n\ '$AlpineRepo'edge/community\n\ \#'$AlpineRepo'edge/testing\n\ {% endif %}\n\ \#EndREPOS#g' CT-Build/Alpine.yaml #DebianBaseRepo sed -i -e '/#InitDownloadREPO/{n;d}' CT-Build/Debian.yaml @@ -70,3 +73,7 @@ sed -i -e '/#InitDownloadREPO/a \ url: '$DebianCore'' CT-Build/Debian.yaml #DebianProxyCache sed -i -e '/#ProxyCacheSetting/{n;d}' CT-Build/Debian.yaml sed -i -e "/#ProxyCacheSetting/a \ echo \'$DebianCache\' > /etc/apt/apt.conf.d/01prox" CT-Build/Debian.yaml + +#FedoraProxyCache +sed -i -e '/#ProxyCacheSetting/{n;d}' CT-Build/Fedora.yaml +sed -i -e "/#ProxyCacheSetting/a \ echo \'$FedoraCache\' >> /etc/dnf/dnf.conf" CT-Build/Fedora.yaml